1 /* tangram, Copyright (c) 2005 Jeremy English <jhe@jeremyenglish.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
14 #endif /* HAVE_CONFIG_H */
22 #endif /* HAVE_JWZGLES */
24 #include "tangram_shapes.h"
26 #define small_scale ( 1 )
27 #define large_scale ( 2 )
28 #define medium_scale ( 1.414213562 )
35 GLfloat vertices[][3] = {
44 glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
47 glVertex3fv(vertices[0]);
49 glVertex3fv(vertices[2]);
51 glVertex3fv(vertices[1]);
54 glVertex3fv(vertices[3]);
56 glVertex3fv(vertices[4]);
58 glVertex3fv(vertices[5]);
61 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
63 glVertex3fv(vertices[2]);
65 glVertex3fv(vertices[5]);
67 glVertex3fv(vertices[4]);
69 glVertex3fv(vertices[1]);
72 glVertex3fv(vertices[0]);
74 glVertex3fv(vertices[1]);
76 glVertex3fv(vertices[4]);
78 glVertex3fv(vertices[3]);
81 glVertex3fv(vertices[0]);
83 glVertex3fv(vertices[3]);
85 glVertex3fv(vertices[5]);
87 glVertex3fv(vertices[2]);
94 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
97 glNormal3f(0.0f, 1.0f, 0.0f);
98 glVertex3f(0.0f, alpha, 0.0f);
99 glVertex3f(0.0f, alpha, 1.0f);
100 glVertex3f(1.0f, alpha, 1.0f);
101 glVertex3f(1.0f, alpha, 0.0f);
103 glNormal3f(0.0f, 0.0f, 1.0f);
104 glVertex3f(0.0f, -alpha, 1.0f);
105 glVertex3f(1.0f, -alpha, 1.0f);
106 glVertex3f(1.0f, alpha, 1.0f);
107 glVertex3f(0.0f, alpha, 1.0f);
109 glNormal3f(0.0f, 0.0f, -1.0f);
110 glVertex3f(0.0f, -alpha, 0.0f);
111 glVertex3f(0.0f, alpha, 0.0f);
112 glVertex3f(1.0f, alpha, 0.0f);
113 glVertex3f(1.0f, -alpha, 0.0f);
115 glNormal3f(1.0f, 0.0f, 0.0f);
116 glVertex3f(1.0f, -alpha, 0.0f);
117 glVertex3f(1.0f, alpha, 0.0f);
118 glVertex3f(1.0f, alpha, 1.0f);
119 glVertex3f(1.0f, -alpha, 1.0f);
121 glNormal3f(-1.0f, 0.0f, 0.0f);
122 glVertex3f(0.0f, -alpha, 0.0f);
123 glVertex3f(0.0f, -alpha, 1.0f);
124 glVertex3f(0.0f, alpha, 1.0f);
125 glVertex3f(0.0f, alpha, 0.0f);
127 glNormal3f(0.0f, -1.0f, 0.0f);
128 glVertex3f(0.0f, -alpha, 0.0f);
129 glVertex3f(1.0f, -alpha, 0.0f);
130 glVertex3f(1.0f, -alpha, 1.0f);
131 glVertex3f(0.0f, -alpha, 1.0f);
137 unit_rhomboid(int wire)
139 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
141 glNormal3f(0.0f, 1.0f, 0.0f);
142 glVertex3f(0, alpha, 0);
143 glVertex3f(1, alpha, 1);
144 glVertex3f(1, alpha, 2);
145 glVertex3f(0, alpha, 1);
147 glNormal3f(0.0f, -1.0f, 0.0f);
148 glVertex3f(0, -alpha, 0);
149 glVertex3f(0, -alpha, 1);
150 glVertex3f(1, -alpha, 2);
151 glVertex3f(1, -alpha, 1);
153 glNormal3f(-1.0f, 0.0f, 0.0f);
154 glVertex3f(0, alpha, 0);
155 glVertex3f(0, alpha, 1);
156 glVertex3f(0, -alpha, 1);
157 glVertex3f(0, -alpha, 0);
160 glNormal3f(0.0f, 0.0f, 1.0f);
161 glVertex3f(0, alpha, 1);
162 glVertex3f(1, alpha, 2);
163 glVertex3f(1, -alpha, 2);
164 glVertex3f(0, -alpha, 1);
166 glNormal3f(1.0f, 0.0f, 0.0f);
167 glVertex3f(1, alpha, 1);
168 glVertex3f(1, -alpha, 1);
169 glVertex3f(1, -alpha, 2);
170 glVertex3f(1, alpha, 2);
172 glNormal3f(0.0f, 0.0f, 1.0f);
173 glVertex3f(0, alpha, 0);
174 glVertex3f(0, -alpha, 0);
175 glVertex3f(1, -alpha, 1);
176 glVertex3f(1, alpha, 1);
181 /* All of the pieces have the same thickness so all of the Y values are the same */
184 tangram_get_sm_tri_dl(int wire)
186 GLuint triangle = glGenLists(1);
187 glNewList(triangle, GL_COMPILE);
188 glScalef(small_scale, small_scale, small_scale);
195 tangram_get_lg_tri_dl(int wire)
197 GLuint triangle = glGenLists(1);
198 glNewList(triangle, GL_COMPILE);
199 glScalef(large_scale, small_scale, large_scale);
206 tangram_get_md_tri_dl(int wire)
208 GLuint triangle = glGenLists(1);
209 glNewList(triangle, GL_COMPILE);
210 glScalef(medium_scale, small_scale, medium_scale);
217 tangram_get_square_dl(int wire)
219 GLuint square = glGenLists(1);
220 glNewList(square, GL_COMPILE);
221 glScalef(small_scale, small_scale, small_scale);
228 tangram_get_rhomboid_dl(int wire)
230 GLuint rhomboid = glGenLists(1);
231 glNewList(rhomboid, GL_COMPILE);
232 glScalef(small_scale, small_scale, small_scale);