~ubuntu-branches/ubuntu/gutsy/rss-glx/gutsy

« back to all changes in this revision

Viewing changes to reallyslick/c_src/lattice.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-11-30 18:21:27 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051130182127-5iww7elbiyzej1lk
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
char *hack_name = (char *)"lattice";
24
24
 
25
25
#include <stdio.h>
26
 
#include <time.h>
27
26
#include <GL/gl.h>
28
27
#include <GL/glu.h>
29
 
#include <sys/time.h>
30
28
 
31
29
#include "driver.h"
32
30
#include "lattice_textures.h"
45
43
/*
46
44
 * Where in the registry to store user defined variables 
47
45
 */
48
 
#define NUMOBJECTS 10
49
 
#define LATSIZE 10
 
46
#define NUMOBJECTS 20
 
47
#define LATSIZE 12
50
48
#define TEXSIZE 256
51
49
 
52
50
/*
82
80
 
83
81
camera ATTR_ALIGN(16) theCamera;
84
82
 
85
 
int ATTR_ALIGN(8) lattice[LATSIZE][LATSIZE][LATSIZE];
 
83
unsigned int ATTR_ALIGN(8) lattice[LATSIZE][LATSIZE][LATSIZE];
 
84
unsigned int list_base;
 
85
unsigned int texture_id[2];
 
86
 
86
87
float bPnt[10][6];      /* Border points and direction
87
88
                         * vectors where camera can cross
88
89
                         * from cube to cube */
92
93
int segments;
93
94
 
94
95
float elapsedTime;
95
 
unsigned int lastTime;
96
96
 
97
97
/*
98
98
 * Parameters edited in the dialog box 
105
105
int dFov;
106
106
int dPathrand;
107
107
int dSpeed;
108
 
int dPriority;
109
108
int dTexture;
110
109
int dSmooth;
111
110
int dFog;
259
258
{
260
259
        unsigned char *l_tex;
261
260
 
 
261
        glGenTextures (2, texture_id);
 
262
 
262
263
        switch (dTexture) {
263
264
        case 1:
264
265
                LOAD_TEXTURE (l_tex, indtex1, indtex1_compressedsize, indtex1_size)
265
 
                        glBindTexture (GL_TEXTURE_2D, 1);
266
 
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
267
 
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
268
 
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
269
 
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
270
 
                FREE_TEXTURE (l_tex)
271
 
 
272
 
                        LOAD_TEXTURE (l_tex, indtex2, indtex2_compressedsize, indtex2_size)
273
 
                        glBindTexture (GL_TEXTURE_2D, 2);
274
 
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
275
 
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
276
 
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
277
 
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
278
 
                FREE_TEXTURE (l_tex)
279
 
 
280
 
                        break;
 
266
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
 
267
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
268
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
269
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
 
270
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
 
271
                FREE_TEXTURE (l_tex)
 
272
 
 
273
                LOAD_TEXTURE (l_tex, indtex2, indtex2_compressedsize, indtex2_size)
 
274
                glBindTexture (GL_TEXTURE_2D, texture_id[1]);
 
275
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
276
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
277
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
 
278
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
 
279
                FREE_TEXTURE (l_tex)
 
280
 
 
281
                break;
281
282
 
282
283
        case 2:
283
284
                LOAD_TEXTURE (l_tex, crystex, crystex_compressedsize, crystex_size)
284
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
285
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
285
286
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
286
287
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
287
288
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
288
289
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
289
290
                FREE_TEXTURE (l_tex)
290
291
 
291
 
                        break;
 
292
                break;
292
293
 
293
294
        case 3:
294
295
                LOAD_TEXTURE (l_tex, chrometex, chrometex_compressedsize, chrometex_size)
295
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
296
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
296
297
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
297
298
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
298
299
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
299
300
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
300
301
                FREE_TEXTURE (l_tex)
301
302
 
302
 
                        break;
 
303
                break;
303
304
 
304
305
        case 4:
305
306
                LOAD_TEXTURE (l_tex, brasstex, brasstex_compressedsize, brasstex_size)
306
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
307
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
307
308
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
308
309
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
309
310
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
310
311
                gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEXSIZE, TEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, l_tex);
311
312
                FREE_TEXTURE (l_tex)
312
313
 
313
 
                        break;
 
314
                break;
314
315
 
315
316
        case 5:
316
317
                LOAD_TEXTURE (l_tex, shinytex, shinytex_compressedsize, shinytex_size)
317
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
318
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
318
319
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
319
320
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
320
321
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
321
322
                gluBuild2DMipmaps (GL_TEXTURE_2D, 4, TEXSIZE, TEXSIZE, GL_RGBA, GL_UNSIGNED_BYTE, l_tex);
322
323
                FREE_TEXTURE (l_tex)
323
324
 
324
 
                        break;
 
325
                break;
325
326
 
326
327
        case 6:
327
328
                LOAD_TEXTURE (l_tex, ghostlytex, ghostlytex_compressedsize, ghostlytex_size)
328
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
329
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
329
330
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
330
331
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
331
332
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
332
333
                gluBuild2DMipmaps (GL_TEXTURE_2D, GL_ALPHA, TEXSIZE, TEXSIZE, GL_ALPHA, GL_UNSIGNED_BYTE, l_tex);
333
334
                FREE_TEXTURE (l_tex)
334
335
 
335
 
                        break;
 
336
                break;
336
337
 
337
338
        case 7:
338
339
                LOAD_TEXTURE (l_tex, circuittex, circuittex_compressedsize, circuittex_size)
339
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
340
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
340
341
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
341
342
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
342
343
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
343
344
                gluBuild2DMipmaps (GL_TEXTURE_2D, GL_ALPHA, TEXSIZE, TEXSIZE, GL_ALPHA, GL_UNSIGNED_BYTE, l_tex);
344
345
                FREE_TEXTURE (l_tex)
345
346
 
346
 
                        break;
 
347
                break;
347
348
 
348
349
        case 8:
349
350
                LOAD_TEXTURE (l_tex, doughtex, doughtex_compressedsize, doughtex_size)
350
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
351
                glBindTexture (GL_TEXTURE_2D, texture_id[0]);
351
352
                glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
352
353
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
353
354
                glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
448
449
        }
449
450
}
450
451
 
 
452
void setMaterialAttribs(){
 
453
        if(dTexture == 0 || dTexture >= 5)
 
454
                glColor3f(rsRandf(1.0f), rsRandf(1.0f), rsRandf(1.0f));
 
455
        if(dTexture == 1)
 
456
                glBindTexture(GL_TEXTURE_2D, texture_id[rsRandi(2)]);
 
457
}
 
458
 
451
459
/*
452
460
 * Build the lattice display lists 
453
461
 */
