22
19
* other special, indirect and consequential damages.
24
21
* The RotateAroundU() routine was adapted from the book
25
* "Computer Graphics Principles and Practice
22
* "Computer Graphics Principles and Practice
26
23
* Foley - vanDam - Feiner - Hughes
27
24
* Second Edition" Pag. 227, exercise 5.15.
29
26
* This mode shows some interesting scenes that are impossible OR very
30
27
* wierd to build in the real universe. Much of the scenes are inspirated
31
28
* on Mauritz Cornelis Escher's works which derivated the mode's name.
32
29
* M.C. Escher (1898-1972) was a dutch artist and many people prefer to
33
30
* say he was a mathematician.
35
* Thanks goes to Brian Paul for making it possible and inexpensive to use
32
* Thanks goes to Brian Paul for making it possible and inexpensive to use
38
35
* Since I'm not a native English speaker, my apologies for any grammatical
41
38
* My e-mail address is
39
* mfvianna@centroin.com.br
44
41
* Marcelo F. Vianna (Jun-01-1997)
46
43
* Revision History:
47
* 01-Jan-98: Mode separated from escher and renamed
48
* 08-Jun-97: New scene implemented: "Impossible Cage" based in a M.C. Escher's
49
* painting with the same name (quite similar). The first GL mode
50
* to use texture mapping.
51
* The "Impossible Cage" scene doesn't use DEPTH BUFFER, the
52
* wood planks are drawn consistently using GL_CULL_FACE, and
53
* the painter's algorithm is used to sort the planks.
55
* 07-Jun-97: Speed ups in Moebius Strip using GL_CULL_FACE.
57
* 03-Jun-97: Initial Release (Only one scene: "Moebius Strip")
58
* The Moebius Strip scene was inspirated in a M.C. Escher's
59
* painting named Moebius Strip II in wich ants walk across a
60
* Moebius Strip path, sometimes meeting each other and sometimes
61
* being in "opposite faces" (note that the moebius strip has
62
* only one face and one edge).
44
* 05-Apr-2002: Removed all gllist uses (fix some bug with nvidia driver)
45
* 01-Mar-2001: Added FPS stuff E.Lassauge <lassauge@mail.dotcom.fr>
46
* 01-Nov-2000: Allocation checks
47
* 01-Jan-1998: Mode separated from escher and renamed
48
* 08-Jun-1997: New scene implemented: "Impossible Cage" based in a M.C.
49
* Escher's painting with the same name (quite similar). The
50
* first GL mode to use texture mapping.
51
* The "Impossible Cage" scene doesn't use DEPTH BUFFER, the
52
* wood planks are drawn consistently using GL_CULL_FACE, and
53
* the painter's algorithm is used to sort the planks.
55
* 07-Jun-1997: Speed ups in Moebius Strip using GL_CULL_FACE.
57
* 03-Jun-1997: Initial Release (Only one scene: "Moebius Strip")
58
* The Moebius Strip scene was inspirated in a M.C. Escher's
59
* painting named Moebius Strip II in wich ants walk across a
60
* Moebius Strip path, sometimes meeting each other and sometimes
61
* being in "opposite faces" (note that the moebius strip has
62
* only one face and one edge).
150
149
static float MaterialWhite[] =
151
150
{0.7, 0.7, 0.7, 1.0};
153
static cagestruct *cage = NULL;
154
static GLuint objects;
156
#define ObjWoodPlank 0
152
static cagestruct *cage = (cagestruct *) NULL;
158
154
#define PlankWidth 3.0
159
155
#define PlankHeight 0.35
160
156
#define PlankThickness 0.15
163
159
draw_woodplank(cagestruct * cp)
165
if (!cp->AreObjectsDefined[ObjWoodPlank]) {
166
glNewList(objects + ObjWoodPlank, GL_COMPILE_AND_EXECUTE);
170
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
172
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
174
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
176
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
177
glNormal3f(0, 0, -1);
179
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
181
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
183
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
185
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
188
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
190
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
192
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
194
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
195
glNormal3f(0, -1, 0);
197
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
199
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
201
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
203
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
206
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
208
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
210
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
212
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
213
glNormal3f(-1, 0, 0);
215
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
217
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
219
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
221
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
224
cp->AreObjectsDefined[ObjWoodPlank] = 1;
226
(void) printf("WoodPlank drawn SLOWLY\n");
229
glCallList(objects + ObjWoodPlank);
231
(void) printf("WoodPlank drawn quickly\n");
164
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
166
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
168
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
170
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
171
glNormal3f(0, 0, -1);
173
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
175
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
177
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
179
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
182
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
184
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
186
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
188
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
189
glNormal3f(0, -1, 0);
191
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
193
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
195
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
197
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
200
glVertex3f(PlankWidth, -PlankHeight, PlankThickness);
202
glVertex3f(PlankWidth, -PlankHeight, -PlankThickness);
204
glVertex3f(PlankWidth, PlankHeight, -PlankThickness);
206
glVertex3f(PlankWidth, PlankHeight, PlankThickness);
207
glNormal3f(-1, 0, 0);
209
glVertex3f(-PlankWidth, PlankHeight, PlankThickness);
211
glVertex3f(-PlankWidth, PlankHeight, -PlankThickness);
213
glVertex3f(-PlankWidth, -PlankHeight, -PlankThickness);
215
glVertex3f(-PlankWidth, -PlankHeight, PlankThickness);
237
222
draw_impossiblecage(cagestruct * cp)
240
225
glRotatef(90, 0, 1, 0);
241
226
glTranslatef(0.0, PlankHeight - PlankWidth, -PlankThickness - PlankWidth);
227
if (!draw_woodplank(cp))
245
231
glRotatef(90, 0, 0, 1);
246
232
glTranslatef(0.0, PlankHeight - PlankWidth, PlankWidth - PlankThickness);
233
if (!draw_woodplank(cp))
250
237
glRotatef(90, 0, 1, 0);
251
238
glTranslatef(0.0, PlankWidth - PlankHeight, -PlankThickness - PlankWidth);
239
if (!draw_woodplank(cp))
255
243
glTranslatef(0.0, PlankWidth - PlankHeight, 3 * PlankThickness - PlankWidth);
244
if (!draw_woodplank(cp))
259
248
glRotatef(90, 0, 0, 1);
260
249
glTranslatef(0.0, PlankWidth - PlankHeight, PlankWidth - PlankThickness);
250
if (!draw_woodplank(cp))
264
254
glTranslatef(0.0, PlankWidth - PlankHeight, PlankWidth - 3 * PlankThickness);
255
if (!draw_woodplank(cp))
268
259
glTranslatef(0.0, PlankHeight - PlankWidth, 3 * PlankThickness - PlankWidth);
260
if (!draw_woodplank(cp))
272
264
glRotatef(90, 0, 0, 1);
273
265
glTranslatef(0.0, PlankHeight - PlankWidth, PlankThickness - PlankWidth);
266
if (!draw_woodplank(cp))
277
270
glTranslatef(0.0, PlankHeight - PlankWidth, PlankWidth - 3 * PlankThickness);
271
if (!draw_woodplank(cp))
281
275
glRotatef(90, 0, 1, 0);
282
276
glTranslatef(0.0, PlankHeight - PlankWidth, PlankWidth + PlankThickness);
277
if (!draw_woodplank(cp))
286
281
glRotatef(90, 0, 0, 1);
287
282
glTranslatef(0.0, PlankWidth - PlankHeight, PlankThickness - PlankWidth);
283
if (!draw_woodplank(cp))
291
287
glRotatef(90, 0, 1, 0);
292
288
glTranslatef(0.0, PlankWidth - PlankHeight, PlankWidth + PlankThickness);
289
if (!draw_woodplank(cp))
298
reshape_cage(ModeInfo * mi, int width, int height)
296
reshape(ModeInfo * mi, int width, int height)
300
298
cagestruct *cp = &cage[MI_SCREEN(mi)];
302
301
glViewport(0, 0, cp->WindW = (GLint) width, cp->WindH = (GLint) height);
303
302
glMatrixMode(GL_PROJECTION);
304
303
glLoadIdentity();
305
304
glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
306
305
glMatrixMode(GL_MODELVIEW);
310
} else if (width >= 512) {
317
cp->AreObjectsDefined[ObjWoodPlank] = 0;
323
315
glClearDepth(1.0);
324
316
glClearColor(0.0, 0.0, 0.0, 1.0);