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 )
32 static void tri_45_90(int wire)
34 GLfloat vertices[][3] = {
43 glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
46 glVertex3fv(vertices[0]);
48 glVertex3fv(vertices[2]);
50 glVertex3fv(vertices[1]);
53 glVertex3fv(vertices[3]);
55 glVertex3fv(vertices[4]);
57 glVertex3fv(vertices[5]);
60 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
62 glVertex3fv(vertices[2]);
64 glVertex3fv(vertices[5]);
66 glVertex3fv(vertices[4]);
68 glVertex3fv(vertices[1]);
71 glVertex3fv(vertices[0]);
73 glVertex3fv(vertices[1]);
75 glVertex3fv(vertices[4]);
77 glVertex3fv(vertices[3]);
80 glVertex3fv(vertices[0]);
82 glVertex3fv(vertices[3]);
84 glVertex3fv(vertices[5]);
86 glVertex3fv(vertices[2]);
91 void unit_cube(int wire)
93 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
96 glNormal3f(0.0f, 1.0f, 0.0f);
97 glVertex3f(0.0f, alpha, 0.0f);
98 glVertex3f(0.0f, alpha, 1.0f);
99 glVertex3f(1.0f, alpha, 1.0f);
100 glVertex3f(1.0f, alpha, 0.0f);
102 glNormal3f(0.0f, 0.0f, 1.0f);
103 glVertex3f(0.0f, -alpha, 1.0f);
104 glVertex3f(1.0f, -alpha, 1.0f);
105 glVertex3f(1.0f, alpha, 1.0f);
106 glVertex3f(0.0f, alpha, 1.0f);
108 glNormal3f(0.0f, 0.0f, -1.0f);
109 glVertex3f(0.0f, -alpha, 0.0f);
110 glVertex3f(0.0f, alpha, 0.0f);
111 glVertex3f(1.0f, alpha, 0.0f);
112 glVertex3f(1.0f, -alpha, 0.0f);
114 glNormal3f(1.0f, 0.0f, 0.0f);
115 glVertex3f(1.0f, -alpha, 0.0f);
116 glVertex3f(1.0f, alpha, 0.0f);
117 glVertex3f(1.0f, alpha, 1.0f);
118 glVertex3f(1.0f, -alpha, 1.0f);
120 glNormal3f(-1.0f, 0.0f, 0.0f);
121 glVertex3f(0.0f, -alpha, 0.0f);
122 glVertex3f(0.0f, -alpha, 1.0f);
123 glVertex3f(0.0f, alpha, 1.0f);
124 glVertex3f(0.0f, alpha, 0.0f);
126 glNormal3f(0.0f, -1.0f, 0.0f);
127 glVertex3f(0.0f, -alpha, 0.0f);
128 glVertex3f(1.0f, -alpha, 0.0f);
129 glVertex3f(1.0f, -alpha, 1.0f);
130 glVertex3f(0.0f, -alpha, 1.0f);
136 void unit_rhomboid(int wire)
138 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
140 glNormal3f(0.0f, 1.0f, 0.0f);
141 glVertex3f(0, alpha, 0);
142 glVertex3f(1, alpha, 1);
143 glVertex3f(1, alpha, 2);
144 glVertex3f(0, alpha, 1);
146 glNormal3f(0.0f, -1.0f, 0.0f);
147 glVertex3f(0, -alpha, 0);
148 glVertex3f(0, -alpha, 1);
149 glVertex3f(1, -alpha, 2);
150 glVertex3f(1, -alpha, 1);
152 glNormal3f(-1.0f, 0.0f, 0.0f);
153 glVertex3f(0, alpha, 0);
154 glVertex3f(0, alpha, 1);
155 glVertex3f(0, -alpha, 1);
156 glVertex3f(0, -alpha, 0);
159 glNormal3f(0.0f, 0.0f, 1.0f);
160 glVertex3f(0, alpha, 1);
161 glVertex3f(1, alpha, 2);
162 glVertex3f(1, -alpha, 2);
163 glVertex3f(0, -alpha, 1);
165 glNormal3f(1.0f, 0.0f, 0.0f);
166 glVertex3f(1, alpha, 1);
167 glVertex3f(1, -alpha, 1);
168 glVertex3f(1, -alpha, 2);
169 glVertex3f(1, alpha, 2);
171 glNormal3f(0.0f, 0.0f, 1.0f);
172 glVertex3f(0, alpha, 0);
173 glVertex3f(0, -alpha, 0);
174 glVertex3f(1, -alpha, 1);
175 glVertex3f(1, alpha, 1);
180 /* All of the pieces have the same thickness so all of the Y values are the same */
182 GLuint get_sm_tri_dl(int wire)
184 GLuint triangle = glGenLists(1);
185 glNewList(triangle, GL_COMPILE);
186 glScalef(small_scale, small_scale, small_scale);
192 GLuint get_lg_tri_dl(int wire)
194 GLuint triangle = glGenLists(1);
195 glNewList(triangle, GL_COMPILE);
196 glScalef(large_scale, small_scale, large_scale);
202 GLuint get_md_tri_dl(int wire)
204 GLuint triangle = glGenLists(1);
205 glNewList(triangle, GL_COMPILE);
206 glScalef(medium_scale, small_scale, medium_scale);
212 GLuint get_square_dl(int wire)
214 GLuint square = glGenLists(1);
215 glNewList(square, GL_COMPILE);
216 glScalef(small_scale, small_scale, small_scale);
222 GLuint get_rhomboid_dl(int wire)
224 GLuint rhomboid = glGenLists(1);
225 glNewList(rhomboid, GL_COMPILE);
226 glScalef(small_scale, small_scale, small_scale);