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 #define small_scale ( 1 )
15 #define large_scale ( 2 )
16 #define medium_scale ( 1.414213562 )
20 static void tri_45_90(int wire)
22 GLfloat vertices[][3] = {
31 glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
34 glVertex3fv(vertices[0]);
36 glVertex3fv(vertices[2]);
38 glVertex3fv(vertices[1]);
41 glVertex3fv(vertices[3]);
43 glVertex3fv(vertices[4]);
45 glVertex3fv(vertices[5]);
48 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
50 glVertex3fv(vertices[2]);
52 glVertex3fv(vertices[5]);
54 glVertex3fv(vertices[4]);
56 glVertex3fv(vertices[1]);
59 glVertex3fv(vertices[0]);
61 glVertex3fv(vertices[1]);
63 glVertex3fv(vertices[4]);
65 glVertex3fv(vertices[3]);
68 glVertex3fv(vertices[0]);
70 glVertex3fv(vertices[3]);
72 glVertex3fv(vertices[5]);
74 glVertex3fv(vertices[2]);
78 void unit_cube(int wire)
80 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
83 glNormal3f(0.0f, 1.0f, 0.0f);
84 glVertex3f(0.0f, alpha, 0.0f);
85 glVertex3f(0.0f, alpha, 1.0f);
86 glVertex3f(1.0f, alpha, 1.0f);
87 glVertex3f(1.0f, alpha, 0.0f);
89 glNormal3f(0.0f, 0.0f, 1.0f);
90 glVertex3f(0.0f, -alpha, 1.0f);
91 glVertex3f(1.0f, -alpha, 1.0f);
92 glVertex3f(1.0f, alpha, 1.0f);
93 glVertex3f(0.0f, alpha, 1.0f);
95 glNormal3f(0.0f, 0.0f, -1.0f);
96 glVertex3f(0.0f, -alpha, 0.0f);
97 glVertex3f(0.0f, alpha, 0.0f);
98 glVertex3f(1.0f, alpha, 0.0f);
99 glVertex3f(1.0f, -alpha, 0.0f);
101 glNormal3f(1.0f, 0.0f, 0.0f);
102 glVertex3f(1.0f, -alpha, 0.0f);
103 glVertex3f(1.0f, alpha, 0.0f);
104 glVertex3f(1.0f, alpha, 1.0f);
105 glVertex3f(1.0f, -alpha, 1.0f);
107 glNormal3f(-1.0f, 0.0f, 0.0f);
108 glVertex3f(0.0f, -alpha, 0.0f);
109 glVertex3f(0.0f, -alpha, 1.0f);
110 glVertex3f(0.0f, alpha, 1.0f);
111 glVertex3f(0.0f, alpha, 0.0f);
113 glNormal3f(0.0f, -1.0f, 0.0f);
114 glVertex3f(0.0f, -alpha, 0.0f);
115 glVertex3f(1.0f, -alpha, 0.0f);
116 glVertex3f(1.0f, -alpha, 1.0f);
117 glVertex3f(0.0f, -alpha, 1.0f);
122 void unit_rhomboid(int wire)
124 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
126 glNormal3f(0.0f, 1.0f, 0.0f);
127 glVertex3f(0, alpha, 0);
128 glVertex3f(1, alpha, 1);
129 glVertex3f(1, alpha, 2);
130 glVertex3f(0, alpha, 1);
132 glNormal3f(0.0f, -1.0f, 0.0f);
133 glVertex3f(0, -alpha, 0);
134 glVertex3f(0, -alpha, 1);
135 glVertex3f(1, -alpha, 2);
136 glVertex3f(1, -alpha, 1);
138 glNormal3f(-1.0f, 0.0f, 0.0f);
139 glVertex3f(0, alpha, 0);
140 glVertex3f(0, alpha, 1);
141 glVertex3f(0, -alpha, 1);
142 glVertex3f(0, -alpha, 0);
145 glNormal3f(0.0f, 0.0f, 1.0f);
146 glVertex3f(0, alpha, 1);
147 glVertex3f(1, alpha, 2);
148 glVertex3f(1, -alpha, 2);
149 glVertex3f(0, -alpha, 1);
151 glNormal3f(1.0f, 0.0f, 0.0f);
152 glVertex3f(1, alpha, 1);
153 glVertex3f(1, -alpha, 1);
154 glVertex3f(1, -alpha, 2);
155 glVertex3f(1, alpha, 2);
157 glNormal3f(0.0f, 0.0f, 1.0f);
158 glVertex3f(0, alpha, 0);
159 glVertex3f(0, -alpha, 0);
160 glVertex3f(1, -alpha, 1);
161 glVertex3f(1, alpha, 1);
166 /* All of the pieces have the same thickness so all of the Y values are the same */
168 GLuint get_sm_tri_dl(int wire)
170 GLuint triangle = glGenLists(1);
171 glNewList(triangle, GL_COMPILE);
172 glScalef(small_scale, small_scale, small_scale);
178 GLuint get_lg_tri_dl(int wire)
180 GLuint triangle = glGenLists(1);
181 glNewList(triangle, GL_COMPILE);
182 glScalef(large_scale, small_scale, large_scale);
188 GLuint get_md_tri_dl(int wire)
190 GLuint triangle = glGenLists(1);
191 glNewList(triangle, GL_COMPILE);
192 glScalef(medium_scale, small_scale, medium_scale);
198 GLuint get_square_dl(int wire)
200 GLuint square = glGenLists(1);
201 glNewList(square, GL_COMPILE);
202 glScalef(small_scale, small_scale, small_scale);
208 GLuint get_rhomboid_dl(int wire)
210 GLuint rhomboid = glGenLists(1);
211 glNewList(rhomboid, GL_COMPILE);
212 glScalef(small_scale, small_scale, small_scale);