1
/* -*- Mode: C; tab-width: 4 -*- */
2
/* Klein --- Klein Bottle, Moebius and other parametric surfaces
7
* 2000: written by Andrey Mirtchovski <mirtchov@cpsc.ucalgary.ca
9
* 01-Mar-2003 mirtchov modified as a xscreensaver hack
1
/* klein --- Shows a Klein bottle that rotates in 4d or on which you
5
static const char sccsid[] = "@(#)klein.c 1.1 08/10/04 xlockmore";
8
/* Copyright (c) 2005-2009 Carsten Steger <carsten@mirsanmir.org>. */
11
* Permission to use, copy, modify, and distribute this software and its
12
* documentation for any purpose and without fee is hereby granted,
13
* provided that the above copyright notice appear in all copies and that
14
* both that copyright notice and this permission notice appear in
15
* supporting documentation.
17
* This file is provided AS IS with no warranties of any kind. The author
18
* shall have no liability with respect to the infringement of copyrights,
19
* trade secrets or any patents by this file or any part thereof. In no
20
* event will the author be liable for any lost revenue or profits or
21
* other special, indirect and consequential damages.
24
* C. Steger - 08/10/04: Initial version
25
* C. Steger - 09/08/03: Changes to the parameter handling
29
* This program shows two different Klein bottles in 4d: the figure-8 Klein
30
* bottle or the Lawson Klein bottle. You can walk on the Klein bottle, see
31
* it turn in 4d, or walk on it while it turns in 4d. The figure-8 Klein
32
* bottle is well known in its 3d form. The 4d form used in this program is
33
* an extension of the 3d form to 4d that does not intersect itself in 4d
34
* (which can be seen in the depth colors mode). The Lawson Klein bottle,
35
* on the other hand, does intersect itself in 4d. Its primary use is that
36
* it has a nice appearance for walking and for turning in 3d. The Klein
37
* bottle is a non-orientable surface. To make this apparent, the two-sided
38
* color mode can be used. Alternatively, orientation markers (curling
39
* arrows) can be drawn as a texture map on the surface of the Klein bottle.
40
* While walking on the Klein bottle, you will notice that the orientation
41
* of the curling arrows changes (which it must because the Klein bottle is
42
* non-orientable). The program projects the 4d Klein bottle to 3d using
43
* either a perspective or an orthographic projection. Which of the two
44
* alternatives looks more appealing depends on the viewing mode and the
45
* Klein bottle. For example, the Lawson Klein bottle looks nicest when
46
* projected perspectively. The figure-8 Klein bottle, on the other
47
* hand, looks nicer while walking when projected orthographically from 4d.
48
* The projected Klein bottle can then be projected to the screen either
49
* perspectively or orthographically. When using the walking modes,
50
* perspective projection to the screen should be used. There are three
51
* display modes for the Klein bottle: mesh (wireframe), solid, or
52
* transparent. Furthermore, the appearance of the Klein bottle can be as
53
* a solid object or as a set of see-through bands. Finally, the colors
54
* with with the Klein bottle is drawn can be set to two-sided, rainbow, or
55
* depth. In the first case, the Klein bottle is drawn with red on one
56
* "side" and green on the "other side". Of course, the Klein bottle only
57
* has one side, so the color jumps from red to green along a curve on the
58
* surface of the Klein bottle. This mode enables you to see that the Klein
59
* bottle is non-orientable. The second mode draws the Klein bottle with
60
* fully saturated rainbow colors. This gives a very nice effect when
61
* combined with the see-through bands mode or with the orientation markers
62
* drawn. The third mode draws the Klein bottle with colors that are chosen
63
* according to the 4d "depth" of the points. This mode enables you to see
64
* that the figure-8 Klein bottle does not intersect itself in 4d, while the
65
* Lawson Klein bottle does intersect itself. The rotation speed for each
66
* of the six planes around which the Klein bottle rotates can be chosen.
67
* For the walk-and-turn more, only the rotation speeds around the true 4d
68
* planes are used (the xy, xz, and yz planes). Furthermore, in the walking
69
* modes the walking direction in the 2d base square of the Klein bottle and
70
* the walking speed can be chosen. This program is somewhat inspired by
71
* Thomas Banchoff's book "Beyond the Third Dimension: Geometry, Computer
72
* Graphics, and Higher Dimensions", Scientific American Library, 1990.
76
#define M_PI 3.14159265358979323846
79
#define KLEIN_BOTTLE_FIGURE_8 0
80
#define KLEIN_BOTTLE_LAWSON 1
81
#define NUM_KLEIN_BOTTLES 2
83
#define DISP_WIREFRAME 0
84
#define DISP_SURFACE 1
85
#define DISP_TRANSPARENT 2
86
#define NUM_DISPLAY_MODES 3
88
#define APPEARANCE_SOLID 0
89
#define APPEARANCE_BANDS 1
90
#define NUM_APPEARANCES 2
92
#define COLORS_TWOSIDED 0
93
#define COLORS_RAINBOW 1
94
#define COLORS_DEPTH 2
99
#define VIEW_WALKTURN 2
100
#define NUM_VIEW_MODES 3
102
#define DISP_3D_PERSPECTIVE 0
103
#define DISP_3D_ORTHOGRAPHIC 1
104
#define NUM_DISP_3D_MODES 2
106
#define DISP_4D_PERSPECTIVE 0
107
#define DISP_4D_ORTHOGRAPHIC 1
108
#define NUM_DISP_4D_MODES 2
110
#define DEF_KLEIN_BOTTLE "random"
111
#define DEF_DISPLAY_MODE "random"
112
#define DEF_APPEARANCE "random"
113
#define DEF_COLORS "random"
114
#define DEF_VIEW_MODE "random"
115
#define DEF_MARKS "False"
116
#define DEF_PROJECTION_3D "random"
117
#define DEF_PROJECTION_4D "random"
118
#define DEF_SPEEDWX "1.1"
119
#define DEF_SPEEDWY "1.3"
120
#define DEF_SPEEDWZ "1.5"
121
#define DEF_SPEEDXY "1.7"
122
#define DEF_SPEEDXZ "1.9"
123
#define DEF_SPEEDYZ "2.1"
124
#define DEF_WALK_DIRECTION "7.0"
125
#define DEF_WALK_SPEED "20.0"
14
# define DEFAULTS "*delay: 20000 \n" \
128
# define DEFAULTS "*delay: 10000 \n" \
129
"*showFPS: False \n" \
17
131
# define refresh_klein 0
18
# include "xlockmore.h" /* from the xscreensaver distribution */
132
# include "xlockmore.h" /* from the xscreensaver distribution */
19
133
#else /* !STANDALONE */
20
# include "xlock.h" /* from the xlockmore distribution */
134
# include "xlock.h" /* from the xlockmore distribution */
21
135
#endif /* !STANDALONE */
25
#define DEF_SPIN "True"
26
#define DEF_WANDER "False"
27
#define DEF_RAND "True"
28
#define DEF_SPEED "150"
139
#include <X11/keysym.h>
31
141
#include "gltrackball.h"
34
#define countof(x) (sizeof((x))/sizeof((*x)))
36
/* surfaces being drawn */
49
/* primitives to draw with
50
* note that we skip the polygons and
51
* triangle fans -- too slow
53
* also removed triangle_strip and quads --
54
* just doesn't look good enough
68
static Bool do_wander;
70
static XrmOptionDescRec opts[] = {
71
{"-speed", ".speed", XrmoptionSepArg, 0 },
72
{ "-spin", ".spin", XrmoptionNoArg, "True" },
73
{ "+spin", ".spin", XrmoptionNoArg, "False" },
74
{ "-wander", ".wander", XrmoptionNoArg, "True" },
75
{ "+wander", ".wander", XrmoptionNoArg, "False" },
76
{ "-random", ".rand", XrmoptionNoArg, "True" },
77
{ "+random", ".rand", XrmoptionNoArg, "False" },
80
static argtype vars[] = {
81
{&rand, "rand", "Random", DEF_RAND, t_Bool},
82
{&do_spin, "spin", "Spin", DEF_SPIN, t_Bool},
83
{&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
84
{&speed, "speed", "Speed", DEF_SPEED, t_Int},
88
ENTRYPOINT ModeSpecOpt klein_opts = {countof(opts), opts, countof(vars), vars, NULL};
145
ModStruct klein_description =
146
{"klein", "init_klein", "draw_klein", "release_klein",
147
"draw_klein", "change_klein", NULL, &klein_opts,
148
25000, 1, 1, 1, 1.0, 4, "",
149
"Rotate a Klein bottle in 4d or walk on it", 0, NULL};
154
static char *klein_bottle;
155
static int bottle_type;
157
static int display_mode;
159
static int appearance;
160
static char *color_mode;
162
static char *view_mode;
165
static char *proj_3d;
166
static int projection_3d;
167
static char *proj_4d;
168
static int projection_4d;
169
static float speed_wx;
170
static float speed_wy;
171
static float speed_wz;
172
static float speed_xy;
173
static float speed_xz;
174
static float speed_yz;
175
static float walk_direction;
176
static float walk_speed;
179
static XrmOptionDescRec opts[] =
181
{"-klein-bottle", ".kleinBottle", XrmoptionSepArg, 0 },
182
{"-figure-8", ".kleinBottle", XrmoptionNoArg, "figure-8" },
183
{"-lawson", ".kleinBottle", XrmoptionNoArg, "lawson" },
184
{"-mode", ".displayMode", XrmoptionSepArg, 0 },
185
{"-wireframe", ".displayMode", XrmoptionNoArg, "wireframe" },
186
{"-surface", ".displayMode", XrmoptionNoArg, "surface" },
187
{"-transparent", ".displayMode", XrmoptionNoArg, "transparent" },
188
{"-appearance", ".appearance", XrmoptionSepArg, 0 },
189
{"-solid", ".appearance", XrmoptionNoArg, "solid" },
190
{"-bands", ".appearance", XrmoptionNoArg, "bands" },
191
{"-colors", ".colors", XrmoptionSepArg, 0 },
192
{"-twosided", ".colors", XrmoptionNoArg, "two-sided" },
193
{"-rainbow", ".colors", XrmoptionNoArg, "rainbow" },
194
{"-depth", ".colors", XrmoptionNoArg, "depth" },
195
{"-view-mode", ".viewMode", XrmoptionSepArg, 0 },
196
{"-walk", ".viewMode", XrmoptionNoArg, "walk" },
197
{"-turn", ".viewMode", XrmoptionNoArg, "turn" },
198
{"-walk-turn", ".viewMode", XrmoptionNoArg, "walk-turn" },
199
{"-orientation-marks", ".marks", XrmoptionNoArg, "on"},
200
{"+orientation-marks", ".marks", XrmoptionNoArg, "off"},
201
{"-projection-3d", ".projection3d", XrmoptionSepArg, 0 },
202
{"-perspective-3d", ".projection3d", XrmoptionNoArg, "perspective" },
203
{"-orthographic-3d", ".projection3d", XrmoptionNoArg, "orthographic" },
204
{"-projection-4d", ".projection4d", XrmoptionSepArg, 0 },
205
{"-perspective-4d", ".projection4d", XrmoptionNoArg, "perspective" },
206
{"-orthographic-4d", ".projection4d", XrmoptionNoArg, "orthographic" },
207
{"-speed-wx", ".speedwx", XrmoptionSepArg, 0 },
208
{"-speed-wy", ".speedwy", XrmoptionSepArg, 0 },
209
{"-speed-wz", ".speedwz", XrmoptionSepArg, 0 },
210
{"-speed-xy", ".speedxy", XrmoptionSepArg, 0 },
211
{"-speed-xz", ".speedxz", XrmoptionSepArg, 0 },
212
{"-speed-yz", ".speedyz", XrmoptionSepArg, 0 },
213
{"-walk-direction", ".walkDirection", XrmoptionSepArg, 0 },
214
{"-walk-speed", ".walkSpeed", XrmoptionSepArg, 0 }
217
static argtype vars[] =
219
{ &klein_bottle, "kleinBottle", "KleinBottle", DEF_KLEIN_BOTTLE, t_String },
220
{ &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String },
221
{ &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String },
222
{ &color_mode, "colors", "Colors", DEF_COLORS, t_String },
223
{ &view_mode, "viewMode", "ViewMode", DEF_VIEW_MODE, t_String },
224
{ &marks, "marks", "Marks", DEF_MARKS, t_Bool },
225
{ &proj_3d, "projection3d", "Projection3d", DEF_PROJECTION_3D, t_String },
226
{ &proj_4d, "projection4d", "Projection4d", DEF_PROJECTION_4D, t_String },
227
{ &speed_wx, "speedwx", "Speedwx", DEF_SPEEDWX, t_Float},
228
{ &speed_wy, "speedwy", "Speedwy", DEF_SPEEDWY, t_Float},
229
{ &speed_wz, "speedwz", "Speedwz", DEF_SPEEDWZ, t_Float},
230
{ &speed_xy, "speedxy", "Speedxy", DEF_SPEEDXY, t_Float},
231
{ &speed_xz, "speedxz", "Speedxz", DEF_SPEEDXZ, t_Float},
232
{ &speed_yz, "speedyz", "Speedyz", DEF_SPEEDYZ, t_Float},
233
{ &walk_direction, "walkDirection", "WalkDirection", DEF_WALK_DIRECTION, t_Float},
234
{ &walk_speed, "walkSpeed", "WalkSpeed", DEF_WALK_SPEED, t_Float}
237
ENTRYPOINT ModeSpecOpt klein_opts =
238
{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, NULL};
241
/* Radius of the Figure 8 Klein bottle */
242
#define FIGURE_8_RADIUS 2.0
244
/* Offset by which we walk above the Klein bottle */
247
/* Number of subdivisions of the Klein bottle */
251
/* Number of subdivisions per band */
99
GLXContext *glx_context;
102
trackball_state *trackball;
257
GLXContext *glx_context;
258
/* 4D rotation angles */
259
float alpha, beta, delta, zeta, eta, theta;
260
/* Movement parameters */
261
float umove, vmove, dumove, dvmove;
263
/* The viewing offset in 4d */
265
/* The viewing offset in 3d */
267
/* The 4d coordinates of the Klein bottle and their derivatives */
268
float x[(NUMU+1)*(NUMV+1)][4];
269
float xu[(NUMU+1)*(NUMV+1)][4];
270
float xv[(NUMU+1)*(NUMV+1)][4];
271
float pp[(NUMU+1)*(NUMV+1)][3];
272
float pn[(NUMU+1)*(NUMV+1)][3];
273
/* The precomputed colors of the Klein bottle */
274
float col[(NUMU+1)*(NUMV+1)][4];
275
/* The precomputed texture coordinates of the Klein bottle */
276
float tex[(NUMU+1)*(NUMV+1)][2];
277
/* The "curlicue" texture */
279
/* Aspect ratio of the current window */
281
/* Trackball states */
282
trackball_state *trackballs[2];
283
int current_trackball;
285
/* A random factor to modify the rotation speeds */
115
static kleinstruct *klein = NULL;
121
kleinstruct *kp = &klein[MI_SCREEN(mi)];
125
mi->polygon_count = 0;
126
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
128
glEnable(GL_DEPTH_TEST);
129
glEnable(GL_NORMALIZE);
130
glEnable(GL_CULL_FACE);
136
get_position (kp->rot, &x, &y, &z, !kp->button_down_p);
137
glTranslatef((x - 0.5) * 10,
141
gltrackball_rotate (kp->trackball);
143
get_rotation (kp->rot, &x, &y, &z, !kp->button_down_p);
144
glRotatef (x * 360, 1.0, 0.0, 0.0);
145
glRotatef (y * 360, 0.0, 1.0, 0.0);
146
glRotatef (z * 360, 0.0, 0.0, 1.0);
149
glScalef( 4.0, 4.0, 4.0 );
152
switch(kp->surface) {
154
for(u = -M_PI; u < M_PI; u+=kp->du){
155
for(v = -M_PI; v < M_PI; v+=kp->dv){
156
coord[0] = cos(u)*(kp->a + sin(v)*cos(u/2) -
157
sin(2*v)*sin(u/2)/2);
158
coord[1] = sin(u)*(kp->a + sin(v)*cos(u/2) -
159
sin(2*v)*sin(u/2)/2);
160
coord[2] = sin(u/2)*sin(v) + cos(u/2)*sin(2*v)/2;
161
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
168
for(u = -M_PI; u < M_PI; u+=kp->du){
169
for(v = -M_PI; v < M_PI; v+=kp->dv){
170
coord[0] = kp->a*cos(u)*sin(v);
171
coord[1] = kp->a*sin(u)*sin(v);
172
coord[2] = kp->a*(cos(v) + sin(tan((v/2))))+0.2*u;
173
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
180
for(u = -M_PI; u < M_PI; u+=kp->du){
181
for(v = -M_PI; v < M_PI; v+=kp->dv){
182
coord[0] = kp->a*(u-(u*u*u/3)+u*v*v);
183
coord[1] = kp->b*(v-(v*v*v/3)+u*u*v);
185
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
192
for(u = -M_PI; u < M_PI; u+=kp->du){
193
for(v = -M_PI; v < M_PI; v+=kp->dv){
194
coord[0] = 2*(cos(u)+u*sin(u))*sin(v)/(1+u*u*sin(v)*sin(v));
195
coord[1] = 2*(sin(u)-u*cos(u))*sin(v)/(1+u*u*sin(v)*sin(v));
196
coord[2] = sin(tan(v/2))+2*cos(v)/(1+u*u*sin(v)*sin(v));
198
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
205
for(u = -M_PI; u < M_PI; u+=kp->du){
206
for(v = -M_PI; v < M_PI; v+=kp->dv){
207
coord[0] = cos(u)+v*cos(u/2)*cos(u);
208
coord[1] = sin(u)+v*cos(u/2)*sin(u);
209
coord[2] = v*sin(u/2);
210
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
217
for(u = 0; u < 2*M_PI; u+=kp->du){
218
for(v = 0; v < 2*M_PI; v+=kp->dv){
219
coord[0] = kp->a*(1-v/(2*M_PI))*cos(2*v)*(1+cos(u))+sin(kp->c+=0.00001)*cos(2*v);
220
coord[1] = kp->a*(1-v/(2*M_PI))*sin(2*v)*(1+cos(u))+cos(kp->c+=0.00001)*sin(2*v);
221
coord[2] = sin(kp->b+=0.00001)*v/(2*M_PI)+kp->a*(1-v/(2*M_PI))*sin(u);
222
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
229
for(u = -M_PI; u < M_PI; u+=kp->du){
230
for(v = -M_PI; v < M_PI; v+=kp->dv){
231
coord[0] = u*pow(v,2) + 3*pow(v,4);
232
coord[1] = -2*u*v - 4*pow(v,3);
234
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
241
for(u = -M_PI; u < M_PI; u+=kp->du){
242
for(v = -M_PI; v < M_PI; v+=kp->dv){
243
coord[0] = kp->a*cos(u);
244
coord[1] = 1.5*cos(v) + kp->a*sin(u);
246
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
253
for(u = -M_PI; u < M_PI; u+=kp->du){
254
for(v = -M_PI; v < M_PI; v+=kp->dv){
255
coord[0] = sin(u)*kp->a;
256
coord[1] = cos(u)*kp->a;
257
coord[2] = sin(u/2)*cos(v) + cos(u/2)*sin(v);
258
glColor3f(coord[0]+0.7, coord[1]+0.7, coord[2]+0.7);
268
if (kp->render == GL_LINES)
269
mi->polygon_count /= 2;
271
kp->a = sin(kp->draw_step+=0.01);
272
kp->b = cos(kp->draw_step+=0.01);
276
/* new window size or exposure */
278
reshape_klein(ModeInfo *mi, int width, int height)
280
GLfloat h = (GLfloat) height / (GLfloat) width;
282
glViewport(0, 0, (GLint) width, (GLint) height);
283
glMatrixMode(GL_PROJECTION);
285
gluPerspective (30.0, 1/h, 1.0, 100.0);
287
glMatrixMode(GL_MODELVIEW);
289
gluLookAt( 0.0, 0.0, 30.0,
293
glClear(GL_COLOR_BUFFER_BIT);
298
klein_handle_event (ModeInfo *mi, XEvent *event)
300
kleinstruct *kp = &klein[MI_SCREEN(mi)];
302
if (event->xany.type == ButtonPress && event->xbutton.button == Button1) {
303
kp->button_down_p = True;
304
gltrackball_start (kp->trackball, event->xbutton.x, event->xbutton.y, MI_WIDTH (mi), MI_HEIGHT (mi));
306
} else if (event->xany.type == ButtonRelease && event->xbutton.button == Button1) {
307
kp->button_down_p = False;
309
} else if (event->xany.type == ButtonPress &&
310
(event->xbutton.button == Button4 ||
311
event->xbutton.button == Button5 ||
312
event->xbutton.button == Button6 ||
313
event->xbutton.button == Button7)) {
314
gltrackball_mousewheel (kp->trackball, event->xbutton.button, 10,
315
!!event->xbutton.state);
317
} else if (event->xany.type == MotionNotify && kp->button_down_p) {
318
gltrackball_track (kp->trackball, event->xmotion.x, event->xmotion.y, MI_WIDTH (mi), MI_HEIGHT (mi));
327
init_klein(ModeInfo *mi)
329
int screen = MI_SCREEN(mi);
333
if ((klein = (kleinstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (kleinstruct))) == NULL)
338
kp->window = MI_WINDOW(mi);
341
double spin_speed = 1.0;
342
double wander_speed = 0.03;
343
kp->rot = make_rotator (do_spin ? spin_speed : 0,
344
do_spin ? spin_speed : 0,
345
do_spin ? spin_speed : 0,
347
do_wander ? wander_speed : 0,
349
kp->trackball = gltrackball_init ();
353
render = random() % MY_PRIM_LAST;
354
kp->surface = random() % SURFACE_LAST;
356
render = MY_LINE_LOOP;
361
case MY_POINTS: kp->render = GL_POINTS; break;
362
case MY_LINES: kp->render = GL_LINES; break;
363
case MY_LINE_LOOP: kp->render = GL_LINE_LOOP; break;
365
kp->render = GL_LINE_LOOP;
367
/*kp->render=GL_TRIANGLE_FAN;*/
368
/*kp->render=GL_POLYGON;*/
376
if ((kp->glx_context = init_GL(mi)) != NULL) {
377
reshape_klein(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
384
draw_klein(ModeInfo * mi)
386
kleinstruct *kp = &klein[MI_SCREEN(mi)];
387
Display *display = MI_DISPLAY(mi);
388
Window window = MI_WINDOW(mi);
390
if (!kp->glx_context) return;
392
glDrawBuffer(GL_BACK);
394
glXMakeCurrent(display, window, *(kp->glx_context));
396
if (mi->fps_p) do_fps (mi);
398
glXSwapBuffers(display, window);
402
release_klein(ModeInfo * mi)
407
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
408
kleinstruct *kp = &klein[screen];
410
if (kp->glx_context) {
411
/* Display lists MUST be freed while their glXContext is current. */
412
glXMakeCurrent(MI_DISPLAY(mi), kp->window, *(kp->glx_context));
415
(void) free((void *) klein);
289
static kleinstruct *klein = (kleinstruct *) NULL;
292
/* A texture map containing a "curlicue" */
293
#define TEX_DIMENSION 64
294
static const unsigned char texture[TEX_DIMENSION*TEX_DIMENSION] = {
295
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
296
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
297
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
298
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
299
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
300
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
301
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
302
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
303
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
304
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
305
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
306
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
307
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
308
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
309
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
310
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
311
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
312
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
313
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
314
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
315
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
316
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
317
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
318
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
319
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
320
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
321
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
322
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
323
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
324
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
325
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
326
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
327
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
328
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
329
255,255,255,255,255,255,255, 58, 43, 43, 43, 43, 45, 70, 70, 70,
330
70, 70, 70, 70, 74, 98, 98, 98,100,194,255,255,255,255,255,255,
331
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
332
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
333
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
334
0, 0, 0, 0, 0, 0, 0, 30,186,255,255,255,255,255,255,255,
335
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
336
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
337
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
338
0, 0, 0, 0, 0, 1,111,244,255,255,255,255,255,255,255,255,
339
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
340
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
341
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
342
0, 0, 0, 0, 43,198,255,255,255,255,255,255,255,255,255,255,
343
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
344
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
345
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
346
0, 0, 5,123,248,255,255,255,255,255,255,255,255,255,255,255,
347
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
348
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
349
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
350
0, 50,209,255,255,255,255,255,255,255,255,255,255,255,255,255,
351
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,246,
352
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
353
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
354
74,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
355
255,255,255,255,255,255,255,255,255,255,255,255,255,255,138, 4,
356
66,229,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
357
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
358
1,170,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
359
255,255,255,255,255,255,255,255,255,255,255,255,255,153, 0, 0,
360
0, 53,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
361
255,255,255,255,255,255,255, 18, 0, 0, 0, 0, 0, 0, 0, 0,
362
0, 6,188,255,255,255,255,255,255,255,255,255,255,255,255,255,
363
255,255,255,255,255,255,255,255,255,255,255,255,213, 7, 0, 0,
364
0, 0,226,255,255,255,255,255,255,255,255,255,255,255,255,255,
365
255,255,255,255,255,255,255, 45, 0, 0, 0, 0, 0, 47, 0, 0,
366
0, 0, 22,225,255,255,255,255,255,255,255,255,255,255,255,255,
367
255,255,255,255,255,255,255,255,255,255,255,254, 54, 0, 0, 0,
368
0, 81,254,255,255,255,255,255,255,255,255,255,255,255,255,255,
369
255,255,255,255,255,255,255, 45, 0, 0, 0, 0, 56,247, 82, 0,
370
0, 0, 0, 59,253,255,255,255,255,255,255,255,255,255,255,255,
371
255,255,255,255,255,255,255,255,255,255,255,152, 0, 0, 0, 0,
372
52,243,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
373
255,255,255,255,255,255,255, 45, 0, 0, 0, 8,215,255,250, 56,
374
0, 0, 0, 0,142,255,255,255,255,255,255,255,255,255,255,255,
375
255,255,255,255,255,255,255,255,255,255,241, 19, 0, 0, 0, 15,
376
220,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
377
255,255,255,255,255,255,255, 45, 0, 0, 0,129,255,255,255,230,
378
23, 0, 0, 0, 12,230,255,255,255,255,255,255,255,255,255,255,
379
255,255,255,255,255,255,255,255,255,255,131, 0, 0, 0, 0,157,
380
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
381
255,255,255,255,255,255,255, 45, 0, 0, 49,250,255,255,255,255,
382
171, 0, 0, 0, 0,112,255,255,255,255,255,255,255,255,255,255,
383
255,255,255,255,255,255,255,255,255,246, 19, 0, 0, 0, 54,253,
384
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
385
255,255,255,255,255,255,255, 45, 0, 5,208,255,255,255,255,255,
386
255, 77, 0, 0, 0, 9,231,255,255,255,255,255,255,255,255,255,
387
255,255,255,255,255,255,255,255,255,163, 0, 0, 0, 0,186,255,
388
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
389
255,255,255,255,255,255,255, 45, 0,121,255,255,255,255,255,255,
390
255,211, 2, 0, 0, 0,134,255,255,255,255,255,255,255,255,255,
391
255,255,255,255,255,255,255,255,255, 69, 0, 0, 0, 50,255,255,
392
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
393
255,255,255,255,255,255,255, 45, 41,247,255,255,255,255,255,255,
394
255,255, 73, 0, 0, 0, 38,254,255,255,255,255,255,255,255,255,
395
255,255,255,255,255,255,255,255,237, 4, 0, 0, 0,145,255,255,
396
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
397
255,255,255,255,255,255,255, 52,201,255,255,255,255,255,255,255,
398
255,255,169, 0, 0, 0, 0,216,255,255,255,255,255,255,255,255,
399
255,255,255,255,255,255,255,255,181, 0, 0, 0, 0,229,255,255,
400
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
401
255,255,255,255,255,255,255,186,255,255,255,255,255,255,255,255,
402
255,255,247, 7, 0, 0, 0,150,255,255,255,255,255,255,255,255,
403
255,255,255,255,255,255,255,255,130, 0, 0, 0, 42,255,255,255,
404
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
405
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
406
255,255,255, 67, 0, 0, 0, 91,255,255,255,255,255,255,255,255,
407
255,255,255,255,255,255,255,255, 79, 0, 0, 0, 95,255,255,255,
408
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
409
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
410
255,255,255,120, 0, 0, 0, 56,255,255,255,255,255,255,255,255,
411
255,255,255,255,255,255,255,255, 55, 0, 0, 0,130,255,255,255,
412
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
413
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
414
255,255,255,157, 0, 0, 0, 21,255,255,255,255,255,255,255,255,
415
255,255,255,255,255,255,255,255, 34, 0, 0, 0,161,255,255,255,
416
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
417
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
418
255,255,255,179, 0, 0, 0, 2,250,255,255,255,255,255,255,255,
419
255,255,255,255,255,255,255,255, 27, 0, 0, 0,168,255,255,255,
420
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
421
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
422
255,255,255,200, 0, 0, 0, 0,249,255,255,255,255,255,255,255,
423
255,255,255,255,255,255,255,255, 27, 0, 0, 0,168,255,255,255,
424
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
425
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
426
255,255,255,200, 0, 0, 0, 0,249,255,255,255,255,255,255,255,
427
255,255,255,255,255,255,255,255, 27, 0, 0, 0,163,255,255,255,
428
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
429
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
430
255,255,255,183, 0, 0, 0, 0,249,255,255,255,255,255,255,255,
431
255,255,255,255,255,255,255,255, 42, 0, 0, 0,135,255,255,255,
432
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
433
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
434
255,255,255,161, 0, 0, 0, 17,254,255,255,255,255,255,255,255,
435
255,255,255,255,255,255,255,255, 76, 0, 0, 0,100,255,255,255,
436
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
437
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
438
255,255,255,126, 0, 0, 0, 48,255,255,255,255,255,255,255,255,
439
255,255,255,255,255,255,255,255,114, 0, 0, 0, 53,255,255,255,
440
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
441
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
442
255,255,255, 78, 0, 0, 0, 84,255,255,255,255,255,255,255,255,
443
255,255,255,255,255,255,255,255,165, 0, 0, 0, 3,241,255,255,
444
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
445
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
446
255,255,252, 16, 0, 0, 0,139,255,255,255,255,255,255,255,255,
447
255,255,255,255,255,255,255,255,228, 0, 0, 0, 0,161,255,255,
448
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
449
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
450
255,255,192, 0, 0, 0, 0,198,255,255,255,255,255,255,255,255,
451
255,255,255,255,255,255,255,255,255, 46, 0, 0, 0, 67,255,255,
452
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
453
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
454
255,255, 93, 0, 0, 0, 21,250,255,255,255,255,255,255,255,255,
455
255,255,255,255,255,255,255,255,255,139, 0, 0, 0, 1,211,255,
456
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
457
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
458
255,226, 7, 0, 0, 0,108,255,255,255,255,255,255,255,255,255,
459
255,255,255,255,255,255,255,255,255,230, 6, 0, 0, 0, 79,255,
460
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
461
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
462
255,106, 0, 0, 0, 1,206,255,255,255,255,255,255,255,255,255,
463
255,255,255,255,255,255,255,255,255,255, 97, 0, 0, 0, 0,183,
464
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
465
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
466
202, 3, 0, 0, 0, 67,255,255,255,255,255,255,255,255,255,255,
467
255,255,255,255,255,255,255,255,255,255,221, 8, 0, 0, 0, 27,
468
235,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
469
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,243,
470
40, 0, 0, 0, 0,198,255,255,255,255,255,255,255,255,255,255,
471
255,255,255,255,255,255,255,255,255,255,255,126, 0, 0, 0, 0,
472
71,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
473
255,255,255,255,255,255,255,255,255,255,255,255,255,255,253, 85,
474
0, 0, 0, 0, 96,255,255,255,255,255,255,255,255,255,255,255,
475
255,255,255,255,255,255,255,255,255,255,255,247, 44, 0, 0, 0,
476
0, 91,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
477
255,255,255,255,255,255,255,255,255,255,255,255,255,255,116, 0,
478
0, 0, 0, 25,233,255,255,255,255,255,255,255,255,255,255,255,
479
255,255,255,255,255,255,255,255,255,255,255,255,216, 11, 0, 0,
480
0, 0, 90,251,255,255,255,255,255,255,255,255,255,255,255,255,
481
255,255,255,255,255,255,255,255,255,255,255,255,252,112, 0, 0,
482
0, 0, 4,191,255,255,255,255,255,255,255,255,255,255,255,255,
483
255,255,255,255,255,255,255,255,255,255,255,255,255,174, 4, 0,
484
0, 0, 0, 72,235,255,255,255,255,255,255,255,255,255,255,255,
485
255,255,255,255,255,255,255,255,255,255,255,242, 84, 0, 0, 0,
486
0, 0,146,255,255,255,255,255,255,255,255,255,255,255,255,255,
487
255,255,255,255,255,255,255,255,255,255,255,255,255,255,150, 1,
488
0, 0, 0, 0, 27,181,255,255,255,255,255,255,255,255,255,255,
489
255,255,255,255,255,255,255,255,255,255,194, 39, 0, 0, 0, 0,
490
0,120,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
491
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,151,
492
4, 0, 0, 0, 0, 0, 77,209,255,255,255,255,255,255,255,255,
493
255,255,255,255,255,255,255,255,216, 92, 1, 0, 0, 0, 0, 0,
494
125,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
495
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
496
175, 12, 0, 0, 0, 0, 0, 1, 70,164,241,255,255,255,255,255,
497
255,255,255,255,255,242,171, 77, 2, 0, 0, 0, 0, 0, 4,150,
498
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
499
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
500
255,214, 41, 0, 0, 0, 0, 0, 0, 0, 4, 48, 98,138,163,163,
501
163,163,140,103, 55, 5, 0, 0, 0, 0, 0, 0, 0, 30,199,255,
502
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
503
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
504
255,255,245,125, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
505
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,105,240,255,255,
506
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
507
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
508
255,255,255,255,222,100, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
509
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 83,210,255,255,255,255,
510
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
511
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
512
255,255,255,255,255,255,228,136, 45, 0, 0, 0, 0, 0, 0, 0,
513
0, 0, 0, 0, 0, 0, 0, 37,125,220,255,255,255,255,255,255,
514
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
515
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
516
255,255,255,255,255,255,255,255,255,225,166,112, 74, 43, 32, 12,
517
8, 32, 40, 71,105,162,218,255,255,255,255,255,255,255,255,255,
518
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
519
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
520
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
521
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
522
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
523
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
524
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
525
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
526
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
527
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
528
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
529
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
530
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
531
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
532
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
533
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
534
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
535
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
536
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
537
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
538
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
539
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
540
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
541
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
542
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
543
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
544
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
545
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
546
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
547
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
548
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
549
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
550
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
554
/* Add a rotation around the wx-plane to the matrix m. */
555
static void rotatewx(float m[4][4], float phi)
573
/* Add a rotation around the wy-plane to the matrix m. */
574
static void rotatewy(float m[4][4], float phi)
592
/* Add a rotation around the wz-plane to the matrix m. */
593
static void rotatewz(float m[4][4], float phi)
611
/* Add a rotation around the xy-plane to the matrix m. */
612
static void rotatexy(float m[4][4], float phi)
630
/* Add a rotation around the xz-plane to the matrix m. */
631
static void rotatexz(float m[4][4], float phi)
649
/* Add a rotation around the yz-plane to the matrix m. */
650
static void rotateyz(float m[4][4], float phi)
668
/* Compute the rotation matrix m from the rotation angles. */
669
static void rotateall(float al, float be, float de, float ze, float et,
670
float th, float m[4][4])
686
/* Compute the rotation matrix m from the 4d rotation angles. */
687
static void rotateall4d(float ze, float et, float th, float m[4][4])
700
/* Multiply two rotation matrices: o=m*n. */
701
static void mult_rotmat(float m[4][4], float n[4][4], float o[4][4])
711
o[i][j] += m[i][k]*n[k][j];
717
/* Compute a 4D rotation matrix from two unit quaternions. */
718
static void quats_to_rotmat(float p[4], float q[4], float m[4][4])
720
double al, be, de, ze, et, th;
721
double r00, r01, r02, r12, r22;
723
r00 = 1.0-2.0*(p[1]*p[1]+p[2]*p[2]);
724
r01 = 2.0*(p[0]*p[1]+p[2]*p[3]);
725
r02 = 2.0*(p[2]*p[0]-p[1]*p[3]);
726
r12 = 2.0*(p[1]*p[2]+p[0]*p[3]);
727
r22 = 1.0-2.0*(p[1]*p[1]+p[0]*p[0]);
729
al = atan2(-r12,r22)*180.0/M_PI;
730
be = atan2(r02,sqrt(r00*r00+r01*r01))*180.0/M_PI;
731
de = atan2(-r01,r00)*180.0/M_PI;
733
r00 = 1.0-2.0*(q[1]*q[1]+q[2]*q[2]);
734
r01 = 2.0*(q[0]*q[1]+q[2]*q[3]);
735
r02 = 2.0*(q[2]*q[0]-q[1]*q[3]);
736
r12 = 2.0*(q[1]*q[2]+q[0]*q[3]);
737
r22 = 1.0-2.0*(q[1]*q[1]+q[0]*q[0]);
739
et = atan2(-r12,r22)*180.0/M_PI;
740
th = atan2(r02,sqrt(r00*r00+r01*r01))*180.0/M_PI;
741
ze = atan2(-r01,r00)*180.0/M_PI;
743
rotateall(al,be,de,ze,et,-th,m);
747
/* Compute a fully saturated and bright color based on an angle. */
748
static void color(double angle, float col[4])
753
if (colors == COLORS_TWOSIDED)
757
angle = fmod(angle,2.0*M_PI);
759
angle = fmod(angle,-2.0*M_PI);
760
s = floor(angle/(M_PI/3));
761
t = angle/(M_PI/3)-s;
797
if (display_mode == DISP_TRANSPARENT)
804
/* Set up the figure-8 Klein bottle coordinates, colors, and texture. */
805
static void setup_figure8(ModeInfo *mi, double umin, double umax, double vmin,
810
double cu, su, cv, sv, cv2, sv2, c2u, s2u;
811
kleinstruct *kb = &klein[MI_SCREEN(mi)];
815
for (i=0; i<=NUMU; i++)
817
for (j=0; j<=NUMV; j++)
822
if (colors == COLORS_DEPTH)
823
color((cos(u)+1.0)*M_PI*2.0/3.0,kb->col[k]);
826
kb->tex[k][0] = -32*u/(2.0*M_PI);
827
kb->tex[k][1] = 32*v/(2.0*M_PI);
836
kb->x[k][0] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*cv;
837
kb->x[k][1] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*sv;
838
kb->x[k][2] = su*sv2+s2u*cv2;
840
kb->xu[k][0] = (cu*cv2-2.0*c2u*sv2)*cv;
841
kb->xu[k][1] = (cu*cv2-2.0*c2u*sv2)*sv;
842
kb->xu[k][2] = cu*sv2+2.0*c2u*cv2;
844
kb->xv[k][0] = ((-0.5*su*sv2-0.5*s2u*cv2)*cv-
845
(su*cv2-s2u*sv2+FIGURE_8_RADIUS)*sv);
846
kb->xv[k][1] = ((-0.5*su*sv2-0.5*s2u*cv2)*sv+
847
(su*cv2-s2u*sv2+FIGURE_8_RADIUS)*cv);
848
kb->xv[k][2] = 0.5*su*cv2-0.5*s2u*sv2;
852
kb->x[k][l] /= FIGURE_8_RADIUS+1.25;
853
kb->xu[k][l] /= FIGURE_8_RADIUS+1.25;
854
kb->xv[k][l] /= FIGURE_8_RADIUS+1.25;
861
/* Set up the Lawson Klein bottle coordinates, colors, and texture. */
862
static void setup_lawson(ModeInfo *mi, double umin, double umax, double vmin,
867
double cu, su, cv, sv, cv2, sv2;
868
kleinstruct *kb = &klein[MI_SCREEN(mi)];
872
for (i=0; i<=NUMV; i++)
874
for (j=0; j<=NUMU; j++)
879
if (colors == COLORS_DEPTH)
880
color((sin(u)*cos(0.5*v)+1.0)*M_PI*2.0/3.0,kb->col[k]);
883
kb->tex[k][0] = -32*u/(2.0*M_PI);
884
kb->tex[k][1] = 32*v/(2.0*M_PI);
893
kb->x[k][2] = su*sv2;
894
kb->x[k][3] = su*cv2;
895
kb->xu[k][0] = -su*cv;
896
kb->xu[k][1] = -su*sv;
897
kb->xu[k][2] = cu*sv2;
898
kb->xu[k][3] = cu*cv2;
899
kb->xv[k][0] = -cu*sv;
900
kb->xv[k][1] = cu*cv;
901
kb->xv[k][2] = su*cv2*0.5;
902
kb->xv[k][3] = -su*sv2*0.5;
908
/* Draw a figure-8 Klein bottle projected into 3D. */
909
static int figure8(ModeInfo *mi, double umin, double umax, double vmin,
913
static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 };
914
static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 };
915
static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 };
916
static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 };
917
float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4];
918
int i, j, k, l, m, o;
920
double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4];
922
double cu, su, cv, sv, cv2, sv2, c2u, s2u;
923
float q1[4], q2[4], r1[4][4], r2[4][4];
924
kleinstruct *kb = &klein[MI_SCREEN(mi)];
926
if (view == VIEW_WALK || view == VIEW_WALKTURN)
928
/* Compute the rotation that rotates the Klein bottle in 4D without the
929
trackball rotations. */
930
rotateall4d(kb->zeta,kb->eta,kb->theta,mat);
942
xx[0] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*cv;
943
xx[1] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*sv;
944
xx[2] = su*sv2+s2u*cv2;
946
xxu[0] = (cu*cv2-2.0*c2u*sv2)*cv;
947
xxu[1] = (cu*cv2-2.0*c2u*sv2)*sv;
948
xxu[2] = cu*sv2+2.0*c2u*cv2;
950
xxv[0] = ((-0.5*su*sv2-0.5*s2u*cv2)*cv-
951
(su*cv2-s2u*sv2+FIGURE_8_RADIUS)*sv);
952
xxv[1] = ((-0.5*su*sv2-0.5*s2u*cv2)*sv+
953
(su*cv2-s2u*sv2+FIGURE_8_RADIUS)*cv);
954
xxv[2] = 0.5*su*cv2-0.5*s2u*sv2;
958
xx[l] /= FIGURE_8_RADIUS+1.25;
959
xxu[l] /= FIGURE_8_RADIUS+1.25;
960
xxv[l] /= FIGURE_8_RADIUS+1.25;
964
y[l] = (mat[l][0]*xx[0]+mat[l][1]*xx[1]+
965
mat[l][2]*xx[2]+mat[l][3]*xx[3]);
966
yu[l] = (mat[l][0]*xxu[0]+mat[l][1]*xxu[1]+
967
mat[l][2]*xxu[2]+mat[l][3]*xxu[3]);
968
yv[l] = (mat[l][0]*xxv[0]+mat[l][1]*xxv[1]+
969
mat[l][2]*xxv[2]+mat[l][3]*xxv[3]);
971
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
975
p[l] = y[l]+kb->offset4d[l];
982
s = y[3]+kb->offset4d[3];
987
r = y[l]+kb->offset4d[l];
989
pu[l] = (yu[l]*s-r*yu[3])*t;
990
pv[l] = (yv[l]*s-r*yv[3])*t;
993
n[0] = pu[1]*pv[2]-pu[2]*pv[1];
994
n[1] = pu[2]*pv[0]-pu[0]*pv[2];
995
n[2] = pu[0]*pv[1]-pu[1]*pv[0];
996
t = 1.0/(kb->side*4.0*sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]));
1000
pm[0] = pu[0]*kb->dumove+pv[0]*kb->dvmove;
1001
pm[1] = pu[1]*kb->dumove+pv[1]*kb->dvmove;
1002
pm[2] = pu[2]*kb->dumove+pv[2]*kb->dvmove;
1003
t = 1.0/(4.0*sqrt(pm[0]*pm[0]+pm[1]*pm[1]+pm[2]*pm[2]));
1007
b[0] = n[1]*pm[2]-n[2]*pm[1];
1008
b[1] = n[2]*pm[0]-n[0]*pm[2];
1009
b[2] = n[0]*pm[1]-n[1]*pm[0];
1010
t = 1.0/(4.0*sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]));
1015
/* Compute alpha, beta, delta from the three basis vectors.
1016
| -b[0] -b[1] -b[2] |
1017
m = | n[0] n[1] n[2] |
1018
| -pm[0] -pm[1] -pm[2] |
1020
kb->alpha = atan2(-n[2],-pm[2])*180/M_PI;
1021
kb->beta = atan2( -b[2],sqrt(b[0]*b[0]+b[1]*b[1]))*180/M_PI;
1022
kb->delta = atan2(b[1],-b[0])*180/M_PI;
1024
/* Compute the rotation that rotates the Klein bottle in 4D. */
1025
rotateall(kb->alpha,kb->beta,kb->delta,kb->zeta,kb->eta,kb->theta,mat);
1037
xx[0] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*cv;
1038
xx[1] = (su*cv2-s2u*sv2+FIGURE_8_RADIUS)*sv;
1039
xx[2] = su*sv2+s2u*cv2;
1042
xx[l] /= FIGURE_8_RADIUS+1.25;
1047
r += mat[l][m]*xx[m];
1050
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1053
p[l] = y[l]+kb->offset4d[l];
1057
s = y[3]+kb->offset4d[3];
1059
p[l] = (y[l]+kb->offset4d[l])/s;
1062
kb->offset3d[0] = -p[0];
1063
kb->offset3d[1] = -p[1]-DELTAY;
1064
kb->offset3d[2] = -p[2];
1068
/* Compute the rotation that rotates the Klein bottle in 4D, including
1069
the trackball rotations. */
1070
rotateall(kb->alpha,kb->beta,kb->delta,kb->zeta,kb->eta,kb->theta,r1);
1072
gltrackball_get_quaternion(kb->trackballs[0],q1);
1073
gltrackball_get_quaternion(kb->trackballs[1],q2);
1074
quats_to_rotmat(q1,q2,r2);
1076
mult_rotmat(r2,r1,mat);
1079
/* Project the points from 4D to 3D. */
1080
for (i=0; i<=NUMU; i++)
1082
for (j=0; j<=NUMV; j++)
1087
y[l] = (mat[l][0]*kb->x[o][0]+mat[l][1]*kb->x[o][1]+
1088
mat[l][2]*kb->x[o][2]+mat[l][3]*kb->x[o][3]);
1089
yu[l] = (mat[l][0]*kb->xu[o][0]+mat[l][1]*kb->xu[o][1]+
1090
mat[l][2]*kb->xu[o][2]+mat[l][3]*kb->xu[o][3]);
1091
yv[l] = (mat[l][0]*kb->xv[o][0]+mat[l][1]*kb->xv[o][1]+
1092
mat[l][2]*kb->xv[o][2]+mat[l][3]*kb->xv[o][3]);
1094
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1098
kb->pp[o][l] = (y[l]+kb->offset4d[l])+kb->offset3d[l];
1105
s = y[3]+kb->offset4d[3];
1110
r = y[l]+kb->offset4d[l];
1111
kb->pp[o][l] = r*q+kb->offset3d[l];
1112
pu[l] = (yu[l]*s-r*yu[3])*t;
1113
pv[l] = (yv[l]*s-r*yv[3])*t;
1116
kb->pn[o][0] = pu[1]*pv[2]-pu[2]*pv[1];
1117
kb->pn[o][1] = pu[2]*pv[0]-pu[0]*pv[2];
1118
kb->pn[o][2] = pu[0]*pv[1]-pu[1]*pv[0];
1119
t = 1.0/sqrt(kb->pn[o][0]*kb->pn[o][0]+kb->pn[o][1]*kb->pn[o][1]+
1120
kb->pn[o][2]*kb->pn[o][2]);
1127
if (colors == COLORS_TWOSIDED)
1129
glColor3fv(mat_diff_red);
1130
if (display_mode == DISP_TRANSPARENT)
1132
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red);
1133
glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green);
1137
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red);
1138
glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green);
1141
glBindTexture(GL_TEXTURE_2D,kb->tex_name);
1143
for (i=0; i<NUMU; i++)
1145
if (appearance == APPEARANCE_BANDS && ((i & (NUMB-1)) >= NUMB/2))
1147
if (display_mode == DISP_WIREFRAME)
1148
glBegin(GL_QUAD_STRIP);
1150
glBegin(GL_TRIANGLE_STRIP);
1151
for (j=0; j<=NUMV; j++)
1153
for (k=0; k<=1; k++)
1158
glNormal3fv(kb->pn[o]);
1159
glTexCoord2fv(kb->tex[o]);
1160
if (colors != COLORS_TWOSIDED)
1162
glColor3fv(kb->col[o]);
1163
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,kb->col[o]);
1165
glVertex3fv(kb->pp[o]);
1176
/* Draw a Lawson Klein bottle projected into 3D. */
1177
static int lawson(ModeInfo *mi, double umin, double umax, double vmin,
1181
static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 };
1182
static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 };
1183
static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 };
1184
static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 };
1185
float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4];
1186
int i, j, k, l, m, o;
1188
double cu, su, cv, sv, cv2, sv2;
1189
double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4];
1191
float q1[4], q2[4], r1[4][4], r2[4][4];
1192
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1194
if (view == VIEW_WALK || view == VIEW_WALKTURN)
1196
/* Compute the rotation that rotates the Klein bottle in 4D without the
1197
trackball rotations. */
1198
rotateall4d(kb->zeta,kb->eta,kb->theta,mat);
1218
xxv[2] = su*cv2*0.5;
1219
xxv[3] = -su*sv2*0.5;
1222
y[l] = (mat[l][0]*xx[0]+mat[l][1]*xx[1]+
1223
mat[l][2]*xx[2]+mat[l][3]*xx[3]);
1224
yu[l] = (mat[l][0]*xxu[0]+mat[l][1]*xxu[1]+
1225
mat[l][2]*xxu[2]+mat[l][3]*xxu[3]);
1226
yv[l] = (mat[l][0]*xxv[0]+mat[l][1]*xxv[1]+
1227
mat[l][2]*xxv[2]+mat[l][3]*xxv[3]);
1229
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1233
p[l] = y[l]+kb->offset4d[l];
1240
s = y[3]+kb->offset4d[3];
1245
r = y[l]+kb->offset4d[l];
1247
pu[l] = (yu[l]*s-r*yu[3])*t;
1248
pv[l] = (yv[l]*s-r*yv[3])*t;
1251
n[0] = pu[1]*pv[2]-pu[2]*pv[1];
1252
n[1] = pu[2]*pv[0]-pu[0]*pv[2];
1253
n[2] = pu[0]*pv[1]-pu[1]*pv[0];
1254
t = 1.0/(kb->side*4.0*sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]));
1258
pm[0] = pu[0]*kb->dumove+pv[0]*kb->dvmove;
1259
pm[1] = pu[1]*kb->dumove+pv[1]*kb->dvmove;
1260
pm[2] = pu[2]*kb->dumove+pv[2]*kb->dvmove;
1261
t = 1.0/(4.0*sqrt(pm[0]*pm[0]+pm[1]*pm[1]+pm[2]*pm[2]));
1265
b[0] = n[1]*pm[2]-n[2]*pm[1];
1266
b[1] = n[2]*pm[0]-n[0]*pm[2];
1267
b[2] = n[0]*pm[1]-n[1]*pm[0];
1268
t = 1.0/(4.0*sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]));
1273
/* Compute alpha, beta, delta from the three basis vectors.
1274
| -b[0] -b[1] -b[2] |
1275
m = | n[0] n[1] n[2] |
1276
| -pm[0] -pm[1] -pm[2] |
1278
kb->alpha = atan2(-n[2],-pm[2])*180/M_PI;
1279
kb->beta = atan2( -b[2],sqrt(b[0]*b[0]+b[1]*b[1]))*180/M_PI;
1280
kb->delta = atan2(b[1],-b[0])*180/M_PI;
1282
/* Compute the rotation that rotates the Klein bottle in 4D. */
1283
rotateall(kb->alpha,kb->beta,kb->delta,kb->zeta,kb->eta,kb->theta,mat);
1301
r += mat[l][m]*xx[m];
1304
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1307
p[l] = y[l]+kb->offset4d[l];
1311
s = y[3]+kb->offset4d[3];
1313
p[l] = (y[l]+kb->offset4d[l])/s;
1316
kb->offset3d[0] = -p[0];
1317
kb->offset3d[1] = -p[1]-DELTAY;
1318
kb->offset3d[2] = -p[2];
1322
/* Compute the rotation that rotates the Klein bottle in 4D, including
1323
the trackball rotations. */
1324
rotateall(kb->alpha,kb->beta,kb->delta,kb->zeta,kb->eta,kb->theta,r1);
1326
gltrackball_get_quaternion(kb->trackballs[0],q1);
1327
gltrackball_get_quaternion(kb->trackballs[1],q2);
1328
quats_to_rotmat(q1,q2,r2);
1330
mult_rotmat(r2,r1,mat);
1333
/* Project the points from 4D to 3D. */
1334
for (i=0; i<=NUMV; i++)
1336
for (j=0; j<=NUMU; j++)
1341
y[l] = (mat[l][0]*kb->x[o][0]+mat[l][1]*kb->x[o][1]+
1342
mat[l][2]*kb->x[o][2]+mat[l][3]*kb->x[o][3]);
1343
yu[l] = (mat[l][0]*kb->xu[o][0]+mat[l][1]*kb->xu[o][1]+
1344
mat[l][2]*kb->xu[o][2]+mat[l][3]*kb->xu[o][3]);
1345
yv[l] = (mat[l][0]*kb->xv[o][0]+mat[l][1]*kb->xv[o][1]+
1346
mat[l][2]*kb->xv[o][2]+mat[l][3]*kb->xv[o][3]);
1348
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1352
kb->pp[o][l] = (y[l]+kb->offset4d[l])+kb->offset3d[l];
1359
s = y[3]+kb->offset4d[3];
1364
r = y[l]+kb->offset4d[l];
1365
kb->pp[o][l] = r*q+kb->offset3d[l];
1366
pu[l] = (yu[l]*s-r*yu[3])*t;
1367
pv[l] = (yv[l]*s-r*yv[3])*t;
1370
kb->pn[o][0] = pu[1]*pv[2]-pu[2]*pv[1];
1371
kb->pn[o][1] = pu[2]*pv[0]-pu[0]*pv[2];
1372
kb->pn[o][2] = pu[0]*pv[1]-pu[1]*pv[0];
1373
t = 1.0/sqrt(kb->pn[o][0]*kb->pn[o][0]+kb->pn[o][1]*kb->pn[o][1]+
1374
kb->pn[o][2]*kb->pn[o][2]);
1381
if (colors == COLORS_TWOSIDED)
1383
glColor3fv(mat_diff_red);
1384
if (display_mode == DISP_TRANSPARENT)
1386
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red);
1387
glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green);
1391
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red);
1392
glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green);
1395
glBindTexture(GL_TEXTURE_2D,kb->tex_name);
1397
for (i=0; i<NUMV; i++)
1399
if (appearance == APPEARANCE_BANDS && ((i & (NUMB-1)) >= NUMB/2))
1401
if (display_mode == DISP_WIREFRAME)
1402
glBegin(GL_QUAD_STRIP);
1404
glBegin(GL_TRIANGLE_STRIP);
1405
for (j=0; j<=NUMU; j++)
1407
for (k=0; k<=1; k++)
1412
glNormal3fv(kb->pn[o]);
1413
glTexCoord2fv(kb->tex[o]);
1414
if (colors != COLORS_TWOSIDED)
1416
glColor3fv(kb->col[o]);
1417
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,kb->col[o]);
1419
glVertex3fv(kb->pp[o]);
1430
/* Generate a texture image that shows the orientation reversal. */
1431
static void gen_texture(ModeInfo *mi)
1433
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1435
glGenTextures(1,&kb->tex_name);
1436
glBindTexture(GL_TEXTURE_2D,kb->tex_name);
1437
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
1438
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
1439
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
1440
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
1441
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
1442
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
1443
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEX_DIMENSION,TEX_DIMENSION,0,
1444
GL_LUMINANCE,GL_UNSIGNED_BYTE,texture);
1448
static void init(ModeInfo *mi)
1450
static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
1451
static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
1452
static const GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
1453
static const GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
1454
static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
1455
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1457
if (walk_speed == 0.0)
1460
if (view == VIEW_TURN)
1462
kb->alpha = frand(360.0);
1463
kb->beta = frand(360.0);
1464
kb->delta = frand(360.0);
1473
if (bottle_type == KLEIN_BOTTLE_FIGURE_8)
1478
kb->umove = frand(2.0*M_PI);
1479
kb->vmove = frand(2.0*M_PI);
1484
if (bottle_type == KLEIN_BOTTLE_FIGURE_8)
1486
kb->offset4d[0] = 0.0;
1487
kb->offset4d[1] = 0.0;
1488
kb->offset4d[2] = 0.0;
1489
kb->offset4d[3] = 1.5;
1490
kb->offset3d[0] = 0.0;
1491
kb->offset3d[1] = 0.0;
1492
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1493
kb->offset3d[2] = -2.1;
1495
kb->offset3d[2] = -1.9;
1496
kb->offset3d[3] = 0.0;
1500
kb->offset4d[0] = 0.0;
1501
kb->offset4d[1] = 0.0;
1502
kb->offset4d[2] = 0.0;
1503
if (projection_4d == DISP_4D_PERSPECTIVE &&
1504
projection_3d == DISP_3D_ORTHOGRAPHIC)
1505
kb->offset4d[3] = 1.5;
1507
kb->offset4d[3] = 1.1;
1508
kb->offset3d[0] = 0.0;
1509
kb->offset3d[1] = 0.0;
1510
if (projection_4d == DISP_4D_ORTHOGRAPHIC)
1511
kb->offset3d[2] = -2.0;
1513
kb->offset3d[2] = -5.0;
1514
kb->offset3d[3] = 0.0;
1518
if (bottle_type == KLEIN_BOTTLE_FIGURE_8)
1519
setup_figure8(mi,0.0,2.0*M_PI,0.0,2.0*M_PI);
1521
setup_lawson(mi,0.0,2.0*M_PI,0.0,2.0*M_PI);
1524
glEnable(GL_TEXTURE_2D);
1526
glDisable(GL_TEXTURE_2D);
1528
glMatrixMode(GL_PROJECTION);
1530
if (projection_3d == DISP_3D_PERSPECTIVE ||
1531
view == VIEW_WALK || view == VIEW_WALKTURN)
1533
if (view == VIEW_WALK || view == VIEW_WALKTURN)
1534
gluPerspective(60.0,1.0,0.01,10.0);
1536
gluPerspective(60.0,1.0,0.1,10.0);
1540
glOrtho(-1.0,1.0,-1.0,1.0,0.1,10.0);
1542
glMatrixMode(GL_MODELVIEW);
1545
if (display_mode == DISP_WIREFRAME)
1547
glDisable(GL_DEPTH_TEST);
1548
glShadeModel(GL_FLAT);
1549
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
1550
glDisable(GL_LIGHTING);
1551
glDisable(GL_LIGHT0);
1552
glDisable(GL_BLEND);
1554
else if (display_mode == DISP_SURFACE)
1556
glEnable(GL_DEPTH_TEST);
1557
glDepthFunc(GL_LESS);
1558
glShadeModel(GL_SMOOTH);
1559
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
1560
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
1561
glEnable(GL_LIGHTING);
1562
glEnable(GL_LIGHT0);
1563
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
1564
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
1565
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
1566
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
1567
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
1568
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0);
1569
glDepthMask(GL_TRUE);
1570
glDisable(GL_BLEND);
1572
else if (display_mode == DISP_TRANSPARENT)
1574
glDisable(GL_DEPTH_TEST);
1575
glShadeModel(GL_SMOOTH);
1576
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
1577
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
1578
glEnable(GL_LIGHTING);
1579
glEnable(GL_LIGHT0);
1580
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
1581
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
1582
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
1583
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
1584
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
1585
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0);
1586
glDepthMask(GL_FALSE);
1588
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
1592
glDisable(GL_DEPTH_TEST);
1593
glShadeModel(GL_FLAT);
1594
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
1595
glDisable(GL_LIGHTING);
1596
glDisable(GL_LIGHT0);
1597
glDisable(GL_BLEND);
1602
/* Redisplay the Klein bottle. */
1603
static void display_klein(ModeInfo *mi)
1605
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1607
if (!kb->button_pressed)
1609
if (view == VIEW_TURN)
1611
kb->alpha += speed_wx * kb->speed_scale;
1612
if (kb->alpha >= 360.0)
1614
kb->beta += speed_wy * kb->speed_scale;
1615
if (kb->beta >= 360.0)
1617
kb->delta += speed_wz * kb->speed_scale;
1618
if (kb->delta >= 360.0)
1620
kb->zeta += speed_xy * kb->speed_scale;
1621
if (kb->zeta >= 360.0)
1623
kb->eta += speed_xz * kb->speed_scale;
1624
if (kb->eta >= 360.0)
1626
kb->theta += speed_yz * kb->speed_scale;
1627
if (kb->theta >= 360.0)
1630
if (view == VIEW_WALKTURN)
1632
kb->zeta += speed_xy * kb->speed_scale;
1633
if (kb->zeta >= 360.0)
1635
kb->eta += speed_xz * kb->speed_scale;
1636
if (kb->eta >= 360.0)
1638
kb->theta += speed_yz * kb->speed_scale;
1639
if (kb->theta >= 360.0)
1642
if (view == VIEW_WALK || view == VIEW_WALKTURN)
1644
kb->dvmove = cos(walk_direction*M_PI/180.0)*walk_speed*M_PI/4096.0;
1645
kb->vmove += kb->dvmove;
1646
if (kb->vmove >= 2.0*M_PI)
1648
kb->vmove -= 2.0*M_PI;
1649
kb->umove = 2.0*M_PI-kb->umove;
1650
kb->side = -kb->side;
1652
kb->dumove = (kb->side*sin(walk_direction*M_PI/180.0)*
1653
walk_speed*M_PI/4096.0);
1654
kb->umove += kb->dumove;
1655
if (kb->umove >= 2.0*M_PI)
1656
kb->umove -= 2.0*M_PI;
1657
if (kb->umove < 0.0)
1658
kb->umove += 2.0*M_PI;
1662
glMatrixMode(GL_PROJECTION);
1664
if (projection_3d == DISP_3D_PERSPECTIVE ||
1665
view == VIEW_WALK || view == VIEW_WALKTURN)
1667
if (view == VIEW_WALK || view == VIEW_WALKTURN)
1668
gluPerspective(60.0,kb->aspect,0.01,10.0);
1670
gluPerspective(60.0,kb->aspect,0.1,10.0);
1674
if (kb->aspect >= 1.0)
1675
glOrtho(-kb->aspect,kb->aspect,-1.0,1.0,0.1,10.0);
1677
glOrtho(-1.0,1.0,-1.0/kb->aspect,1.0/kb->aspect,0.1,10.0);
1679
glMatrixMode(GL_MODELVIEW);
1682
if (bottle_type == KLEIN_BOTTLE_FIGURE_8)
1683
mi->polygon_count = figure8(mi,0.0,2.0*M_PI,0.0,2.0*M_PI);
1685
mi->polygon_count = lawson(mi,0.0,2.0*M_PI,0.0,2.0*M_PI);
1689
ENTRYPOINT void reshape_klein(ModeInfo *mi, int width, int height)
1691
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1693
kb->WindW = (GLint)width;
1694
kb->WindH = (GLint)height;
1695
glViewport(0,0,width,height);
1696
kb->aspect = (GLfloat)width/(GLfloat)height;
1700
ENTRYPOINT Bool klein_handle_event(ModeInfo *mi, XEvent *event)
1702
Display *display = MI_DISPLAY(mi);
1703
kleinstruct *kb = &klein[MI_SCREEN(mi)];
1706
if (event->xany.type == ButtonPress &&
1707
event->xbutton.button == Button1)
1709
kb->button_pressed = True;
1710
gltrackball_start(kb->trackballs[kb->current_trackball],
1711
event->xbutton.x, event->xbutton.y,
1712
MI_WIDTH(mi), MI_HEIGHT(mi));
1715
else if (event->xany.type == ButtonRelease &&
1716
event->xbutton.button == Button1)
1718
kb->button_pressed = False;
1721
else if (event->xany.type == KeyPress)
1723
sym = XKeycodeToKeysym(display,event->xkey.keycode,0);
1724
if (sym == XK_Shift_L || sym == XK_Shift_R)
1726
kb->current_trackball = 1;
1727
if (kb->button_pressed)
1728
gltrackball_start(kb->trackballs[kb->current_trackball],
1729
event->xbutton.x, event->xbutton.y,
1730
MI_WIDTH(mi), MI_HEIGHT(mi));
1734
else if (event->xany.type == KeyRelease)
1736
sym = XKeycodeToKeysym(display,event->xkey.keycode,0);
1737
if (sym == XK_Shift_L || sym == XK_Shift_R)
1739
kb->current_trackball = 0;
1740
if (kb->button_pressed)
1741
gltrackball_start(kb->trackballs[kb->current_trackball],
1742
event->xbutton.x, event->xbutton.y,
1743
MI_WIDTH(mi), MI_HEIGHT(mi));
1747
else if (event->xany.type == MotionNotify && kb->button_pressed)
1749
gltrackball_track(kb->trackballs[kb->current_trackball],
1750
event->xmotion.x, event->xmotion.y,
1751
MI_WIDTH(mi), MI_HEIGHT(mi));
1760
*-----------------------------------------------------------------------------
1761
*-----------------------------------------------------------------------------
1763
*-----------------------------------------------------------------------------
1764
*-----------------------------------------------------------------------------
1768
*-----------------------------------------------------------------------------
1769
* Initialize klein. Called each time the window changes.
1770
*-----------------------------------------------------------------------------
1773
ENTRYPOINT void init_klein(ModeInfo *mi)
1779
klein = (kleinstruct *)calloc(MI_NUM_SCREENS(mi),
1780
sizeof(kleinstruct));
1784
kb = &klein[MI_SCREEN(mi)];
1787
kb->trackballs[0] = gltrackball_init();
1788
kb->trackballs[1] = gltrackball_init();
1789
kb->current_trackball = 0;
1790
kb->button_pressed = False;
1792
/* Set the Klein bottle. */
1793
if (!strcasecmp(klein_bottle,"random"))
1795
bottle_type = random() % NUM_KLEIN_BOTTLES;
1797
else if (!strcasecmp(klein_bottle,"figure-8"))
1799
bottle_type = KLEIN_BOTTLE_FIGURE_8;
1801
else if (!strcasecmp(klein_bottle,"lawson"))
1803
bottle_type = KLEIN_BOTTLE_LAWSON;
1807
bottle_type = random() % NUM_KLEIN_BOTTLES;
1810
/* Set the display mode. */
1811
if (!strcasecmp(mode,"random"))
1813
display_mode = random() % NUM_DISPLAY_MODES;
1815
else if (!strcasecmp(mode,"wireframe"))
1817
display_mode = DISP_WIREFRAME;
1819
else if (!strcasecmp(mode,"surface"))
1821
display_mode = DISP_SURFACE;
1823
else if (!strcasecmp(mode,"transparent"))
1825
display_mode = DISP_TRANSPARENT;
1829
display_mode = random() % NUM_DISPLAY_MODES;
1832
/* Orientation marks don't make sense in wireframe mode. */
1833
if (display_mode == DISP_WIREFRAME)
1836
/* Set the appearance. */
1837
if (!strcasecmp(appear,"random"))
1839
appearance = random() % NUM_APPEARANCES;
1841
else if (!strcasecmp(appear,"solid"))
1843
appearance = APPEARANCE_SOLID;
1845
else if (!strcasecmp(appear,"bands"))
1847
appearance = APPEARANCE_BANDS;
1851
appearance = random() % NUM_APPEARANCES;
1854
/* Set the color mode. */
1855
if (!strcasecmp(color_mode,"random"))
1857
colors = random() % NUM_COLORS;
1859
else if (!strcasecmp(color_mode,"two-sided"))
1861
colors = COLORS_TWOSIDED;
1863
else if (!strcasecmp(color_mode,"rainbow"))
1865
colors = COLORS_RAINBOW;
1867
else if (!strcasecmp(color_mode,"depth"))
1869
colors = COLORS_DEPTH;
1873
colors = random() % NUM_COLORS;
1876
/* Set the view mode. */
1877
if (!strcasecmp(view_mode,"random"))
1879
view = random() % NUM_VIEW_MODES;
1881
else if (!strcasecmp(view_mode,"walk"))
1885
else if (!strcasecmp(view_mode,"turn"))
1889
else if (!strcasecmp(view_mode,"walk-turn"))
1891
view = VIEW_WALKTURN;
1895
view = random() % NUM_VIEW_MODES;
1898
/* Set the 3d projection mode. */
1899
if (!strcasecmp(proj_3d,"random"))
1901
/* Orthographic projection only makes sense in turn mode. */
1902
if (view == VIEW_TURN)
1903
projection_3d = random() % NUM_DISP_3D_MODES;
1905
projection_3d = DISP_3D_PERSPECTIVE;
1907
else if (!strcasecmp(proj_3d,"perspective"))
1909
projection_3d = DISP_3D_PERSPECTIVE;
1911
else if (!strcasecmp(proj_3d,"orthographic"))
1913
projection_3d = DISP_3D_ORTHOGRAPHIC;
1917
/* Orthographic projection only makes sense in turn mode. */
1918
if (view == VIEW_TURN)
1919
projection_3d = random() % NUM_DISP_3D_MODES;
1921
projection_3d = DISP_3D_PERSPECTIVE;
1924
/* Set the 4d projection mode. */
1925
if (!strcasecmp(proj_4d,"random"))
1927
projection_4d = random() % NUM_DISP_4D_MODES;
1929
else if (!strcasecmp(proj_4d,"perspective"))
1931
projection_4d = DISP_4D_PERSPECTIVE;
1933
else if (!strcasecmp(proj_4d,"orthographic"))
1935
projection_4d = DISP_4D_ORTHOGRAPHIC;
1939
projection_4d = random() % NUM_DISP_4D_MODES;
1942
/* Modify the speeds to a useful range in walk-and-turn mode. */
1943
if (view == VIEW_WALKTURN)
1953
/* make multiple screens rotate at slightly different rates. */
1954
kb->speed_scale = 0.9 + frand(0.3);
1956
if ((kb->glx_context = init_GL(mi)) != NULL)
1958
reshape_klein(mi,MI_WIDTH(mi),MI_HEIGHT(mi));
1959
glDrawBuffer(GL_BACK);
1969
*-----------------------------------------------------------------------------
1970
* Called by the mainline code periodically to update the display.
1971
*-----------------------------------------------------------------------------
1973
ENTRYPOINT void draw_klein(ModeInfo *mi)
1975
Display *display = MI_DISPLAY(mi);
1976
Window window = MI_WINDOW(mi);
1981
kb = &klein[MI_SCREEN(mi)];
1983
MI_IS_DRAWN(mi) = True;
1984
if (!kb->glx_context)
1987
glXMakeCurrent(display,window,*(kb->glx_context));
1989
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1999
glXSwapBuffers(display,window);
2004
*-----------------------------------------------------------------------------
2005
* The display is being taken away from us. Free up malloc'ed
2006
* memory and X resources that we've alloc'ed. Only called
2007
* once, we must zap everything for every screen.
2008
*-----------------------------------------------------------------------------
2011
ENTRYPOINT void release_klein(ModeInfo *mi)
2017
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
2019
kleinstruct *kb = &klein[screen];
2021
if (kb->glx_context)
2022
kb->glx_context = (GLXContext *)NULL;
2024
(void) free((void *)klein);
2025
klein = (kleinstruct *)NULL;
2031
ENTRYPOINT void change_klein(ModeInfo *mi)
2033
kleinstruct *kb = &klein[MI_SCREEN(mi)];
2035
if (!kb->glx_context)
2038
glXMakeCurrent(MI_DISPLAY(mi),MI_WINDOW(mi),*(kb->glx_context));
2041
#endif /* !STANDALONE */
422
2043
XSCREENSAVER_MODULE ("Klein", klein)
424
/*********************************************************/