456
464
        int i, d = 0;
457
465
        float thick = (float)dThick * 0.001f;
458
466
 
459
 
        if (dTexture > 0 && dTexture < 8)
460
 
                glColor3f (1.0f, 1.0f, 1.0f);
 
467
        list_base = glGenLists(NUMOBJECTS);
461
468
 
462
469
        for (i = 1; i <= NUMOBJECTS; i++) {
463
 
                glNewList (i, GL_COMPILE);
 
470
                glNewList (list_base + i, GL_COMPILE);
464
471
 
465
472
                if (dTexture >= 2)
466
 
                        glBindTexture (GL_TEXTURE_2D, 1);
 
473
                        glBindTexture (GL_TEXTURE_2D, texture_id[0]);
467
474
 
468
475
                if (d < dDensity) {
469
476
                        glPushMatrix ();
470
477
 
471
 
                        if (dTexture == 0 || dTexture >= 5)
472
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
473
 
 
474
 
                        if (dTexture == 1)
475
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
478
                        setMaterialAttribs();
476
479
 
477
480
                        glTranslatef (-0.25f, -0.25f, -0.25f);
478
481
 
479
 
                        if (myRandi (2))
 
482
                        if (rsRandi (2))
480
483
                                glRotatef (180.0f, 1, 0, 0);
481
484
 
482
485
                        makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);
489
492
                if (d < dDensity) {
490
493
                        glPushMatrix ();
491
494
 
492
 
                        if (dTexture == 0 || dTexture >= 5)
493
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
494
 
 
495
 
                        if (dTexture == 1)
496
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
495
                        setMaterialAttribs();
497
496
 
498
497
                        glTranslatef (0.25f, -0.25f, -0.25f);
499
498
 
500
 
                        if (myRandi (2))
 
499
                        if (rsRandi (2))
501
500
                                glRotatef (90.0f, 1, 0, 0);
502
501
                        else
503
502
                                glRotatef (-90.0f, 1, 0, 0);
512
511
                if (d < dDensity) {
513
512
                        glPushMatrix ();
514
513
 
515
 
                        if (dTexture == 0 || dTexture >= 5)
516
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
517
 
 
518
 
                        if (dTexture == 1)
519
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
514
                        setMaterialAttribs();
520
515
 
521
516
                        glTranslatef (0.25f, -0.25f, 0.25f);
522
517
 
523
 
                        if (myRandi (2))
 
518
                        if (rsRandi (2))
524
519
                                glRotatef (90.0f, 0, 1, 0);
525
520
                        else
526
521
                                glRotatef (-90.0f, 0, 1, 0);
535
530
                if (d < dDensity) {
536
531
                        glPushMatrix ();
537
532
 
538
 
                        if (dTexture == 0 || dTexture >= 5)
539
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
540
 
 
541
 
                        if (dTexture == 1)
542
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
533
                        setMaterialAttribs();
543
534
 
544
535
                        glTranslatef (0.25f, 0.25f, 0.25f);
545
536
 
546
 
                        if (myRandi (2))
 
537
                        if (rsRandi (2))
547
538
                                glRotatef (180.0f, 1, 0, 0);
548
539
 
549
540
                        makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);
556
547
                if (d < dDensity) {
557
548
                        glPushMatrix ();
558
549
 
559
 
                        if (dTexture == 0 || dTexture >= 5)
560
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
561
 
 
562
 
                        if (dTexture == 1)
563
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
550
                        setMaterialAttribs();
564
551
 
565
552
                        glTranslatef (-0.25f, 0.25f, 0.25f);
566
553
 
567
 
                        if (myRandi (2))
 
554
                        if (rsRandi (2))
568
555
                                glRotatef (90.0f, 1, 0, 0);
569
556
                        else
570
557
                                glRotatef (-90.0f, 1, 0, 0);
578
565
                if (d < dDensity) {
579
566
                        glPushMatrix ();
580
567
 
581
 
                        if (dTexture == 0 || dTexture >= 5)
582
 
                                glColor3f (myRandf (1.0f), myRandf (1.0f), myRandf (1.0f));
583
 
 
584
 
                        if (dTexture == 1)
585
 
                                glBindTexture (GL_TEXTURE_2D, myRandi (2) + 1);
 
568
                        setMaterialAttribs();
586
569
 
587
570
                        glTranslatef (-0.25f, 0.25f, -0.25f);
588
571
 
589
 
                        if (myRandi (2))
 
572
                        if (rsRandi (2))
590
573
                                glRotatef (90.0f, 0, 1, 0);
591
574
                        else
592
575
                                glRotatef (-90.0f, 0, 1, 0);
647
630
                        globalxyz[2]--;
648
631
        }
649
632
 
650
 
        if (!myRandi (11 - dPathrand)) {        /* Change directions */
 
633
        if (!rsRandi (11 - dPathrand)) {        /* Change directions */
651
634
                if (!positive)
652
635
                        lastBorder += 10;
653
636
 
654
 
                newBorder = transitions[lastBorder][myRandi (6)];
 
637
                newBorder = transitions[lastBorder][rsRandi (6)];
655
638
                positive = 0;
656
639
                if (newBorder < 10)
657
640
                        positive = 1;
702
685
                for (j = 0; j < 3; j++) {
703
686
                        path[1][j] += globalxyz[j];
704
687
                        if ((newBorder < 6) && (j != 1))
705
 
                                path[1][j] += myRandf (0.15f) - 0.075f;
 
688
                                path[1][j] += rsRandf (0.15f) - 0.075f;
706
689
                }
707
690
 
708
691
                if (newBorder >= 6)
709
 
                        path[1][0] += myRandf (0.1f) - 0.05f;
 
692
                        path[1][0] += rsRandf (0.1f) - 0.05f;
710
693
 
711
694
                segments = 1;
712
695
        }
721
704
        static float ATTR_ALIGN(16) oldDir[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
722
705
        static float ATTR_ALIGN(16) oldAngvel[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
723
706
        float angle, distance;
724
 
        float rotationInertia = 0.007f * (float)dSpeed;
725
 
        float maxSpin = 0.0025f * (float)dSpeed;
726
707
        float ATTR_ALIGN(16) rotMat[16];
727
708
        float ATTR_ALIGN(16) newQuat[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
728
709
        static float ATTR_ALIGN(16) quat[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
732
713
        static float where = 0.0f;      /* Position on path */
733
714
        static float rollVel = 0.0f, rollAcc = 0.0f;
734
715
        int drawDepth = dDrawdepth + 2;
735
 
        static float rollChange = 0;    /* myRandf (10.0f) + 2.0f; */
 
716
        static float rollChange = 0;    /* rsRandf (10.0f) + 2.0f; */
736
717
 
737
718
        where += (float)dSpeed * 0.05f * elapsedTime;
738
719
        if (where >= 1.0f) {
760
741
        rsVec_cross ((float *)&angvel, dir, oldDir); /* Desired axis of rotation */
761
742
 
762
743
        /* Protect against mild "overflow" */
763
 
        angle = rsVec_dot (oldDir, dir);
764
 
        if (angle >= 1.0f) {
765
 
                angle = 0.0f;
766
 
        } else {
767
 
                angle = acos (rsVec_dot (oldDir, dir)); /* Desired turn angle */
768
 
        }
769
 
 
770
 
        if (angle > maxSpin) /* Cap the spin */
771
 
                angle = maxSpin;
772
 
        if (angle < -maxSpin)
773
 
                angle = -maxSpin;
 
744
        float dot = MAX(MIN(rsVec_dot (oldDir, dir), -1.0), 1.0);
 
745
        float maxSpin = 0.25f * (float)dSpeed * elapsedTime;
 
746
        angle = MAX(MIN(acos(dot), -maxSpin), maxSpin);
774
747
 
775
748
        rsVec_scale ((float *)&angvel, angle); /* Desired angular velocity */
776
749
        rsVec_subtract (angvel, oldAngvel, (float *)&tempVec); /* Change in angular velocity */
777
750
        distance = rsVec_length (tempVec); /* Don't let angular velocity change too much */
 
751
        float rotationInertia = 0.007f * (float)dSpeed * elapsedTime;
778
752
        if (distance > rotationInertia * elapsedTime) {
779
753
                rsVec_scale ((float *)&tempVec, ((rotationInertia * elapsedTime) / distance));
780
754
                rsVec_add (oldAngvel, tempVec, (float *)&angvel);
787
761
 
788
762
        if (flymodeChange <= 0.0f) {    /* transition from one fly mode to 
789
763
                                         * the other? */
790
 
                flymode = myRandi (4);
791
 
                flymodeChange = myRandf ((float)(150 - dSpeed)) + 5.0f;
 
764
                flymode = rsRandi (4);
 
765
                flymodeChange = rsRandf ((float)(150 - dSpeed)) + 5.0f;
792
766
        }
793
767
 
794
768
        rsVec_copy (angvel, (float *)&tempVec); /* Recompute desired rotation */
803
777
        /* Roll */
804
778
        rollChange -= elapsedTime;
805
779
        if (rollChange <= 0.0f) {
806
 
                rollAcc = myRandf (0.02f * (float)dSpeed) - (0.01f * (float)dSpeed);
807
 
                rollChange = myRandf (10.0f) + 2.0f;
 
780
                rollAcc = rsRandf (0.02f * (float)dSpeed) - (0.01f * (float)dSpeed);
 
781
                rollChange = rsRandf (10.0f) + 2.0f;
808
782
        }
809
783
 
810
784
        rollVel += rollAcc * elapsedTime;
833
807
        /*
834
808
         * Apply transformations 
835
809
         */
 
810
        glMatrixMode (GL_MODELVIEW);
836
811
        glLoadMatrixf (rotMat);
837
812
        glTranslatef (-xyz[0], -xyz[1], -xyz[2]);
838
813
 
 
814
        // Just in case display lists contain no colors
 
815
        glColor3f(1.0f, 1.0f, 1.0f);
 
816
 
 
817
        // Environment mapping for crystal, chrome, brass, shiny, and ghostly
 
818
        if(dTexture == 2 || dTexture == 3 || dTexture == 4  || dTexture == 5 || dTexture == 6){
 
819
                glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
 
820
                glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
 
821
                glEnable(GL_TEXTURE_GEN_S);
 
822
                glEnable(GL_TEXTURE_GEN_T);
 
823
        }
 
824
 
839
825
        /*
840
826
         * Render everything 
841
827
         */
895
881
                }
896
882
        }
897
883
 
 
884
        glDisable(GL_TEXTURE_GEN_S);
 
885
        glDisable(GL_TEXTURE_GEN_T);
 
886
 
898
887
        glFlush ();
899
888
}
900
889
 
901
 
void hack_draw (xstuff_t * XStuff)
 
890
void hack_draw (xstuff_t * XStuff, double currentTime, float frameTime)
902
891
{
903
 
        unsigned int thisTime;
904
892
        static float times[10] = { 0.03f, 0.03f, 0.03f, 0.03f, 0.03f,
905
893
                0.03f, 0.03f, 0.03f, 0.03f, 0.03f
906
894
        };
907
895
        static int timeindex = 0;
908
 
        struct timeval now;
909
896
#ifdef BENCHMARK
910
897
        static int a = 1;
911
898
#endif
912
899
 
913
 
        /*
914
 
         * update time 
915
 
         */
916
 
        gettimeofday (&now, NULL);
917
 
        thisTime = (now.tv_sec & 65535) * 1000 + now.tv_usec / 1000;
918
 
 
919
 
        if (thisTime >= lastTime)
920
 
                times[timeindex] = (thisTime - lastTime) * 0.001f;
 
900
        if (frameTime > 0)
 
901
                times[timeindex] = frameTime;
921
902
        else
922
903
                times[timeindex] = elapsedTime;
923
904
 
924
 
        lastTime = thisTime;
925
 
 
926
905
#ifdef BENCHMARK
927
906
        elapsedTime = 0.027;
928
907
#else
969
948
void hack_init (xstuff_t * XStuff)
970
949
{
971
950
        int i, j, k;
972
 
        struct timeval now;
973
951
 
974
952
        rsCPUDetect();
975
953
 
976
 
        /*
977
 
         * update time 
978
 
         */
979
 
        gettimeofday (&now, NULL);
980
 
        lastTime = (now.tv_sec & 65535) * 1000 + now.tv_usec / 1000;
981
 
 
982
954
        hack_reshape (XStuff);
983
955
 
984
956
        if (dTexture == 9)      /* Choose random texture */
985
 
                dTexture = myRandi (9);
 
957
                dTexture = rsRandi (9);
986
958
 
987
959
        if (dTexture != 2 && dTexture != 6)     /* No z-buffering for crystal or ghostly */
988
960
                glEnable (GL_DEPTH_TEST);
1038
1010
        if (dTexture) {
1039
1011
                glEnable (GL_TEXTURE_2D);
1040
1012
                initTextures ();
1041
 
                /*
1042
 
                 * Environment mapping for crystal, chrome, brass, shiny, and
1043
 
                 * ghostly 
1044
 
                 */
1045
 
                if (dTexture == 2 || dTexture == 3 || dTexture == 4 || dTexture == 5 || dTexture == 6) {
1046
 
                        glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
1047
 
                        glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
1048
 
                        glEnable (GL_TEXTURE_GEN_S);
1049
 
                        glEnable (GL_TEXTURE_GEN_T);
1050
 
                }
1051
1013
        }
1052
1014
 
1053
1015
        /*
1057
1019
        for (i = 0; i < LATSIZE; i++) {
1058
1020
                for (j = 0; j < LATSIZE; j++) {
1059
1021
                        for (k = 0; k < LATSIZE; k++) {
1060
 
                                lattice[i][j][k] = myRandi (NUMOBJECTS) + 1;
 
1022
                                lattice[i][j][k] = list_base + rsRandi (NUMOBJECTS);
1061
1023
                        }
1062
1024
                }
1063
1025
        }
1142
1104
        path[0][4] = 0.0f;
1143
1105
        path[0][5] = 0.0f;
1144
1106
 
1145
 
        j = myRandi (12);
 
1107
        j = rsRandi (12);
1146
1108
        k = j % 6;
1147
1109
        for (i = 0; i < 6; i++)
1148
1110
                path[1][i] = bPnt[k][i];
1308
1270
        }
1309
1271
 
1310
1272
        if (!change_flag) {
1311
 
                setDefaults (myRandi (6) + 1);
 
1273
                setDefaults (rsRandi (6) + 1);
1312
1274
        }
1313
1275
}