-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_mesh.c
117 lines (109 loc) · 2.91 KB
/
test_mesh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
The contents of this file are subject to the "do whatever you like"-license.
That means: Do, whatver you want, this file is under public domain. It is an
example for sparrow3d. Copy it and learn from it for your project and release
it under every license you want. ;-)
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , zizsdl_at_googlemail.com
*/
#include "test_mesh.h"
#include <sparrow3d.h>
#include <strings.h>
SDL_Surface *mesh_texture;
spModelPointer mesh;
int mesh_z = 1;
int mesh_light = 1;
void init_mesh(char* parameter1,char* parameter2)
{
if (parameter2)
mesh_texture = spLoadSurface( parameter2 );
else
mesh_texture = spLoadSurface( "./data/garfield.png" );
if (parameter1)
mesh = spMeshLoadObj( parameter1, mesh_texture, 65535 );
else
mesh = spMeshLoadObj( "./data/testmeshuv_tri.obj", mesh_texture, 65535 );
}
char* caption_mesh(char* caption)
{
sprintf(caption,"Mesh Loading");
return caption;
}
char* settings_mesh(char* caption,int button)
{
switch (button)
{
case SP_BUTTON_A:
if (mesh_z)
sprintf(caption,"[A] Z Set & Test");
else
sprintf(caption,"[A] No Z Set & Test");
break;
case SP_BUTTON_B:
if (mesh_light)
sprintf(caption,"[B] Light on");
else
sprintf(caption,"[B] Light off");
break;
}
return caption;
}
void draw_mesh(int rotation)
{
spClearTarget(0);
spSetZSet( mesh_z );
spSetZTest( mesh_z );
spSetLight( mesh_light );
spSetAlphaTest( 0 );
spTranslate( 0, 0, spFloatToFixed( -6.0f )+spSin(rotation)*6 );
spRotateX( rotation );
spRotateY( rotation );
spRotateZ( rotation );
int i;
spSetLineWidth( 3 );
spMesh3D( mesh, 2 );
//spSetZSet( 0 );
//spSetZTest( 0 );
for (i = 0; i < mesh->edgeCount; i++)
{
if (mesh->edge[i].status == 0)
spLine3D(mesh->point[mesh->edge[i].point[0]].x,
mesh->point[mesh->edge[i].point[0]].y,
mesh->point[mesh->edge[i].point[0]].z,
mesh->point[mesh->edge[i].point[1]].x,
mesh->point[mesh->edge[i].point[1]].y,
mesh->point[mesh->edge[i].point[1]].z,spGetFastRGB(255,255,0));
}
for (i = 0; i < mesh->texEdgeCount; i++)
{
if (mesh->texEdge[i].status == 0)
spLine3D(mesh->texPoint[mesh->texEdge[i].point[0]].x,
mesh->texPoint[mesh->texEdge[i].point[0]].y,
mesh->texPoint[mesh->texEdge[i].point[0]].z,
mesh->texPoint[mesh->texEdge[i].point[1]].x,
mesh->texPoint[mesh->texEdge[i].point[1]].y,
mesh->texPoint[mesh->texEdge[i].point[1]].z,spGetFastRGB(255,255,0));
}
spSetLineWidth(1);
spSetZSet( 1 );
spSetZTest( 1 );
spSetLight( 1 );
}
void calc_mesh()
{
if ( spGetInput()->button[SP_BUTTON_A] )
{
spGetInput()->button[SP_BUTTON_A] = 0;
mesh_z = 1-mesh_z;
}
if ( spGetInput()->button[SP_BUTTON_B] )
{
spGetInput()->button[SP_BUTTON_B] = 0;
mesh_light = 1-mesh_light;
}
}
void quit_mesh()
{
spDeleteSurface(mesh_texture);
spMeshDelete(mesh);
}