forked from nickzman/skyrocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.cpp
executable file
·1479 lines (1373 loc) · 40.5 KB
/
particle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 1999-2005 Terence M. Welsh
*
* This file is part of Skyrocket.
*
* Skyrocket is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Skyrocket is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*#include <Skyrocket/particle.h>
#include <Skyrocket/world.h>*/
#include "particle.h"
#include "world.h"
particle::particle(SkyrocketSaverSettings *inSettings){
type = STAR;
displayList = inSettings->flarelist[0];
drag = 0.612f; // terminal velocity of 20 ft/s
t = 2.0f;
tr = t;
bright = 1.0f;
life = bright;
size = 30.0f;
makeSmoke = 0;
smokeTimeIndex = 0;
smokeTrailLength = 0.0f;
sparkTrailLength = 0.0f;
depth = 0.0f;
}
void particle::randomColor(rsVec& color){
int i, j, k;
//rsVec color;
switch(rsRandi(6)){
case 0:
i=0; j=1, k=2;
break;
case 1:
i=0; j=2, k=1;
break;
case 2:
i=1; j=0, k=2;
break;
case 3:
i=1; j=2, k=0;
break;
case 4:
i=2; j=0, k=1;
break;
case 5:
i=2; j=1, k=0;
}
color[i] = 1.0f;
color[j] = rsRandf(1.0f);
color[k] = rsRandf(0.2f);
//return(color);
}
void particle::initRocket(SkyrocketSaverSettings *inSettings){
// Thrust, initial velocity, and t (time) should send
// rockets to about 800 to 1200 feet before exploding.
type = ROCKET;
//displayList = rocketlist;
xyz[0] = rsRandf(200.0f) - 100.0f;
xyz[1] = 5.0f;
xyz[2] = rsRandf(200.0f) - 100.0f;
lastxyz[0] = xyz[0];
lastxyz[1] = 4.0f;
lastxyz[2] = xyz[2];
vel.set(0.0f, 100.0f, 0.0f);
rgb.set(rsRandf(0.7f) + 0.3f, rsRandf(0.7f) + 0.3f, 0.3f);
size = 1.0f;
drag = 0.281f; // terminal velocity of 50 ft/s
t = tr = rsRandf(2.0f) + 5.0f;
life = 1.0f;
bright = 0.0f;
thrust = 185.0f;
endthrust = rsRandf(0.1f) + 0.3f;
spin = rsRandf(40.0f) - 20.0f;
tilt = rsRandf(30.0f * float(fabs(spin)));
tiltvec.set(cosf(spin), 0.0f, sinf(spin));
if(!rsRandi(200)){ // crash the occasional rocket
spin = 0.0f;
tilt = rsRandf(100.0f) + 75.0f;
float temp = rsRandf(PIx2);
tiltvec.set(cosf(temp), 0.0f, sinf(temp));
}
makeSmoke = 1;
smokeTrailLength = 0.0f;
sparkTrailLength = 0.0f;
explosiontype = 0;
if(soundengine){
if(rsRandi(2))
soundengine->insertSoundNode(LAUNCH1SOUND, xyz, inSettings->cameraPos);
else
soundengine->insertSoundNode(LAUNCH2SOUND, xyz, inSettings->cameraPos);
}
}
void particle::initFountain(SkyrocketSaverSettings *inSettings){
type = FOUNTAIN;
displayList = inSettings->flarelist[0];
size = 30.0f;
// position can be defined here because these are always on the ground
xyz[0] = rsRandf(300.0f) - 150.0f;
xyz[1] = 5.0f;
xyz[2] = rsRandf(300.0f) - 150.0f;
randomColor(rgb);
t = tr = rsRandf(5.0f) + 10.0f;
bright = 0.0f;
life = 1.0f;
makeSmoke = 0;
if(soundengine){
if(rsRandi(2))
soundengine->insertSoundNode(LAUNCH1SOUND, xyz, inSettings->cameraPos);
else
soundengine->insertSoundNode(LAUNCH2SOUND, xyz, inSettings->cameraPos);
}
}
void particle::initSpinner(SkyrocketSaverSettings *inSettings){
type = SPINNER;
displayList = inSettings->flarelist[0];
drag = 0.612f; // terminal velocity of 20 ft/s
randomColor(rgb);
spin = rsRandf(3.0f) + 12.0f; // radial velocity
tilt = rsRandf(PIx2); // original rotation
tiltvec.set(rsRandf(2.0f) - 1.0f, rsRandf(2.0f) - 1.0f, rsRandf(2.0f) - 1.0f);
tiltvec.normalize(); // vector around which this spinner spins
t = tr = rsRandf(2.0f) + 6.0f;
bright = 0.0f;
life = 1.0f;
size = 20.0f;
makeSmoke = 1;
sparkTrailLength = 0.0f;
if(soundengine){
if(rsRandi(2))
soundengine->insertSoundNode(LAUNCH1SOUND, xyz, inSettings->cameraPos);
else
soundengine->insertSoundNode(LAUNCH2SOUND, xyz, inSettings->cameraPos);
}
}
void particle::initSmoke(rsVec pos, rsVec speed, SkyrocketSaverSettings *inSettings){
type = SMOKE;
displayList = inSettings->smokelist[rsRandi(5)];
xyz = pos;
vel = speed;
rgb[0] = rgb[1] = rgb[2] = 0.01f * float(inSettings->dAmbient);
drag = 2.0f;
// time for each smoke particle varies and must be assigned by the particle that produces the smoke
size = 0.1f;
makeSmoke = 0;
}
void particle::initStar(SkyrocketSaverSettings *inSettings){
type = STAR;
displayList = inSettings->flarelist[0];
drag = 0.612f; // terminal velocity of 20 ft/s
size = 30.0f;
t = tr = rsRandf(1.0f) + 2.0f;
life = 1.0f;
static int someSmoke = 0;
makeSmoke = inSettings->whichSmoke[someSmoke];
smokeTrailLength = 0.0f;
++someSmoke;
if(someSmoke >= WHICHSMOKES)
someSmoke = 0;
}
void particle::initStreamer(SkyrocketSaverSettings *inSettings){
type = STREAMER;
displayList = inSettings->flarelist[0];
drag = 0.612f; // terminal velocity of 20 ft/s
size = 30.0f;
t = tr = rsRandf(1.0f) + 3.0f;
life = 1.0f;
sparkTrailLength = 0.0f;
}
void particle::initMeteor(SkyrocketSaverSettings *inSettings){
type = METEOR;
displayList = inSettings->flarelist[0];
drag = 0.612f; // terminal velocity of 20 ft/s
t = tr = rsRandf(1.0f) + 3.0f;
life = 1.0f;
size = 20.0f;
sparkTrailLength = 0.0f;
}
void particle::initStarPopper(SkyrocketSaverSettings *inSettings){
type = POPPER;
displayList = inSettings->flarelist[0];
drag = 0.4f;
t = tr = rsRandf(1.5f) + 3.0f;
life = 1.0f;
makeSmoke = 1;
explosiontype = STAR;
size = 0.0f;
smokeTrailLength = 0.0f;
}
void particle::initStreamerPopper(SkyrocketSaverSettings *inSettings){
type = POPPER;
displayList = inSettings->flarelist[0];
size = 0.0f;
drag = 0.4f;
t = tr = rsRandf(1.5f) + 3.0f;
life = 1.0f;
makeSmoke = 1;
explosiontype = STREAMER;
smokeTrailLength = 0.0f;
}
void particle::initMeteorPopper(SkyrocketSaverSettings *inSettings){
type = POPPER;
displayList = inSettings->flarelist[0];
size = 0.0f;
drag = 0.4f;
t = tr = rsRandf(1.5f) + 3.0f;
life = 1.0f;
makeSmoke = 1;
explosiontype = METEOR;
smokeTrailLength = 0.0f;
}
void particle::initLittlePopper(SkyrocketSaverSettings *inSettings){
type = POPPER;
displayList = inSettings->flarelist[0];
drag = 0.4f;
t = tr = 4.0f * (0.5f - sinf(rsRandf(PI))) + 4.5f;
life = 1.0f;
size = rsRandf(3.0f) + 7.0f;
makeSmoke = 0;
explosiontype = POPPER;
}
void particle::initBee(SkyrocketSaverSettings *inSettings){
type = BEE;
displayList = inSettings->flarelist[0];
size = 10.0f;
drag = 0.5f;
t = tr = rsRandf(2.5f) + 2.5f;
life = 1.0f;
makeSmoke = 0;
sparkTrailLength = 0.0f;
// these variables will be misused to describe bee acceleration vector
thrust = rsRandf(PIx2) + PI;
endthrust = rsRandf(PIx2) + PI;
spin = rsRandf(PIx2) + PI;
tiltvec.set(rsRandf(PIx2), rsRandf(PIx2), rsRandf(PIx2));
}
void particle::initSucker(SkyrocketSaverSettings *inSettings){
int i;
particle* newp;
rsVec color;
float temp1, temp2, ch, sh, cp, sp;
type = SUCKER;
drag = 0.612f; // terminal velocity of 20 ft/s
displayList = inSettings->flarelist[2];
rgb.set(1.0f, 1.0f, 1.0f);
size = 300.0f;
t = tr = 4.0f;
life = 1.0f;
makeSmoke = 0;
// make explosion
newp = addParticle(inSettings);
newp->type = EXPLOSION;
newp->xyz = xyz;
newp->vel = vel;
newp->rgb.set(1.0f, 1.0f, 1.0f);
newp->size = 200.0f;
newp->t = newp->tr = 4.0f;
// Make double ring to go along with sucker
randomColor(color);
temp1 = rsRandf(PI); // heading
temp2 = rsRandf(PI); // pitch
ch = cosf(temp1);
sh = sinf(temp1);
cp = cosf(temp2);
sp = sinf(temp2);
for(i=0; i<90; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
// pitch
newp->vel[1] = sp * newp->vel[2];
newp->vel[2] = cp * newp->vel[2];
// heading
temp1 = newp->vel[0];
newp->vel[0] = ch * temp1 + sh * newp->vel[1];
newp->vel[1] = -sh * temp1 + ch * newp->vel[1];
// multiply velocity
newp->vel[0] *= 350.0f + rsRandf(30.0f);
newp->vel[1] *= 350.0f + rsRandf(30.0f);
newp->vel[2] *= 350.0f + rsRandf(30.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
randomColor(color);
temp1 = rsRandf(PI); // heading
temp2 = rsRandf(PI); // pitch
ch = cosf(temp1);
sh = sinf(temp1);
cp = cosf(temp2);
sp = sinf(temp2);
for(i=0; i<90; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
// pitch
newp->vel[1] = sp * newp->vel[2];
newp->vel[2] = cp * newp->vel[2];
// heading
temp1 = newp->vel[0];
newp->vel[0] = ch * temp1 + sh * newp->vel[1];
newp->vel[1] = -sh * temp1 + ch * newp->vel[1];
// multiply velocity
newp->vel[0] *= 600.0f + rsRandf(50.0f);
newp->vel[1] *= 600.0f + rsRandf(50.0f);
newp->vel[2] *= 600.0f + rsRandf(50.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
if(soundengine)
soundengine->insertSoundNode(SUCKSOUND, xyz, inSettings->cameraPos);
}
void particle::initShockwave(SkyrocketSaverSettings *inSettings){
int i;
particle* newp;
rsVec color;
type = SHOCKWAVE;
drag = 0.612f; // terminal velocity of 20 ft/s
rgb.set(1.0f, 1.0f, 1.0f);
size = 0.01f;
t = tr = 8.0f;
life = 1.0f;
bright = life;
// make explosion
newp = addParticle(inSettings);
newp->type = EXPLOSION;
newp->xyz = xyz;
newp->vel = vel;
newp->rgb.set(1.0f, 1.0f, 1.0f);
newp->size = 300.0f;
newp->t = newp->tr = 2.0f;
life = 1.0f;
makeSmoke = 0;
// Little sphere without smoke
randomColor(color);
for(i=0; i<75; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel *= (rsRandf(10.0f) + 100.0f);
newp->vel += vel;
newp->rgb = color;
newp->size = 100.0f;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
// Disk of stars without smoke
randomColor(color);
for(i=0; i<150; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->drag = 0.2f;
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(0.03f) - 0.005f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
// multiply velocity
newp->vel *= (rsRandf(30.0f) + 500.0f);
newp->vel += vel;
newp->rgb = color;
newp->size = 50.0f;
newp->t = newp->tr = rsRandf(2.0f) + 3.0f;
newp->makeSmoke = 0;
}
if(soundengine)
soundengine->insertSoundNode(NUKESOUND, xyz, inSettings->cameraPos);
}
void particle::initStretcher(SkyrocketSaverSettings *inSettings){
int i;
particle* newp;
rsVec color;
type = STRETCHER;
drag = 0.612f; // terminal velocity of 20 ft/s
displayList = inSettings->flarelist[3];
rgb.set(1.0f, 1.0f, 1.0f);
size = 0.0f;
t = tr = 4.0f;
life = 1.0f;
makeSmoke = 0;
// explosion
newp = addParticle(inSettings);
newp->type = EXPLOSION;
newp->displayList = inSettings->flarelist[0];
newp->xyz = xyz;
newp->vel = vel;
newp->rgb.set(1.0f, 0.8f, 0.6f);
newp->size = 400.0f;
newp->t = newp->tr = 4.0f;
life = 1.0f;
newp->makeSmoke = 0;
// Make triple ring to go along with stretcher
randomColor(color);
for(i=0; i<80; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel[0] *= 400.0f + rsRandf(30.0f);
newp->vel[1] += rsRandf(70.0f) - 35.0f;
newp->vel[2] *= 400.0f + rsRandf(30.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
randomColor(color);
for(i=0; i<80; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel[0] *= 550.0f + rsRandf(40.0f);
newp->vel[1] += rsRandf(70.0f) - 35.0f;
newp->vel[2] *= 550.0f + rsRandf(40.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
randomColor(color);
for(i=0; i<80; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel[0] *= 700.0f + rsRandf(50.0f);
newp->vel[1] += rsRandf(70.0f) - 35.0f;
newp->vel[2] *= 700.0f + rsRandf(50.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
if(soundengine)
soundengine->insertSoundNode(SUCKSOUND, xyz, inSettings->cameraPos);
}
void particle::initBigmama(SkyrocketSaverSettings *inSettings){
int i;
particle* newp;
rsVec color;
float temp;
type = BIGMAMA;
drag = 0.612f; // terminal velocity of 20 ft/s
displayList = inSettings->flarelist[2];
rgb.set(0.6f, 0.6f, 1.0f);
size = 0.0f;
t = tr = 5.0f;
life = 1.0f;
bright = life;
makeSmoke = 0;
// explosion
newp = addParticle(inSettings);
newp->type = EXPLOSION;
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->rgb.set(0.8f, 0.8f, 1.0f);
newp->size = 200.0f;
newp->t = newp->tr = 2.5f;
life = 1.0f;
newp->makeSmoke = 0;
// vertical stars
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] += 15.0f;
newp->rgb.set(1.0f, 1.0f, 0.9f);
newp->size = 400.0f;
newp->t = newp->tr = 3.0f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] -= 15.0f;
newp->rgb.set(1.0f, 1.0f, 0.9f);
newp->size = 400.0f;
newp->t = newp->tr = 3.0f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] += 45.0f;
newp->rgb.set(1.0f, 1.0f, 0.6f);
newp->size = 400.0f;
newp->t = newp->tr = 3.5f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] -= 45.0f;
newp->rgb.set(1.0f, 1.0f, 0.6f);
newp->size = 400.0f;
newp->t = newp->tr = 3.5f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] += 75.0f;
newp->rgb.set(1.0f, 0.5f, 0.3f);
newp->size = 400.0f;
newp->t = newp->tr = 4.0f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] -= 75.0f;
newp->rgb.set(1.0f, 0.5f, 0.3f);
newp->size = 400.0f;
newp->t = newp->tr = 4.0f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] += 105.0f;
newp->rgb.set(1.0f, 0.0f, 0.0f);
newp->size = 400.0f;
newp->t = newp->tr = 4.5f;
newp->makeSmoke = 0;
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel = vel;
newp->drag = 0.0f;
newp->vel[1] -= 105.0f;
newp->rgb.set(1.0f, 0.0f, 0.0f);
newp->size = 400.0f;
newp->t = newp->tr = 4.5f;
newp->makeSmoke = 0;
// Sphere without smoke
randomColor(color);
for(i=0; i<75; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
temp = 600.0f + rsRandf(100.0f);
newp->vel[0] *= temp;
newp->vel[1] *= temp;
newp->vel[2] *= temp;
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->t = newp->tr = rsRandf(2.0f) + 2.0f;
newp->makeSmoke = 0;
}
// disk of big streamers
randomColor(color);
for(i=0; i<50; i++){
newp = addParticle(inSettings);
newp->initStreamer(inSettings);
newp->drag = 0.3f;
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel[0] *= 1000.0f + rsRandf(100.0f);
newp->vel[1] += rsRandf(100.0f) - 50.0f;
newp->vel[2] *= 1000.0f + rsRandf(100.0f);
newp->vel[0] += vel[0];
newp->vel[1] += vel[1];
newp->vel[2] += vel[2];
newp->rgb = color;
newp->size = 100.0f;
newp->t = newp->tr = rsRandf(6.0f) + 3.0f;
newp->makeSmoke = 0;
}
if(soundengine)
soundengine->insertSoundNode(NUKESOUND, xyz, inSettings->cameraPos);
}
void particle::initExplosion(SkyrocketSaverSettings *inSettings){
type = EXPLOSION;
displayList = inSettings->flarelist[0];
drag = 0.612f;
t = tr = 0.5f;
bright = 1.0f;
life = 1.0f;
size = 100.0f;
makeSmoke = 0;
// Don't do massive explosions too close to the ground
if((explosiontype == 19 || explosiontype == 20) && (xyz[1] < 600.0f))
explosiontype = 0;
rsVec rgb2;
switch(explosiontype){
case 0:
randomColor(rgb);
if(!rsRandi(10)) // big sphere
popSphere(225, 1000.0f, rgb, inSettings);
else // regular sphere
popSphere(175, rsRandf(100.0f) + 400.0f, rgb, inSettings);
break;
case 1:
randomColor(rgb);
if(!rsRandi(10)) // big split sphere
popSplitSphere(225, 1000.0f, rgb, inSettings);
else // regular split sphere
popSplitSphere(175, rsRandf(100.0f) + 400.0f, rgb, inSettings);
break;
case 2:
rgb.set(1.0f, 1.0f, 1.0f);
if(!rsRandi(10)) // big multicolored sphere
popMultiColorSphere(225, 1000.0f, inSettings);
else // regular multicolored sphere
popMultiColorSphere(175, rsRandf(100.0f) + 400.0f, inSettings);
break;
case 3: // ring
randomColor(rgb);
popRing(80, rsRandf(100.0f) + 400.0f, rgb, inSettings);
break;
case 4: // double sphere
randomColor(rgb);
randomColor(rgb2);
popSphere(90, rsRandf(50.0f) + 200.0f, rgb2, inSettings);
popSphere(150, rsRandf(100.0f) + 500.0f, rgb, inSettings);
break;
case 5: // sphere and ring
randomColor(rgb);
randomColor(rgb2);
popRing(80, rsRandf(100.0f) + 500.0f, rgb2, inSettings);
popSphere(150, rsRandf(50.0f) + 200.0f, rgb, inSettings);
break;
case 6: // Sphere of streamers
randomColor(rgb);
popStreamers(40, rsRandf(100.0f) + 400.0f, rgb, inSettings);
break;
case 7: // Sphere of meteors
randomColor(rgb);
popMeteors(40, rsRandf(100.0f) + 400.0f, rgb, inSettings);
break;
case 8: // Small sphere of stars and large sphere of streamers
randomColor(rgb);
randomColor(rgb2);
popStreamers(30, rsRandf(100.0f) + 500.0f, rgb, inSettings);
popSphere(90, rsRandf(50.0f) + 200.0f, rgb2, inSettings);
break;
case 9: // Small sphere of stars and large sphere of meteors
randomColor(rgb);
randomColor(rgb2);
popMeteors(30, rsRandf(100.0f) + 500.0f, rgb, inSettings);
popSphere(90, rsRandf(50.0f) + 200.0f, rgb2, inSettings);
break;
case 10: // Sphere of streamers inside sphere of stars
randomColor(rgb);
randomColor(rgb2);
popStreamers(30, rsRandf(100.0f) + 450.0f, rgb, inSettings);
popSphere(150, rsRandf(50.0f) + 500.0f, rgb2, inSettings);
break;
case 11: // Sphere of meteors inside sphere of stars
randomColor(rgb);
randomColor(rgb2);
popMeteors(30, rsRandf(100.0f) + 450.0f, rgb, inSettings);
popSphere(150, rsRandf(50.0f) + 500.0f, rgb2, inSettings);
break;
case 12: // a few bombs that fall and explode into stars
randomColor(rgb);
popStarPoppers(8, rsRandf(100.0f) + 300.0f, rgb, inSettings);
break;
case 13: // a few bombs that fall and explode into streamers
randomColor(rgb);
popStreamerPoppers(8, rsRandf(100.0f) + 300.0f, rgb, inSettings);
break;
case 14: // a few bombs that fall and explode into meteors
randomColor(rgb);
popMeteorPoppers(8, rsRandf(100.0f) + 300.0f, rgb, inSettings);
break;
case 15: // lots of little falling firecrackers
popLittlePoppers(250, rsRandf(50.0f) + 150.0f, inSettings);
break;
case 16:
randomColor(rgb);
popBees(50, 10.0f, rgb, inSettings);
break;
case 17: // Boom! (loud noise and flash of light)
rgb.set(1.0f, 1.0f, 1.0f);
size = 150.0f;
break;
// 18 is a spinner, which doesn't require explosion
case 19:
rgb.set(1.0f, 1.0f, 1.0f);
initSucker(inSettings);
break;
case 20:
rgb.set(1.0f, 1.0f, 1.0f);
initStretcher(inSettings);
break;
case 100: // these three are little explosions for poppers
popSphere(30, 100.0f, rgb, inSettings);
break;
case 101:
popStreamers(10, 100.0f, rgb, inSettings);
break;
case 102:
popMeteors(10, 100.0f, rgb, inSettings);
}
if(soundengine){
if(explosiontype == 17) // extra resounding boom
soundengine->insertSoundNode(BOOM4SOUND, xyz, inSettings->cameraPos);
// make bees and big booms whistle sometimes
if(explosiontype == 16 || explosiontype == 17)
if(rsRandi(2))
soundengine->insertSoundNode(WHISTLESOUND, xyz, inSettings->cameraPos);
// regular booms
if(explosiontype <= 16 || explosiontype >= 100)
soundengine->insertSoundNode(BOOM1SOUND + rsRandi(3), xyz, inSettings->cameraPos);
// sucker and stretcher take care of their own sounds
}
}
void particle::popSphere(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel *= v0 + rsRandf(50.0f);
newp->vel += vel;
newp->rgb = color;
}
if(!rsRandi(100))
newp->t = newp->tr = rsRandf(20.0f) + 5.0f;
}
void particle::popSplitSphere(int numParts, float v0, rsVec color1, SkyrocketSaverSettings *inSettings){
particle* newp;
rsVec color2;
rsVec planeNormal;
randomColor(color2);
planeNormal[0] = rsRandf(1.0f) - 0.5f;
planeNormal[1] = rsRandf(1.0f) - 0.5f;
planeNormal[2] = rsRandf(1.0f) - 0.5f;
planeNormal.normalize();
for(int i=0; i<numParts; i++){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
if(planeNormal.dot(newp->vel) > 0.0f)
newp->rgb = color1;
else
newp->rgb = color2;
newp->vel *= v0 + rsRandf(50.0f);
newp->vel += vel;
}
if(!rsRandi(100))
newp->t = newp->tr = rsRandf(20.0f) + 5.0f;
}
void particle::popMultiColorSphere(int numParts, float v0, SkyrocketSaverSettings *inSettings){
particle* newp;
rsVec color[3];
randomColor(color[0]);
randomColor(color[1]);
randomColor(color[2]);
int j(0);
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel *= v0 + rsRandf(30.0f);
newp->vel += vel;
newp->rgb = color[j];
++j;
if(j >= 3)
j = 0;
}
if(!rsRandi(100))
newp->t = newp->tr = rsRandf(20.0f) + 5.0f;
}
void particle::popRing(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
float temph = rsRandf(PI); // heading
float tempp = rsRandf(PI); // pitch
const float ch(cosf(temph));
const float sh(sinf(temph));
const float cp(cosf(tempp));
const float sp(sinf(tempp));
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStar(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = 0.0f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
// pitch
newp->vel[1] = sp * newp->vel[2];
newp->vel[2] = cp * newp->vel[2];
// heading
const float temp(newp->vel[0]);
newp->vel[0] = ch * temp + sh * newp->vel[1];
newp->vel[1] = -sh * temp + ch * newp->vel[1];
// multiply velocity
newp->vel[0] *= v0 + rsRandf(50.0f);
newp->vel[1] *= v0 + rsRandf(50.0f);
newp->vel[2] *= v0 + rsRandf(50.0f);
newp->vel += vel;
newp->rgb = color;
}
if(!rsRandi(100))
newp->t = newp->tr = rsRandf(20.0f) + 5.0f;
}
void particle::popStreamers(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStreamer(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel *= v0 + rsRandf(50.0f);
newp->vel += vel;
newp->rgb = color;
}
}
void particle::popMeteors(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initMeteor(inSettings);
newp->xyz = xyz;
newp->vel[0] = rsRandf(1.0f) - 0.5f;
newp->vel[1] = rsRandf(1.0f) - 0.5f;
newp->vel[2] = rsRandf(1.0f) - 0.5f;
newp->vel.normalize();
newp->vel *= v0 + rsRandf(50.0f);
newp->vel += vel;
newp->rgb = color;
}
}
void particle::popStarPoppers(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
const float v0x2(v0 * 2.0f);
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStarPopper(inSettings);
newp->xyz = xyz;
newp->vel[0] = vel[0] + rsRandf(v0x2) - v0;
newp->vel[1] = vel[1] + rsRandf(v0x2) - v0;
newp->vel[2] = vel[2] + rsRandf(v0x2) - v0;
newp->rgb = color;
}
}
void particle::popStreamerPoppers(int numParts, float v0, rsVec color, SkyrocketSaverSettings *inSettings){
particle* newp;
const float v0x2(v0 * 2.0f);
for(int i=0; i<numParts; ++i){
newp = addParticle(inSettings);
newp->initStreamerPopper(inSettings);
newp->xyz = xyz;
newp->vel[0] = vel[0] + rsRandf(v0x2) - v0;
newp->vel[1] = vel[1] + rsRandf(v0x2) - v0;
newp->vel[2] = vel[2] + rsRandf(v0x2) - v0;