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
13 # include <OpenGL/gl.h>
18 #include "tangram_shapes.h"
20 #define small_scale ( 1 )
21 #define large_scale ( 2 )
22 #define medium_scale ( 1.414213562 )
26 static void tri_45_90(int wire)
28 GLfloat vertices[][3] = {
37 glBegin((wire) ? GL_LINE_LOOP : GL_TRIANGLES);
40 glVertex3fv(vertices[0]);
42 glVertex3fv(vertices[2]);
44 glVertex3fv(vertices[1]);
47 glVertex3fv(vertices[3]);
49 glVertex3fv(vertices[4]);
51 glVertex3fv(vertices[5]);
54 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
56 glVertex3fv(vertices[2]);
58 glVertex3fv(vertices[5]);
60 glVertex3fv(vertices[4]);
62 glVertex3fv(vertices[1]);
65 glVertex3fv(vertices[0]);
67 glVertex3fv(vertices[1]);
69 glVertex3fv(vertices[4]);
71 glVertex3fv(vertices[3]);
74 glVertex3fv(vertices[0]);
76 glVertex3fv(vertices[3]);
78 glVertex3fv(vertices[5]);
80 glVertex3fv(vertices[2]);
85 void unit_cube(int wire)
87 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
90 glNormal3f(0.0f, 1.0f, 0.0f);
91 glVertex3f(0.0f, alpha, 0.0f);
92 glVertex3f(0.0f, alpha, 1.0f);
93 glVertex3f(1.0f, alpha, 1.0f);
94 glVertex3f(1.0f, alpha, 0.0f);
96 glNormal3f(0.0f, 0.0f, 1.0f);
97 glVertex3f(0.0f, -alpha, 1.0f);
98 glVertex3f(1.0f, -alpha, 1.0f);
99 glVertex3f(1.0f, alpha, 1.0f);
100 glVertex3f(0.0f, alpha, 1.0f);
102 glNormal3f(0.0f, 0.0f, -1.0f);
103 glVertex3f(0.0f, -alpha, 0.0f);
104 glVertex3f(0.0f, alpha, 0.0f);
105 glVertex3f(1.0f, alpha, 0.0f);
106 glVertex3f(1.0f, -alpha, 0.0f);
108 glNormal3f(1.0f, 0.0f, 0.0f);
109 glVertex3f(1.0f, -alpha, 0.0f);
110 glVertex3f(1.0f, alpha, 0.0f);
111 glVertex3f(1.0f, alpha, 1.0f);
112 glVertex3f(1.0f, -alpha, 1.0f);
114 glNormal3f(-1.0f, 0.0f, 0.0f);
115 glVertex3f(0.0f, -alpha, 0.0f);
116 glVertex3f(0.0f, -alpha, 1.0f);
117 glVertex3f(0.0f, alpha, 1.0f);
118 glVertex3f(0.0f, alpha, 0.0f);
120 glNormal3f(0.0f, -1.0f, 0.0f);
121 glVertex3f(0.0f, -alpha, 0.0f);
122 glVertex3f(1.0f, -alpha, 0.0f);
123 glVertex3f(1.0f, -alpha, 1.0f);
124 glVertex3f(0.0f, -alpha, 1.0f);
130 void unit_rhomboid(int wire)
132 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
134 glNormal3f(0.0f, 1.0f, 0.0f);
135 glVertex3f(0, alpha, 0);
136 glVertex3f(1, alpha, 1);
137 glVertex3f(1, alpha, 2);
138 glVertex3f(0, alpha, 1);
140 glNormal3f(0.0f, -1.0f, 0.0f);
141 glVertex3f(0, -alpha, 0);
142 glVertex3f(0, -alpha, 1);
143 glVertex3f(1, -alpha, 2);
144 glVertex3f(1, -alpha, 1);
146 glNormal3f(-1.0f, 0.0f, 0.0f);
147 glVertex3f(0, alpha, 0);
148 glVertex3f(0, alpha, 1);
149 glVertex3f(0, -alpha, 1);
150 glVertex3f(0, -alpha, 0);
153 glNormal3f(0.0f, 0.0f, 1.0f);
154 glVertex3f(0, alpha, 1);
155 glVertex3f(1, alpha, 2);
156 glVertex3f(1, -alpha, 2);
157 glVertex3f(0, -alpha, 1);
159 glNormal3f(1.0f, 0.0f, 0.0f);
160 glVertex3f(1, alpha, 1);
161 glVertex3f(1, -alpha, 1);
162 glVertex3f(1, -alpha, 2);
163 glVertex3f(1, alpha, 2);
165 glNormal3f(0.0f, 0.0f, 1.0f);
166 glVertex3f(0, alpha, 0);
167 glVertex3f(0, -alpha, 0);
168 glVertex3f(1, -alpha, 1);
169 glVertex3f(1, alpha, 1);
174 /* All of the pieces have the same thickness so all of the Y values are the same */
176 GLuint get_sm_tri_dl(int wire)
178 GLuint triangle = glGenLists(1);
179 glNewList(triangle, GL_COMPILE);
180 glScalef(small_scale, small_scale, small_scale);
186 GLuint get_lg_tri_dl(int wire)
188 GLuint triangle = glGenLists(1);
189 glNewList(triangle, GL_COMPILE);
190 glScalef(large_scale, small_scale, large_scale);
196 GLuint get_md_tri_dl(int wire)
198 GLuint triangle = glGenLists(1);
199 glNewList(triangle, GL_COMPILE);
200 glScalef(medium_scale, small_scale, medium_scale);
206 GLuint get_square_dl(int wire)
208 GLuint square = glGenLists(1);
209 glNewList(square, GL_COMPILE);
210 glScalef(small_scale, small_scale, small_scale);
216 GLuint get_rhomboid_dl(int wire)
218 GLuint rhomboid = glGenLists(1);
219 glNewList(rhomboid, GL_COMPILE);
220 glScalef(small_scale, small_scale, small_scale);