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 */
26 #endif /* HAVE_JWZGLES */
28 #include "tangram_shapes.h"
30 #define small_scale ( 1 )
31 #define large_scale ( 2 )
32 #define medium_scale ( 1.414213562 )
39 GLfloat vertices[][3] = {
48 glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
51 glVertex3fv(vertices[0]);
53 glVertex3fv(vertices[2]);
55 glVertex3fv(vertices[1]);
58 glVertex3fv(vertices[3]);
60 glVertex3fv(vertices[4]);
62 glVertex3fv(vertices[5]);
65 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
67 glVertex3fv(vertices[2]);
69 glVertex3fv(vertices[5]);
71 glVertex3fv(vertices[4]);
73 glVertex3fv(vertices[1]);
76 glVertex3fv(vertices[0]);
78 glVertex3fv(vertices[1]);
80 glVertex3fv(vertices[4]);
82 glVertex3fv(vertices[3]);
85 glVertex3fv(vertices[0]);
87 glVertex3fv(vertices[3]);
89 glVertex3fv(vertices[5]);
91 glVertex3fv(vertices[2]);
98 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
101 glNormal3f(0.0f, 1.0f, 0.0f);
102 glVertex3f(0.0f, alpha, 0.0f);
103 glVertex3f(0.0f, alpha, 1.0f);
104 glVertex3f(1.0f, alpha, 1.0f);
105 glVertex3f(1.0f, alpha, 0.0f);
107 glNormal3f(0.0f, 0.0f, 1.0f);
108 glVertex3f(0.0f, -alpha, 1.0f);
109 glVertex3f(1.0f, -alpha, 1.0f);
110 glVertex3f(1.0f, alpha, 1.0f);
111 glVertex3f(0.0f, alpha, 1.0f);
113 glNormal3f(0.0f, 0.0f, -1.0f);
114 glVertex3f(0.0f, -alpha, 0.0f);
115 glVertex3f(0.0f, alpha, 0.0f);
116 glVertex3f(1.0f, alpha, 0.0f);
117 glVertex3f(1.0f, -alpha, 0.0f);
119 glNormal3f(1.0f, 0.0f, 0.0f);
120 glVertex3f(1.0f, -alpha, 0.0f);
121 glVertex3f(1.0f, alpha, 0.0f);
122 glVertex3f(1.0f, alpha, 1.0f);
123 glVertex3f(1.0f, -alpha, 1.0f);
125 glNormal3f(-1.0f, 0.0f, 0.0f);
126 glVertex3f(0.0f, -alpha, 0.0f);
127 glVertex3f(0.0f, -alpha, 1.0f);
128 glVertex3f(0.0f, alpha, 1.0f);
129 glVertex3f(0.0f, alpha, 0.0f);
131 glNormal3f(0.0f, -1.0f, 0.0f);
132 glVertex3f(0.0f, -alpha, 0.0f);
133 glVertex3f(1.0f, -alpha, 0.0f);
134 glVertex3f(1.0f, -alpha, 1.0f);
135 glVertex3f(0.0f, -alpha, 1.0f);
141 unit_rhomboid(int wire)
143 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
145 glNormal3f(0.0f, 1.0f, 0.0f);
146 glVertex3f(0, alpha, 0);
147 glVertex3f(1, alpha, 1);
148 glVertex3f(1, alpha, 2);
149 glVertex3f(0, alpha, 1);
151 glNormal3f(0.0f, -1.0f, 0.0f);
152 glVertex3f(0, -alpha, 0);
153 glVertex3f(0, -alpha, 1);
154 glVertex3f(1, -alpha, 2);
155 glVertex3f(1, -alpha, 1);
157 glNormal3f(-1.0f, 0.0f, 0.0f);
158 glVertex3f(0, alpha, 0);
159 glVertex3f(0, alpha, 1);
160 glVertex3f(0, -alpha, 1);
161 glVertex3f(0, -alpha, 0);
164 glNormal3f(0.0f, 0.0f, 1.0f);
165 glVertex3f(0, alpha, 1);
166 glVertex3f(1, alpha, 2);
167 glVertex3f(1, -alpha, 2);
168 glVertex3f(0, -alpha, 1);
170 glNormal3f(1.0f, 0.0f, 0.0f);
171 glVertex3f(1, alpha, 1);
172 glVertex3f(1, -alpha, 1);
173 glVertex3f(1, -alpha, 2);
174 glVertex3f(1, alpha, 2);
176 glNormal3f(0.0f, 0.0f, 1.0f);
177 glVertex3f(0, alpha, 0);
178 glVertex3f(0, -alpha, 0);
179 glVertex3f(1, -alpha, 1);
180 glVertex3f(1, alpha, 1);
185 /* All of the pieces have the same thickness so all of the Y values are the same */
188 tangram_get_sm_tri_dl(int wire)
190 GLuint triangle = glGenLists(1);
191 glNewList(triangle, GL_COMPILE);
192 glScalef(small_scale, small_scale, small_scale);
199 tangram_get_lg_tri_dl(int wire)
201 GLuint triangle = glGenLists(1);
202 glNewList(triangle, GL_COMPILE);
203 glScalef(large_scale, small_scale, large_scale);
210 tangram_get_md_tri_dl(int wire)
212 GLuint triangle = glGenLists(1);
213 glNewList(triangle, GL_COMPILE);
214 glScalef(medium_scale, small_scale, medium_scale);
221 tangram_get_square_dl(int wire)
223 GLuint square = glGenLists(1);
224 glNewList(square, GL_COMPILE);
225 glScalef(small_scale, small_scale, small_scale);
232 tangram_get_rhomboid_dl(int wire)
234 GLuint rhomboid = glGenLists(1);
235 glNewList(rhomboid, GL_COMPILE);
236 glScalef(small_scale, small_scale, small_scale);