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]);
35 glVertex3fv(vertices[2]);
36 glVertex3fv(vertices[1]);
39 glVertex3fv(vertices[3]);
40 glVertex3fv(vertices[4]);
41 glVertex3fv(vertices[5]);
44 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
46 glVertex3fv(vertices[2]);
47 glVertex3fv(vertices[5]);
48 glVertex3fv(vertices[4]);
49 glVertex3fv(vertices[1]);
52 glVertex3fv(vertices[0]);
53 glVertex3fv(vertices[1]);
54 glVertex3fv(vertices[4]);
55 glVertex3fv(vertices[3]);
58 glVertex3fv(vertices[2]);
59 glVertex3fv(vertices[5]);
60 glVertex3fv(vertices[3]);
61 glVertex3fv(vertices[0]);
65 void unit_cube(int wire)
67 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
69 glNormal3f(0.0f, -1.0f, 0.0f);
70 glVertex3f(0.0f, -alpha, 0.0f);
71 glVertex3f(1.0f, -alpha, 0.0f);
72 glVertex3f(1.0f, -alpha, 1.0f);
73 glVertex3f(0.0f, -alpha, 1.0f);
75 glNormal3f(0.0f, 0.0f, 1.0f);
76 glVertex3f(0.0f, -alpha, 1.0f);
77 glVertex3f(1.0f, -alpha, 1.0f);
78 glVertex3f(1.0f, alpha, 1.0f);
79 glVertex3f(0.0f, alpha, 1.0f);
81 glNormal3f(0.0f, 0.0f, -1.0f);
82 glVertex3f(0.0f, -alpha, 0.0f);
83 glVertex3f(0.0f, alpha, 0.0f);
84 glVertex3f(1.0f, alpha, 0.0f);
85 glVertex3f(1.0f, -alpha, 0.0f);
87 glNormal3f(1.0f, 0.0f, 0.0f);
88 glVertex3f(1.0f, -alpha, 0.0f);
89 glVertex3f(1.0f, alpha, 0.0f);
90 glVertex3f(1.0f, alpha, 1.0f);
91 glVertex3f(1.0f, -alpha, 1.0f);
93 glNormal3f(-1.0f, 0.0f, 0.0f);
94 glVertex3f(0.0f, -alpha, 0.0f);
95 glVertex3f(0.0f, -alpha, 1.0f);
96 glVertex3f(0.0f, alpha, 1.0f);
97 glVertex3f(0.0f, alpha, 0.0f);
99 glNormal3f(0.0f, 1.0f, 0.0f);
100 glVertex3f(0.0f, alpha, 0.0f);
101 glVertex3f(0.0f, alpha, 1.0f);
102 glVertex3f(1.0f, alpha, 1.0f);
103 glVertex3f(1.0f, alpha, 0.0f);
107 void unit_rhomboid(int wire)
109 glBegin((wire) ? GL_LINE_LOOP : GL_QUADS);
111 glNormal3f(0.0f, 1.0f, 0.0f);
112 glVertex3f(0, alpha, 0);
113 glVertex3f(1, alpha, 1);
114 glVertex3f(1, alpha, 2);
115 glVertex3f(0, alpha, 1);
117 glNormal3f(0.0f, -1.0f, 0.0f);
118 glVertex3f(0, -alpha, 0);
119 glVertex3f(0, -alpha, 1);
120 glVertex3f(1, -alpha, 2);
121 glVertex3f(1, -alpha, 1);
123 glNormal3f(-1.0f, 0.0f, 0.0f);
124 glVertex3f(0, alpha, 0);
125 glVertex3f(0, alpha, 1);
126 glVertex3f(0, -alpha, 1);
127 glVertex3f(0, -alpha, 0);
130 glNormal3f(0.0f, 0.0f, 1.0f);
131 glVertex3f(0, alpha, 1);
132 glVertex3f(1, alpha, 2);
133 glVertex3f(1, -alpha, 2);
134 glVertex3f(0, -alpha, 1);
136 glNormal3f(1.0f, 0.0f, 0.0f);
137 glVertex3f(1, alpha, 1);
138 glVertex3f(1, -alpha, 1);
139 glVertex3f(1, -alpha, 2);
140 glVertex3f(1, alpha, 2);
142 glNormal3f(0.0f, 0.0f, 1.0f);
143 glVertex3f(0, alpha, 0);
144 glVertex3f(0, -alpha, 0);
145 glVertex3f(1, -alpha, 1);
146 glVertex3f(1, alpha, 1);
151 /* All of the pieces have the same thickness so all of the Y values are the same */
153 GLuint get_sm_tri_dl(int wire)
155 GLuint triangle = glGenLists(1);
156 glNewList(triangle, GL_COMPILE);
157 glScalef(small_scale, small_scale, small_scale);
163 GLuint get_lg_tri_dl(int wire)
165 GLuint triangle = glGenLists(1);
166 glNewList(triangle, GL_COMPILE);
167 glScalef(large_scale, small_scale, large_scale);
173 GLuint get_md_tri_dl(int wire)
175 GLuint triangle = glGenLists(1);
176 glNewList(triangle, GL_COMPILE);
177 glScalef(medium_scale, small_scale, medium_scale);
183 GLuint get_square_dl(int wire)
185 GLuint square = glGenLists(1);
186 glNewList(square, GL_COMPILE);
187 glScalef(small_scale, small_scale, small_scale);
193 GLuint get_rhomboid_dl(int wire)
195 GLuint rhomboid = glGenLists(1);
196 glNewList(rhomboid, GL_COMPILE);
197 glScalef(small_scale, small_scale, small_scale);