89
87
static argtype vars[] = {
90
{(caddr_t *) &do_spin, "spin", "Spin", DEF_SPIN, t_Bool},
91
{(caddr_t *) &do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
92
{(caddr_t *) &speed, "speed", "Speed", DEF_SPEED, t_Float},
88
{&do_spin, "spin", "Spin", DEF_SPIN, t_Bool},
89
{&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
90
{&speed, "speed", "Speed", DEF_SPEED, t_Float},
95
93
ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
107
105
glMatrixMode(GL_PROJECTION);
108
106
glLoadIdentity();
107
gluPerspective (30.0, 1/h, 1.0, 100.0);
110
gluPerspective( 30.0, 1/h, 1.0, 100.0 );
111
gluLookAt( 0.0, 0.0, 15.0,
109
glMatrixMode(GL_MODELVIEW);
111
gluLookAt( 0.0, 0.0, 30.0,
114
glMatrixMode(GL_MODELVIEW);
116
glTranslatef(0.0, 0.0, -15.0);
118
115
glClear(GL_COLOR_BUFFER_BIT);
123
gl_init (ModeInfo *mi)
125
/* ball_configuration *bp = &bps[MI_SCREEN(mi)]; */
126
int wire = MI_IS_WIREFRAME(mi);
128
static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0};
132
glLightfv(GL_LIGHT0, GL_POSITION, pos);
133
glEnable(GL_CULL_FACE);
134
glEnable(GL_LIGHTING);
136
glEnable(GL_DEPTH_TEST);
141
/* lifted from lament.c */
142
#define RAND(n) ((long) ((random() & 0x7fffffff) % ((long) (n))))
143
#define RANDSIGN() ((random() & 1) ? 1 : -1)
146
rotate(GLfloat *pos, GLfloat *v, GLfloat *dv, GLfloat max_v)
161
if (ppos < 0) abort();
162
if (ppos > 1.0) abort();
163
*pos = (*pos > 0 ? ppos : -ppos);
169
if (*v > max_v || *v < -max_v)
173
/* If it stops, start it going in the other direction. */
180
/* keep going in the same direction */
195
/* Alter direction of rotational acceleration randomly. */
196
if (! (random() % 120))
199
/* Change acceleration very occasionally. */
200
if (! (random() % 200))
204
else if (random() & 1)
213
120
randomize_spikes (ModeInfo *mi)
215
122
ball_configuration *bp = &bps[MI_SCREEN(mi)];
190
ball_handle_event (ModeInfo *mi, XEvent *event)
192
ball_configuration *bp = &bps[MI_SCREEN(mi)];
194
if (event->xany.type == ButtonPress &&
195
event->xbutton.button == Button1)
197
bp->button_down_p = True;
198
gltrackball_start (bp->trackball,
199
event->xbutton.x, event->xbutton.y,
200
MI_WIDTH (mi), MI_HEIGHT (mi));
203
else if (event->xany.type == ButtonRelease &&
204
event->xbutton.button == Button1)
206
bp->button_down_p = False;
209
else if (event->xany.type == ButtonPress &&
210
(event->xbutton.button == Button4 ||
211
event->xbutton.button == Button5))
213
gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
214
!!event->xbutton.state);
217
else if (event->xany.type == MotionNotify &&
220
gltrackball_track (bp->trackball,
221
event->xmotion.x, event->xmotion.y,
222
MI_WIDTH (mi), MI_HEIGHT (mi));
281
231
init_ball (ModeInfo *mi)
297
247
bp = &bps[MI_SCREEN(mi)];
299
if ((bp->glx_context = init_GL(mi)) != NULL) {
301
reshape_ball (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
249
bp->glx_context = init_GL(mi);
251
reshape_ball (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
255
GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0};
256
GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};
257
GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
258
GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};
260
glEnable(GL_LIGHTING);
262
glEnable(GL_DEPTH_TEST);
263
glEnable(GL_CULL_FACE);
265
glLightfv(GL_LIGHT0, GL_POSITION, pos);
266
glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
267
glLightfv(GL_LIGHT0, GL_DIFFUSE, dif);
268
glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
272
double spin_speed = 10.0;
273
double wander_speed = 0.12;
274
double spin_accel = 2.0;
276
bp->rot = make_rotator (do_spin ? spin_speed : 0,
277
do_spin ? spin_speed : 0,
278
do_spin ? spin_speed : 0,
280
do_wander ? wander_speed : 0,
282
bp->trackball = gltrackball_init ();
304
bp->rotx = frand(1.0) * RANDSIGN();
305
bp->roty = frand(1.0) * RANDSIGN();
306
bp->rotz = frand(1.0) * RANDSIGN();
308
/* bell curve from 0-6 degrees, avg 3 */
309
bp->dx = (frand(2) + frand(2) + frand(2)) / (360/2);
310
bp->dy = (frand(2) + frand(2) + frand(2)) / (360/2);
311
bp->dz = (frand(2) + frand(2) + frand(2)) / (360/2);
313
bp->d_max = bp->dx * 2;
315
bp->ddx = 0.00006 + frand(0.00003);
316
bp->ddy = 0.00006 + frand(0.00003);
317
bp->ddz = 0.00006 + frand(0.00003);
319
285
bp->ncolors = 128;
320
286
bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
321
287
make_smooth_colormap (0, 0, 0,
349
315
Window window = MI_WINDOW(mi);
352
static GLfloat color1[4] = {0.0, 0.0, 0.0, 1.0};
353
static GLfloat color2[4] = {0.0, 0.0, 0.0, 1.0};
318
static GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
319
static GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};
320
static GLfloat bspec[4] = {1.0, 1.0, 1.0, 1.0};
321
static GLfloat sspec[4] = {0.0, 0.0, 0.0, 1.0};
322
static GLfloat bshiny = 128.0;
323
static GLfloat sshiny = 0.0;
355
325
if (!bp->glx_context)
368
338
glScalef(1.1, 1.1, 1.1);
375
static int frame = 0;
377
# define SINOID(SCALE,SIZE) \
378
((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)
380
x = SINOID(0.051, 8.0);
381
y = SINOID(0.037, 8.0);
382
z = SINOID(0.131, 13.0);
384
glTranslatef(x, y, z);
392
if (x < 0) x = 1 - (x + 1);
393
if (y < 0) y = 1 - (y + 1);
394
if (z < 0) z = 1 - (z + 1);
396
glRotatef(x * 360, 1.0, 0.0, 0.0);
397
glRotatef(y * 360, 0.0, 1.0, 0.0);
398
glRotatef(z * 360, 0.0, 0.0, 1.0);
400
rotate(&bp->rotx, &bp->dx, &bp->ddx, bp->d_max);
401
rotate(&bp->roty, &bp->dy, &bp->ddy, bp->d_max);
402
rotate(&bp->rotz, &bp->dz, &bp->ddz, bp->d_max);
342
get_position (bp->rot, &x, &y, &z, !bp->button_down_p);
343
glTranslatef((x - 0.5) * 8,
347
gltrackball_rotate (bp->trackball);
349
get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p);
350
glRotatef (x * 360, 1.0, 0.0, 0.0);
351
glRotatef (y * 360, 0.0, 1.0, 0.0);
352
glRotatef (z * 360, 0.0, 0.0, 1.0);
406
color1[0] = bp->colors[bp->ccolor].red / 65536.0;
407
color1[1] = bp->colors[bp->ccolor].green / 65536.0;
408
color1[2] = bp->colors[bp->ccolor].blue / 65536.0;
355
bcolor[0] = bp->colors[bp->ccolor].red / 65536.0;
356
bcolor[1] = bp->colors[bp->ccolor].green / 65536.0;
357
bcolor[2] = bp->colors[bp->ccolor].blue / 65536.0;
410
359
c2 = (bp->ccolor + bp->color_shift) % bp->ncolors;
411
color2[0] = bp->colors[c2].red / 65536.0;
412
color2[1] = bp->colors[c2].green / 65536.0;
413
color2[2] = bp->colors[c2].blue / 65536.0;
360
scolor[0] = bp->colors[c2].red / 65536.0;
361
scolor[1] = bp->colors[c2].green / 65536.0;
362
scolor[2] = bp->colors[c2].blue / 65536.0;
416
365
if (bp->ccolor >= bp->ncolors) bp->ccolor = 0;
367
mi->polygon_count = 0;
418
369
glScalef (2.0, 2.0, 2.0);
420
371
move_spikes (mi);
422
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color1);
373
glMaterialfv (GL_FRONT, GL_SPECULAR, bspec);
374
glMateriali (GL_FRONT, GL_SHININESS, bshiny);
375
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bcolor);
423
376
glCallList (bp->ball_list);
377
mi->polygon_count += (SPHERE_SLICES * SPHERE_STACKS);
425
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color2);
379
glMaterialfv (GL_FRONT, GL_SPECULAR, sspec);
380
glMaterialf (GL_FRONT, GL_SHININESS, sshiny);
381
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, scolor);
426
382
draw_spikes (mi);