59
66
#define rnd() (frand(1.0))
61
68
GLfloat speed; /* jwz -- overall speed factor applied to all motion */
71
GLfloat cfg_explosion;
64
74
static XrmOptionDescRec opts[] = {
65
75
{"-speed", ".boxed.speed", XrmoptionSepArg, 0},
76
{"-balls", ".boxed.balls", XrmoptionSepArg, 0},
77
{"-ballsize", ".boxed.ballsize", XrmoptionSepArg, 0},
78
{"-explosion", ".boxed.explosion", XrmoptionSepArg, 0},
68
81
static argtype vars[] = {
69
82
{&speed, "speed", "Speed", DEF_SPEED, t_Float},
83
{&cfg_balls, "balls", "Balls", DEF_BALLS, t_Int},
84
{&cfg_ballsize, "ballsize", "Ball Size", DEF_BALLSIZE, t_Float},
85
{&cfg_explosion, "explosion", "Exlosion", DEF_BALLSIZE, t_Float},
72
88
ModeSpecOpt boxed_opts = {countof(opts), opts, countof(vars), vars, NULL};
378
384
addvectors(&bman->balls[b].loc,&bman->balls[b].loc,&bman->balls[b].dir);
379
385
/* boundary check */
380
386
if (bman->balls[b].loc.y < bman->balls[b].radius) { /* ball onder bodem? (bodem @ y=0) */
381
if ((bman->balls[b].loc.x < -100.0) ||
382
(bman->balls[b].loc.x > 100.0) ||
383
(bman->balls[b].loc.z < -100.0) ||
384
(bman->balls[b].loc.z > 100.0)) {
387
if ((bman->balls[b].loc.x < -95.0) ||
388
(bman->balls[b].loc.x > 95.0) ||
389
(bman->balls[b].loc.z < -95.0) ||
390
(bman->balls[b].loc.z > 95.0)) {
385
391
if (bman->balls[b].loc.y < -1000.0)
386
392
createball(&bman->balls[b]);
512
518
scalevector(&tman->vertices[pos+1],&tman->vertices[pos+1],scale);
513
519
scalevector(&tman->vertices[pos+2],&tman->vertices[pos+2],scale);
521
tman->vertices[pos+0].x += avgdir.x;
522
tman->vertices[pos+0].y += avgdir.y;
523
tman->vertices[pos+0].z += avgdir.z;
524
tman->vertices[pos+1].x += avgdir.x;
525
tman->vertices[pos+1].y += avgdir.y;
526
tman->vertices[pos+1].z += avgdir.z;
527
tman->vertices[pos+2].x += avgdir.x;
528
tman->vertices[pos+2].y += avgdir.y;
529
tman->vertices[pos+2].z += avgdir.z;
515
531
/* bereken nieuwe richting */
516
532
scalevector(&tman->tris[i].dir,&avgdir,explosion);
517
533
dvect.x = (0.1f - 0.2f*rnd());
539
555
/* boundary check */
540
556
if (t->tris[b].far) continue;
541
557
if (t->tris[b].loc.y < 0) { /* onder bodem ? */
542
if ((t->tris[b].loc.x > -100.0f) &
543
(t->tris[b].loc.x < 100.0f) &
544
(t->tris[b].loc.z > -100.0f) &
545
(t->tris[b].loc.z < 100.0f)) { /* in veld */
558
if ((t->tris[b].loc.x > -95.0f) &
559
(t->tris[b].loc.x < 95.0f) &
560
(t->tris[b].loc.z > -95.0f) &
561
(t->tris[b].loc.z < 95.0f)) { /* in veld */
546
562
t->tris[b].dir.y = -(t->tris[b].dir.y);
547
563
t->tris[b].loc.y = -t->tris[b].loc.y;
548
564
scalevector(&t->tris[b].dir,&t->tris[b].dir,0.80f); /* dampening */
619
635
void setdefaultconfig(boxed_config *config)
621
config->numballs = NUMBALLS;
637
cfg_balls = MAX(3,MIN(40,cfg_balls));
638
cfg_ballsize = MAX(1.0f,MIN(5.0f,cfg_ballsize));
639
cfg_explosion = MAX(0.0f,MIN(50.0f,cfg_explosion));
640
config->numballs = cfg_balls;
622
641
config->textures = TRUE;
623
642
config->transparent = FALSE;
624
config->explosion = 25.0f;
625
config->ballsize = BALLSIZE;
643
config->explosion = cfg_explosion;
644
config->ballsize = cfg_ballsize;
626
645
config->camspeed = 35.0f;
900
920
glLoadIdentity();
902
922
gp->tic += 0.01f;
923
gp->camtic += 0.01f + 0.01f * sin(gp->tic * speed);
904
925
/* rotate camera around (0,0,0), looking at (0,0,0), up is (0,1,0) */
905
dcam = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->tic/CAMDISTANCE_SPEED) * speed);
906
v1.x = dcam * sin((gp->tic/gp->cam_x_speed) * speed);
907
v1.z = dcam * cos((gp->tic/gp->cam_z_speed) * speed);
908
v1.y = CAM_HEIGHT * sin((gp->tic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT;
926
dcam = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed);
927
v1.x = dcam * sin((gp->camtic/gp->cam_x_speed) * speed);
928
v1.z = dcam * cos((gp->camtic/gp->cam_z_speed) * speed);
929
v1.y = CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT;
909
930
gluLookAt(v1.x,v1.y,v1.z,0.0,0.0,0.0,0.0,1.0,0.0);
911
glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient);
912
glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse);
913
glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular);
914
glLightfv(GL_LIGHT0, GL_POSITION, l0_position);
915
glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient);
916
glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse);
917
glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular);
918
glLightfv(GL_LIGHT1, GL_POSITION, l1_position);
924
glMaterialfv(GL_FRONT, GL_SPECULAR, black);
925
glMaterialfv(GL_FRONT, GL_EMISSION, lblue);
926
glMaterialfv(GL_FRONT,GL_AMBIENT,black);
927
glMaterialf(GL_FRONT, GL_SHININESS, 5.0);
933
glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient);
934
glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse);
935
glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular);
936
glLightfv(GL_LIGHT0, GL_POSITION, l0_position);
937
glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient);
938
glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse);
939
glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular);
940
glLightfv(GL_LIGHT1, GL_POSITION, l1_position);
946
glMaterialfv(GL_FRONT, GL_SPECULAR, black);
947
glMaterialfv(GL_FRONT, GL_EMISSION, lblue);
948
glMaterialfv(GL_FRONT,GL_AMBIENT,black);
949
glMaterialf(GL_FRONT, GL_SHININESS, 5.0);
930
953
/* draw ground grid */