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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* tangram, Copyright (c) 2005 Jeremy English <jhe@jeremyenglish.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#ifndef HAVE_JWXYZ
# include <GL/gl.h>
#endif
#ifdef HAVE_ANDROID
#include <GLES/gl.h>
#endif
#ifdef HAVE_JWZGLES
# include "jwzgles.h"
#endif /* HAVE_JWZGLES */
#include "tangram_shapes.h"
#define small_scale ( 1 )
#define large_scale ( 2 )
#define medium_scale ( 1.414213562 )
#define alpha (0.05)
static void
tri_45_90(int wire)
{
GLfloat vertices[][3] = {
{0, alpha, 0},
{0, alpha, 1},
{1, alpha, 0},
{0, -alpha, 0},
{0, -alpha, 1},
{1, -alpha, 0}
};
glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
glNormal3f(0, 1, 0);
glVertex3fv(vertices[0]);
glNormal3f(0, 1, 0);
glVertex3fv(vertices[2]);
glNormal3f(0, 1, 0);
glVertex3fv(vertices[1]);
glNormal3f(0, -1, 0);
glVertex3fv(vertices[3]);
glNormal3f(0, -1, 0);
glVertex3fv(vertices[4]);
glNormal3f(0, -1, 0);
glVertex3fv(vertices[5]);
glEnd();
glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
glNormal3f(1, 0, 1);
glVertex3fv(vertices[2]);
glNormal3f(1, 0, 1);
glVertex3fv(vertices[5]);
glNormal3f(1, 0, 1);
glVertex3fv(vertices[4]);
glNormal3f(1, 0, 1);
glVertex3fv(vertices[1]);
glNormal3f(-1, 0, 0);
glVertex3fv(vertices[0]);
glNormal3f(-1, 0, 0);
glVertex3fv(vertices[1]);
glNormal3f(-1, 0, 0);
glVertex3fv(vertices[4]);
glNormal3f(-1, 0, 0);
glVertex3fv(vertices[3]);
glNormal3f(0, 0, -1);
glVertex3fv(vertices[0]);
glNormal3f(0, 0, -1);
glVertex3fv(vertices[3]);
glNormal3f(0, 0, -1);
glVertex3fv(vertices[5]);
glNormal3f(0, 0, -1);
glVertex3fv(vertices[2]);
glEnd();
}
static void
unit_cube(int wire)
{
glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, alpha, 0.0f);
glVertex3f(0.0f, alpha, 1.0f);
glVertex3f(1.0f, alpha, 1.0f);
glVertex3f(1.0f, alpha, 0.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, -alpha, 1.0f);
glVertex3f(1.0f, -alpha, 1.0f);
glVertex3f(1.0f, alpha, 1.0f);
glVertex3f(0.0f, alpha, 1.0f);
glNormal3f(0.0f, 0.0f, -1.0f);
glVertex3f(0.0f, -alpha, 0.0f);
glVertex3f(0.0f, alpha, 0.0f);
glVertex3f(1.0f, alpha, 0.0f);
glVertex3f(1.0f, -alpha, 0.0f);
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, -alpha, 0.0f);
glVertex3f(1.0f, alpha, 0.0f);
glVertex3f(1.0f, alpha, 1.0f);
glVertex3f(1.0f, -alpha, 1.0f);
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, -alpha, 0.0f);
glVertex3f(0.0f, -alpha, 1.0f);
glVertex3f(0.0f, alpha, 1.0f);
glVertex3f(0.0f, alpha, 0.0f);
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(0.0f, -alpha, 0.0f);
glVertex3f(1.0f, -alpha, 0.0f);
glVertex3f(1.0f, -alpha, 1.0f);
glVertex3f(0.0f, -alpha, 1.0f);
glEnd();
}
static void
unit_rhomboid(int wire)
{
glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(0, alpha, 0);
glVertex3f(1, alpha, 1);
glVertex3f(1, alpha, 2);
glVertex3f(0, alpha, 1);
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(0, -alpha, 0);
glVertex3f(0, -alpha, 1);
glVertex3f(1, -alpha, 2);
glVertex3f(1, -alpha, 1);
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(0, alpha, 0);
glVertex3f(0, alpha, 1);
glVertex3f(0, -alpha, 1);
glVertex3f(0, -alpha, 0);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(0, alpha, 1);
glVertex3f(1, alpha, 2);
glVertex3f(1, -alpha, 2);
glVertex3f(0, -alpha, 1);
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f(1, alpha, 1);
glVertex3f(1, -alpha, 1);
glVertex3f(1, -alpha, 2);
glVertex3f(1, alpha, 2);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(0, alpha, 0);
glVertex3f(0, -alpha, 0);
glVertex3f(1, -alpha, 1);
glVertex3f(1, alpha, 1);
glEnd();
}
/* All of the pieces have the same thickness so all of the Y values are the same */
GLuint
tangram_get_sm_tri_dl(int wire)
{
GLuint triangle = glGenLists(1);
glNewList(triangle, GL_COMPILE);
glScalef(small_scale, small_scale, small_scale);
tri_45_90(wire);
glEndList();
return triangle;
}
GLuint
tangram_get_lg_tri_dl(int wire)
{
GLuint triangle = glGenLists(1);
glNewList(triangle, GL_COMPILE);
glScalef(large_scale, small_scale, large_scale);
tri_45_90(wire);
glEndList();
return triangle;
}
GLuint
tangram_get_md_tri_dl(int wire)
{
GLuint triangle = glGenLists(1);
glNewList(triangle, GL_COMPILE);
glScalef(medium_scale, small_scale, medium_scale);
tri_45_90(wire);
glEndList();
return triangle;
}
GLuint
tangram_get_square_dl(int wire)
{
GLuint square = glGenLists(1);
glNewList(square, GL_COMPILE);
glScalef(small_scale, small_scale, small_scale);
unit_cube(wire);
glEndList();
return square;
}
GLuint
tangram_get_rhomboid_dl(int wire)
{
GLuint rhomboid = glGenLists(1);
glNewList(rhomboid, GL_COMPILE);
glScalef(small_scale, small_scale, small_scale);
unit_rhomboid(wire);
glEndList();
return rhomboid;
}
|