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

« back to all changes in this revision

Viewing changes to reallyslick/cpp_src/flocks.cpp

  • 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:
20
20
 
21
21
#include <math.h>
22
22
#include <stdio.h>
23
 
#include <time.h>
24
23
#include <GL/gl.h>
25
24
#include <GL/glu.h>
26
 
#include <sys/time.h>
27
25
 
28
26
#include "driver.h"
29
27
#include "rgbhsl.h"
131
129
 
132
130
void bug::initLeader ()
133
131
{
134
 
        int i = 0;
135
 
 
136
132
        type = 0;
137
 
        h = myRandf (1.0);
 
133
        h = rsRandf (1.0);
138
134
        s = 1.0f;
139
135
        l = 1.0f;
140
 
        x = myRandf (float (wide * 2)) - float (wide);
141
 
        y = myRandf (float (high * 2)) - float (high);
142
 
        z = myRandf (float (wide * 2)) + float (wide * 2);
 
136
        x = rsRandf (float (wide * 2)) - float (wide);
 
137
        y = rsRandf (float (high * 2)) - float (high);
 
138
        z = rsRandf (float (wide * 2)) + float (wide * 2);
143
139
 
144
140
        if (dTrail) {
145
141
                bug::initTrail ();
146
142
 
147
 
                xdrift = (myRandf (2) - 1);
148
 
                ydrift = (myRandf (2) - 1);
149
 
                zdrift = (myRandf (2) - 1);
 
143
                xdrift = (rsRandf (2) - 1);
 
144
                ydrift = (rsRandf (2) - 1);
 
145
                zdrift = (rsRandf (2) - 1);
150
146
        }
151
147
 
152
148
        right = up = forward = 1;
154
150
        maxSpeed = 8.0f * float (dSpeed);
155
151
        accel = 13.0f * float (dSpeed);
156
152
 
157
 
        craziness = myRandf (4.0f) + 0.05f;
 
153
        craziness = rsRandf (4.0f) + 0.05f;
158
154
        nextChange = 1.0f;
159
155
 
160
156
        leader = -1;
162
158
 
163
159
void bug::initFollower ()
164
160
{
165
 
        int i = 0;
166
 
 
167
161
        type = 1;
168
 
        h = myRandf (1.0);
 
162
        h = rsRandf (1.0);
169
163
        s = 1.0f;
170
164
        l = 1.0f;
171
 
        x = myRandf (float (wide * 2)) - float (wide);
172
 
        y = myRandf (float (high * 2)) - float (high);
173
 
        z = myRandf (float (wide * 5)) + float (wide * 2);
 
165
        x = rsRandf (float (wide * 2)) - float (wide);
 
166
        y = rsRandf (float (high * 2)) - float (high);
 
167
        z = rsRandf (float (wide * 5)) + float (wide * 2);
174
168
 
175
169
        if (dTrail) {
176
170
                bug::initTrail ();
178
172
 
179
173
        right = up = forward = 0;
180
174
        xSpeed = ySpeed = zSpeed = 0.0f;
181
 
        maxSpeed = (myRandf (6.0f) + 4.0f) * float (dSpeed);
182
 
        accel = (myRandf (4.0f) + 9.0f) * float (dSpeed);
 
175
        maxSpeed = (rsRandf (6.0f) + 4.0f) * float (dSpeed);
 
176
        accel = (rsRandf (4.0f) + 9.0f) * float (dSpeed);
183
177
 
184
178
        leader = 0;
185
179
}
193
187
                nextChange -= elapsedTime;
194
188
 
195
189
                if (nextChange <= 0.0f) {
196
 
                        if (myRandi (2))
 
190
                        if (rsRandi (2))
197
191
                                right++;
198
 
                        if (myRandi (2))
 
192
                        if (rsRandi (2))
199
193
                                up++;
200
 
                        if (myRandi (2))
 
194
                        if (rsRandi (2))
201
195
                                forward++;
202
196
 
203
197
                        if (right >= 2)
207
201
                        if (forward >= 2)
208
202
                                forward = 0;
209
203
 
210
 
                        nextChange = myRandf (craziness);
 
204
                        nextChange = rsRandf (craziness);
211
205
                }
212
206
 
213
207
                if (right)
245
239
                                h = 0.0f;
246
240
                }
247
241
        } else {                // follower
248
 
                if (!myRandi (10)) {
 
242
                if (!rsRandi (10)) {
249
243
                        float oldDistance = 10000000.0f, newDistance;
250
244
 
251
245
                        for (i = 0; i < dLeaders; i++) {
422
416
        }
423
417
}
424
418
 
425
 
void hack_draw (xstuff_t * XStuff)
 
419
void hack_draw (xstuff_t * XStuff, double currentTime, float frameTime)
426
420
{
427
421
        int i;
428
 
        static int thisTime, lastTime = -1;
429
 
        struct timeval now;
430
 
 
431
 
        /*
432
 
         * update time 
433
 
         */
434
 
        gettimeofday (&now, NULL);
435
 
        thisTime = (now.tv_sec & 65535) * 1000 + now.tv_usec / 1000;
436
 
 
437
 
        if (lastTime == -1)
438
 
                lastTime = thisTime;
439
 
 
440
 
        if (thisTime >= lastTime)
441
 
                elapsedTime = (thisTime - lastTime) * 0.001f;
442
 
        lastTime = thisTime;
 
422
 
 
423
        elapsedTime = frameTime;
443
424
 
444
425
        if (dBlur) {            // partially
445
426
                glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
536
517
 
537
518
                gluDeleteQuadric (qobj);
538
519
                glEndList ();
 
520
        } else {
 
521
                if (dStretch == 0){
 
522
                        // make GL_POINTS round instead of square
 
523
                        glEnable(GL_POINT_SMOOTH);
 
524
                        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
 
525
                }
539
526
        }
540
527
 
541
528
        glMatrixMode (GL_PROJECTION);
542
529
        glLoadIdentity ();
543
 
        gluPerspective (80.0, aspectRatio, 50, 2000);
 
530
        gluPerspective (50.0, aspectRatio, 0.1, 2000);
 
531
 
 
532
        glMatrixMode (GL_MODELVIEW);
 
533
        glLoadIdentity ();
544
534
        glTranslatef (0.0, 0.0, -float (wide * 2));
545
535
 
546
 
        glMatrixMode (GL_MODELVIEW);
547
 
        glLoadIdentity ();
548
 
 
549
536
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
550
537
}
551
538
 
776
763
        }
777
764
 
778
765
        if (!change_flag) {
779
 
                setDefaults (myRandi (4) + 1);
 
766
                setDefaults (rsRandi (4) + 1);
780
767
        }
781
768
}