-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel-draw.c
127 lines (99 loc) · 2.92 KB
/
model-draw.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
118
119
120
121
122
123
124
125
126
127
/*
3D model file loader
v1.2.5
written by Bl0ckeduser
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "headers.h"
#ifndef PC_TARGET
#define GLfloat float
#endif
#define RES 1.0f
int drawModelWithGL_big(model* model)
{
model_group* currentGroup = model -> g;
face* currentFace;
int vertex_id;
/* the scaling code hack here (and below) is due to a quirk in libnds:
glVertex3f only accepts values within a very limited
range; if this range is not respected, I get garbled
models. the value for the RES constant, which works on the NDS,
was found through guesswork... */
glScalef(model->x_scale / RES, model->y_scale / RES, model->z_scale / RES);
while(currentGroup != NULL) {
currentFace = currentGroup -> faces;
/* group color */
glColor3f(currentGroup -> color[0], currentGroup -> color[1], currentGroup -> color[2]);
/* draw the faces */
while(currentFace->next != NULL) {
/* one of the quirks of libnds is that there
is no GL_POLYGON mode ! */
if(currentFace->point_count==3){
glBegin(GL_TRIANGLES);
} else {
glBegin(GL_QUADS);
}
vertex_id = 0;
while(currentFace -> vertnum[vertex_id] != -1) {
glVertex3f(
model -> vertices[currentFace -> vertnum[vertex_id]-1].x / model->x_scale * RES,
model -> vertices[currentFace -> vertnum[vertex_id]-1].y / model->y_scale * RES,
model -> vertices[currentFace -> vertnum[vertex_id]-1].z / model->z_scale * RES);
#ifdef PC_TARGET
vc++; /* for vertex count checking */
#endif
vertex_id++;
}
glEnd();
currentFace = currentFace -> next;
}
currentGroup = currentGroup -> next;
}
#ifdef PC_TARGET
return vc;
#else
return 0;
#endif
}
int drawModelWithGL(model* model)
{
model_group* currentGroup = model -> g;
face* currentFace;
int vertex_id;
while(currentGroup != NULL) {
currentFace = currentGroup -> faces;
/* group color */
glColor3f(currentGroup -> color[0], currentGroup -> color[1], currentGroup -> color[2]);
/* draw the faces */
while(currentFace->next != NULL) {
/* one of the quirks of libnds is that there
is no GL_POLYGON mode ! */
if(currentFace->point_count==3){
glBegin(GL_TRIANGLES);
} else {
glBegin(GL_QUADS);
}
vertex_id = 0;
while(currentFace -> vertnum[vertex_id] != -1) {
glVertex3f(
model -> vertices[currentFace -> vertnum[vertex_id]-1].x,
model -> vertices[currentFace -> vertnum[vertex_id]-1].y,
model -> vertices[currentFace -> vertnum[vertex_id]-1].z);
#ifdef PC_TARGET
vc++; /* for vertex count checking */
#endif
vertex_id++;
}
glEnd();
currentFace = currentFace -> next;
}
currentGroup = currentGroup -> next;
}
#ifdef PC_TARGET
return vc;
#else
return 0;
#endif
}