-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
7525 lines (5676 loc) · 240 KB
/
main.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
#define DEF_TIMEJUMP TIME_SCENE08 // Timejump should be TIME_SCENExx when ONLY_PLAY_SCENE has xx value
#define ONLY_PLAY_SCENE 8
#define PLAY_LOADSCREEN
#define PLAY_SCENE01 // Intro with waterscene and brainroom splashscroller
#define PLAY_SCENE02 // Energy tunnel
#define PLAY_SCENE03 // Textworld
#define PLAY_SCENE04 // Metaball
#define PLAY_SCENE05 // Mean tunnel
#define PLAY_SCENE06 // Nature splashscroller
#define PLAY_SCENE07 // Credit screen
#define PLAY_SCENE08 // 3D scene
#define PLAY_SCENE09 // 3D scene with greets, same style
#define PLAY_SCENE10 // Final splashscreen, with fadeout to end-text
//#define PLAYMUSIC
#define FULLSCREEN
//#define INFOTEXT
#define SLOWMO_FACTOR 1.0f
#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 768
#define MOUSECONTROL FALSE // Flag that specifies whether mouse controls camera or not
#define GLOBAL_FILLMODE D3DFILL_SOLID
#define TEXT_COLOR D3DCOLOR_ARGB(255,127,127,127)
#define GAMMA_RED 255.0f
#define GAMMA_BLUE 255.0f
#define GAMMA_GREEN 255.0f
//-----------------------------------------------------------------------------
// Title: Forsaken v0.926 Hi-Quality PC-Demo
// Author: Zigrath / Heed
// Mail: [email protected]
//
// Desc: My first demo ever, to be contributed at The Gathering 2003.
// Kaktusen provides music, gfx and ideas.
//
// Linked libraries:
// * d3dx8.lib d3dxof.lib d3d8.lib dxguid.lib winmm.lib fmodvc.lib comctl32.lib
//
// Bugs:
// * Heap block modified past requested size of 46020. Scene04/05? Might still exist.
// * Set3DPlaneVBRect() is NOT foolproof with the different vertex formats. Only one flag after XYZ and NORMAL can work 100%.
//
//
// Compatibility checklist:
// * timebased random generating (i.e. feed the chicken vibration)
// * memory allocations (textures above 1024x1024?)
// * test product on a slow computer and a really fast one
//
// Todos:
// * ShowBlurTexture() or alternative blurring
// * sort bloodparticles in scene05
// * metaballs: bruk en sum av vektorenE fra ballenes sentrum ganger verdien fra metafunksjonene dems
// * Fog on water in scene01?
// * Scene04. Metaball and marching cubes. Improve melting.
// * DX SDK has some nice textures. Might find a replacement for flies.
// * Point sprites?
// * World-transformation correction for fireflies, we want sprites to look 2D
//
// Effect ideas:
// * Scroll-in transparency and blur effect on introtext
// * Animated inverse-color rectangle from 4 cross-screen lines
// * Rotate the three manga-heads transparently on top of eachother
//
//
//
// Memos to self:
// 28.11.02: Spank me. The intro is finally getting somewhere..
// 06.12.02: Bugs aren't all that bad, it is fixing them that really sucks.
// 20.02.03: Intro is nearly done, and I'm sort of pleased with it - but not overjoyous, mark you.
// 20.02.03: So much to do, so little time. So hungry.
// 09.03.03: Intro has been improved a lot, the flies in particular. I'm currently working on the
// tunnel effect, and I'm quite pleased with it. I even got most of the plasma effect
// in place already.
// 10.03.03: Skipping sleep is good for demos, but that's just about it.
// I and kaktus have produced a number of concrete ideas that's going to be part of the demo.
// 11.03.03: The soundtrack is finished, thanks to a great job by Kaktus, and it is awesome!
// He has also set up a pretty concrete plan for where and how to apply the different
// scenes and effects we have discussed. This plan is based on the music, and should
// give a very thorough experience if we succeed to follow it.
// Splashscreen 1 is nearly done, and I found a better looking way of creating the
// plasma effect for the tunnel. This demo is gonna be great! :D
// 28.03.03: Lots have been done. The water effect in the intro has been improved a heck of a lot,
// and it's now looking sweet!
// I have also finished most of the textscene in musicpause1, and next up will be the
// metaball. I'm really excited about that one.
// The rest of the scenes are more or less finished on plan level, and they should
// be far faster to create than the scenes so far.
// The deadline is two and a half week from now, and we have finished about 2 minutes out of 5.
// But I think we'll have enough time to come up with a pretty decent demo.
// 30.03.03: I finished off the blue tunnel scene. It's not perfect, but it'll do. We're short on time already,
// and I have that pesky metaball to figure out shortly. The big scenes that remain are.. still many.
// 12.03.03: Time is running out and I'm so busy I can't even take a piss. And when I occasionally do,
// it smells like honney corn.
// A lot has happened since last post however. I have come far with the metaballs (they are still too slow and
// don't look too good because of resolution on grid). The mean tunnel at scene5 is nearly done. The particles
// are basically finished, it's just some camera stuff to set up and flash-effects. Shouldn't take long.
// The nature splashscroller and credits are also basically in place, just missing some textures and finish.
//
// Finally, I have made a temporary 3d-object for use in scene8 and threw in some rotation. I'm thinking of
// adding more objects and some particles, and that should pretty much do it.
// I do have accomplished a lot the past 12 days, and I'm finally seeing an end to this demo. About 30 seconds
// remain that I haven't put any work to yet, and they should only take a day or two to implement.
// Who knows, we might actually finish this demo in time!
// 14.03.03: Two days to dust off. These holidays have been very useful, and I have been able
// to put down quite a share of work. The major accomplishment is a pretty much done
// scene8 and I am thinking of using much of it in scene9 as well. And that narrows
// it down to a 15 second lastscene that I intend to put a lot of work into, as to
// give a good last impression of the demo.
// The camera movement in scene2 and 5 has been improved a lot, scene5 in particular.
// The particles in scene5 are also moving a bit random now to look more alive,
// and it works pretty decent. I'm still thinking of experimenting with the textures a
// bit though, but there's plenty of time for such at the party.
// I also added introtext for the poem in the soundtrack. The textures are rather
// temporary but most of the work there is done. And I'm thinking of adding some blur and
// "scroll-in transparency" effects on the textlines.
// 19.03.03: It is Saturday morning, and less than 4 hours to deadline. I think we have managed to scrap together
// a rather decent demo, at least for a first attempt. We had to cut the soundtrack about 20 seconds at
// the end, since we couldn't get enough time to fill it all. Kaktus did a good job, and the soundtrack
// now fits the demo pretty well (and vice versa).
// We have put a lot of work in refining the textures and adding quite a deal of fill-effects.
// Of course I wish I'd have more time, but then again I'll be happy to wrap up this product.
// I've spent an enormous time and effort making it.. and as long as it shows up ok on the bigscreen
// I will be quite satisfied with this demo.
// My fingers are crossed.
// There is a major bug in the demo however. It seems ATI cards mess up the fade-sequences, so it is
// currently not playable on those. I'll try and fix it before deadline.
// Except for that, all scenes are in place more or less. The metaballs look like crap, but I just don't
// have time to fix it.
// I'm quite excited how this compo will turn out.
//
//
// Disclaimer: Be aware of the bugs, they bite.
//-----------------------------------------------------------------------------
// Global timekeys
#define TIME_SCENE00 0.0f // Start of demo, to make a pause between start and scene01
#define TIME_SCENE01 5.0f // Water and flies
#define TIME_SPLASH01 65.0f // Logo and brain-room splashscroller. Part of scene01, so it uses that localtime
#define TIME_SCENE02 (TIME_SCENE01 + 85.3f) // Energy tunnel
#define TIME_SCENE03 (TIME_SCENE01 + 106.6f) // Textworld
#define TIME_SCENE04 (TIME_SCENE01 + 127.95f) // Metaball
#define TIME_SCENE05 (TIME_SCENE01 + 149.2f) // Mean tunnel
#define TIME_SCENE06 (TIME_SCENE01 + 192.0f) // Nature splashscroller
#define TIME_SCENE07 (TIME_SCENE01 + 213.5f) // Credit screen
#define TIME_SCENE08 (TIME_SCENE01 + 234.7f) // 3D scene
#define TIME_SCENE09 (TIME_SCENE01 + 255.8f) // 3D scene with greets, same style
#define TIME_SCENE10 (TIME_SCENE01 + 277.4f) // Final splashscreen, with fadeout to end-text
#define TIME_SCENE11 (TIME_SCENE01 + 292.0f)
// Scene01
#define WATER_FVF D3DFVF_NLVERTEX
#define WATER_VERTEX NLVERTEX
#define WATER_VX 50 // Number of vertices
#define WATER_VY 50
#define WATER_DELAY 10.0f
#define WATER_VERTS (WATER_VX*WATER_VY)
#define WATER_INDICES ((WATER_VX-1)*(WATER_VY-1)*6) // Number of quads times 6
#define WATER_FACES ((WATER_VX-1)*(WATER_VY-1)*2) // Twice the number of quads
#define MAX_FIREFLIES 100
#define MAX_FIREFLY_WAYPOINTS 100
#define FIREFLY_GLOWLAYERS 4
#define FIREFLY_MAX_GLOWDIST 0.5f
#define FIREFLY_DEPTH_VISIBLE 70.0f // At which depth fireflies go visible (distance from camera)
#define FIREFLY_DEPTH_INVISIBLE 40.0f // At which depth fireflies go invisible (distance from camera)
// Scene02
#define TUNNEL_LENGTH 150.0f
#define TUNNEL_RADIUS 1.0f
#define TUNNEL_WILD_RADIUS 10.0f
#define TUNNEL_SPEED 1.0f
#define TUNNEL_VERTEX NLTVERTEX
#define TUNNEL_FVF D3DFVF_NLTVERTEX
#define TUNNEL_WAYPOINTS 4 // 4 waypoints for the visible part of the tunnel, and 2 endpoints for cat-mull rom calculations
#define TUNNEL_SEGS_PER_WAYPOINT 10
#define TUNNEL_SEGMENT_VERTS 36
#define TUNNEL_SEGMENTS (TUNNEL_SEGS_PER_WAYPOINT * TUNNEL_WAYPOINTS)
#define TUNNEL_SEGMENT_QUADS (TUNNEL_SEGMENT_VERTS)
#define TUNNEL_SEGMENT_INDICES (TUNNEL_SEGMENT_QUADS * 6)
#define TUNNEL_TILE_PER_SEG 1.0f
#define TUNNEL_TILE_PER_QUAD 1.0f
#define TUNNEL_VERTS (2+(TUNNEL_SEGMENTS * TUNNEL_SEGMENT_VERTS * 2)) // Every vertex in a segment has a clone (even counting the first and last segment), for better texturecoord control (each segment is the last and first in two connected quads)
#define TUNNEL_QUADS ((TUNNEL_SEGMENTS-1) * TUNNEL_SEGMENT_QUADS)
#define TUNNEL_INDICES (TUNNEL_QUADS * 6)
#define TUNNEL_FACES (TUNNEL_QUADS * 2)
// Scene03
#define GRID_VERTEX NLTVERTEX
#define GRID_FVF D3DFVF_NLTVERTEX
#define GRID_LINES_X 20
#define GRID_LINES_Y 20
#define GRID_LINES_Z 20
#define GRID_SEG_SIZE 0.5f
#define GRID_TILES 20
#define GRID_SEG_LENGTH (GRID_WIDTH / GRID_TILES)
#define GRID_WIDTH 100.0f
#define GRID_HEIGHT 100.0f
#define GRID_DEPTH 100.0f
#define GRID_SPACE_X (GRID_WIDTH / (FLOAT)(GRID_LINES_X-1))
#define GRID_SPACE_Y (GRID_HEIGHT / (FLOAT)(GRID_LINES_Y-1))
#define GRID_SPACE_Z (GRID_DEPTH / (FLOAT)(GRID_LINES_Z-1))
#define GRID_LINES ((GRID_LINES_X*GRID_LINES_Y) + (GRID_LINES_Y*GRID_LINES_Z) + (GRID_LINES_X*GRID_LINES_Z))
#define GRID_POINTS (GRID_LINES_X * GRID_LINES_Y * GRID_LINES_Z)
#define GRID_VERTS (GRID_LINES * 4) // We'll create a quad for each line
#define GRID_QUADS (GRID_LINES) // 1 quad per line
#define GRID_MOVETIME 20.0f
#define GRID_INDICES (GRID_POINTS * 3 * 6) // 3 quads per point (x,y,z directions), 6 indices per quad
// Scene04
#define METAB_FVF D3DFVF_NVERTEX
#define METAB_VERTEX NVERTEX
#define METAB_VERTS 20000//(METAB_GRID_RES*METAB_GRID_RES*METAB_GRID_RES * (5*3)) // Max 5 triangles (3 vertices each)
#define METAB_FACES (METAB_VERTS / 3)
#define METAB_GRID_SIZE 70.0f
#define METAB_GRID_RES 10 // Number of cells in width, height and depth of grid
#define METAB_CELL_SIZE (METAB_GRID_SIZE / (METAB_GRID_RES-1)) // This is the width, height and depth of all cells (dimensions are "homogeneous")
#define METAB_BALLS 4
#define METAB_RADIUS 13.0f
#define METAB_MOVE_RADIUS 15.0f
#define METAB_SPEED 3.0f
// Scene05
#define TUNNEL2_LENGTH 150.0f
#define TUNNEL2_RADIUS 1.0f
#define TUNNEL2_SHAKERADIUS 0.002f
#define TUNNEL2_WILD_RADIUS 30.0f
#define TUNNEL2_WILDCAM_RADIUS 2.0f
#define TUNNEL2_WILDCAM_TIME 0.5f
#define TUNNEL2_BUMPSTRENGTH 1.3f
#define TUNNEL2_WPBUMPS 2
#define TUNNEL2_SEGBUMPS 8
#define TUNNEL2_SPEED 2.0f
#define TUNNEL2_VERTEX NLVERTEX
#define TUNNEL2_FVF D3DFVF_NLVERTEX
#define TUNNEL2_WAYPOINTS 4 // 4 waypoints for the visible part of the tunnel, and 2 endpoints (added manually) for cat-mull rom calculations
#define TUNNEL2_SEGS_PER_WAYPOINT 20
#define TUNNEL2_SEGMENT_VERTS 64
#define BLOOD_PARTICLES 70
#define BPARTICLES_WAYPOINTS (TUNNEL2_WAYPOINTS+2)
#define BPARTICLES_SIZE 1.0f
#define BPARTICLES_SPEED (TUNNEL2_SPEED * 0.3f)
#define BPARTICLES_RADIUS 7.0f
#define TUNNEL2_SEGMENTS (TUNNEL2_SEGS_PER_WAYPOINT * TUNNEL2_WAYPOINTS)
#define TUNNEL2_SEGMENT_QUADS (TUNNEL2_SEGMENT_VERTS)
#define TUNNEL2_SEGMENT_INDICES (TUNNEL2_SEGMENT_QUADS * 6)
#define TUNNEL2_TILE_PER_SEG 1.0f
#define TUNNEL2_TILE_PER_QUAD 1.0f
#define TUNNEL2_VERTS (2+(TUNNEL2_SEGMENTS * TUNNEL2_SEGMENT_VERTS * 2)) // Every vertex in a segment has a clone (even counting the first and last segment), for better texturecoord control (each segment is the last and first in two connected quads)
#define TUNNEL2_QUADS (TUNNEL2_SEGMENTS-1) * TUNNEL2_SEGMENT_QUADS
#define TUNNEL2_INDICES (TUNNEL2_QUADS * 6)
#define TUNNEL2_FACES (TUNNEL2_QUADS * 2)
// Scene 08
#define STAR_BALLS 750
#define STAR_BALLSPEED 1.5f
#define STAR_BALLSPEED2 0.5f
// Scene 10
#define SCENE10_FVF D3DFVF_LVERTEX
#define SCENE10_VERTEX LVERTEX
// Generic purpose
#define CUBEMAP_RES 512 // Resolution of cubemap
#define QUADS_X 4 // SetDetailedVBRect()
#define QUADS_Y 4
#define ALPHA_FULL 255.0f
#define ALPHA_NONE 0.0f
#define VERTEX_POINTSIZE 10.0f
#include "main.h"
TCHAR g_szInfoLine1[256] = "";
TCHAR g_szInfoLine2[256] = "";
TCHAR szDemoTime[120];
INT iOnlyPlayScene = ONLY_PLAY_SCENE; // Which scene to run unlimited. 0 == disabled
LPDIRECT3DDEVICE8 g_pd3dDevice;
INT GridCompare( const VOID* arg1, const VOID* arg2 );
//-----------------------------------------------------------------------------
// Name: BlendTexture()
// Desc: Blends a texture (source1) with another (source2), storing it in a third texture (dest).
// Note: The RECTs are different treated. Right and Bottom are respectively Width and Height, and
// Left and Top are the offsets.
//-----------------------------------------------------------------------------
HRESULT BlendTexture( LPDIRECT3DTEXTURE8 pSource1, LPDIRECT3DTEXTURE8 pSource2, LPDIRECT3DTEXTURE8 pDest, FRECT frcSource1, FRECT frcSource2, FLOAT fAlpha, BOOL bReplace )
{
HRESULT hr = S_OK;
SetRenderTargetToTexture( pDest );
if ( bReplace )
{
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_SRCALPHA );
}
else
{
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
}
if ( pSource2 )
{
ShowTexture( pSource2, frcSource2.left, frcSource2.top, frcSource2.right, frcSource2.bottom, ALPHA_FULL, 1.0f );
}
ShowTexture( pSource1, frcSource1.left, frcSource1.top, frcSource1.right, frcSource1.bottom, fAlpha, 1.0f );
RestoreRenderTarget();
return hr;
}
//-----------------------------------------------------------------------------
// Name: Animate()
// Desc: Animates the particles
//-----------------------------------------------------------------------------
HRESULT CBloodParticles::Animate( FLOAT fLocalTime, FLOAT fCameraProgress )
{
HRESULT hr = S_OK;
INT i;
if ( m_iNumParticles <= 0 )
return S_OK;
NLTVERTEX vTable[] =
{
{ -BPARTICLES_SIZE, BPARTICLES_SIZE, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }, // x,y,z,nx,ny,nz,col,tu,tv
{ BPARTICLES_SIZE, BPARTICLES_SIZE, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 1.0f, 0.0f },
{ BPARTICLES_SIZE,-BPARTICLES_SIZE, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 1.0f, 1.0f },
{ -BPARTICLES_SIZE,-BPARTICLES_SIZE, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 1.0f },
};
//--------------------------------------------------------------------
// PER-PARTICLE CALCULATION
//--------------------------------------------------------------------
NLTVERTEX* pVertices;
if ( FAILED(hr = m_pVB->Lock(0, NULL, (BYTE**)&pVertices, NULL)) )
return hr;
for ( i=0; i<m_iNumParticles; i++ )
{
FLOAT fTimeDiff = fLocalTime - m_particle[i].fLastTime;
m_particle[i].fAdvance = m_particle[i].fStartOffset - (fTimeDiff * BPARTICLES_SPEED);
/* if ( m_particle[i].fAdvance >= 1.0f )
{
m_particle[i].fAdvance -= 1.0f;
m_particle[i].fStartOffset = 0.0f;
m_particle[i].vPrevOffset = m_particle[i].vNextOffset;
m_particle[i].vNextOffset = D3DXVECTOR3( RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
0.0f );
fTimeDiff -= 1.0f;
m_particle[i].fLastTime = fLocalTime;
}*/
if ( m_particle[i].fAdvance <= 0.0f )
{
m_particle[i].fAdvance += 1.0f;
m_particle[i].fStartOffset = 1.0f;
m_particle[i].vPrevOffset = m_particle[i].vNextOffset;
m_particle[i].vNextOffset = D3DXVECTOR3( RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
0.0f );
fTimeDiff = 0.0f;
m_particle[i].fLastTime = fLocalTime;
}
m_particle[i].fSegProg = fCameraProgress + m_particle[i].fAdvance;
// New spline segment, generate new particle data
if ( m_particle[i].fSegProg >= 1.0f )
{
m_particle[i].fSegProg -= 1.0f; // include excess time
m_particle[i].iCurWaypoint = 1;
}
else
m_particle[i].iCurWaypoint = 0;
memcpy( m_wpWaypoint, &g_tunnel2.m_wpWaypoint[m_particle[i].iCurWaypoint], sizeof(m_wpWaypoint) );
D3DXVECTOR3 vCtrlD3DXVECTOR31 = m_wpWaypoint[1].v + LinearChangeVector( m_particle[i].vPrevOffset, m_particle[i].vNextOffset, m_particle[i].fLastTime, fLocalTime, m_particle[i].fLastTime+3.0f );
D3DXVECTOR3 vCtrlD3DXVECTOR32 = m_wpWaypoint[2].v + LinearChangeVector( m_particle[i].vPrevOffset, m_particle[i].vNextOffset, m_particle[i].fLastTime, fLocalTime, m_particle[i].fLastTime+3.0f );
D3DXVECTOR3 vCtrlD3DXVECTOR33 = m_wpWaypoint[3].v + LinearChangeVector( m_particle[i].vPrevOffset, m_particle[i].vNextOffset, m_particle[i].fLastTime, fLocalTime, m_particle[i].fLastTime+3.0f );
D3DXVECTOR3 vCtrlD3DXVECTOR34 = m_wpWaypoint[4].v + LinearChangeVector( m_particle[i].vPrevOffset, m_particle[i].vNextOffset, m_particle[i].fLastTime, fLocalTime, m_particle[i].fLastTime+3.0f );
D3DXVec3CatmullRom( &m_particle[i].v, // Resulting interpolated point in curve
&vCtrlD3DXVECTOR31, // Controlpoint for startpoint
&vCtrlD3DXVECTOR32, // Startpoint in curve
&vCtrlD3DXVECTOR33, // Endpoint in curve
&vCtrlD3DXVECTOR34, // Controlpoint for endpoint
m_particle[i].fSegProg );
memcpy( pVertices+(i*4), vTable, sizeof(vTable) );
}
m_pVB->Unlock();
return hr;
}
//-----------------------------------------------------------------------------
// Name: CBloodParticles()
// Desc: Constructor
//-----------------------------------------------------------------------------
CBloodParticles::CBloodParticles()
{
m_ptexParticle = NULL;
m_pVB = NULL;
m_iNumParticles = BLOOD_PARTICLES;
m_iNumWaypoints = BPARTICLES_WAYPOINTS;
m_iCurrentWaypoint = 0;
ZeroMemory( m_wpWaypoint, sizeof(m_wpWaypoint ) );
ZeroMemory( m_particle, sizeof(m_particle) );
for ( INT i=0; i<m_iNumParticles; i++ )
{
m_particle[i].v.x = 0.0f;
m_particle[i].v.y = 0.0f;
m_particle[i].v.z = 0.0f;
m_particle[i].fSize = BPARTICLES_SIZE;
m_particle[i].fAdvance = 0.0f;
m_particle[i].fStartOffset = RandRange( 0.0f, 1.0f );//(FLOAT)i / (m_iNumParticles-1) - RandRange( 0.0f, 1.0f / (m_iNumParticles-1) );
m_particle[i].fSegProg = 0.0f; // Prog factor of curve, distribute particles over progressfactor
m_particle[i].iCurWaypoint = 0; // Waypoint0 is not a valid waypoint, as it is only used for catmull-rom splines
}
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initializes and allocates devicedepenent resources for the class.
//-----------------------------------------------------------------------------
HRESULT CBloodParticles::InitDeviceObjects()
{
HRESULT hr = S_OK;
#ifdef PLAY_SCENE05
if ( FAILED(hr = g_pd3dDevice->CreateVertexBuffer(BLOOD_PARTICLES*8*sizeof(NLTVERTEX), NULL, D3DFVF_NLTVERTEX, D3DPOOL_MANAGED, &m_pVB)) )
return hr;
if ( FAILED(hr = D3DXCreateTextureFromFile(g_pd3dDevice, _T("data\\bitmaps\\scene05\\firefly_r.png"), &m_ptexParticle)) )
{
DisplayErrorMsg2( D3DAPPERR_MEDIANOTFOUND, NULL );
return hr;
}
// Initialize wild-waypoints for particles, copy waypoints from tunnel2 as base
memcpy( m_wpWaypoint, g_tunnel2.m_wpWaypoint, sizeof(g_tunnel2.m_wpWaypoint) );
for ( INT i=0; i<m_iNumParticles; i++ )
{
m_particle[i].vPrevOffset = D3DXVECTOR3( RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
0.0f );
m_particle[i].vNextOffset = D3DXVECTOR3( RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
RandRange(-BPARTICLES_RADIUS, BPARTICLES_RADIUS),
0.0f );
}
#endif // PLAY_SCENE05
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Cleans up any allocated resources used by the class.
//-----------------------------------------------------------------------------
HRESULT CBloodParticles::InvalidateDeviceObjects()
{
HRESULT hr = S_OK;
SAFE_RELEASE( m_pVB );
SAFE_RELEASE( m_ptexParticle );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Renders the group of fireflies
//-----------------------------------------------------------------------------
HRESULT CBloodParticles::Render()
{
HRESULT hr = S_OK;
D3DXMATRIX matBillboard;
if ( m_iNumParticles <= 0 )
return S_OK;
matBillboard = g_cam.GetViewMatrix();
matBillboard._14 = 0.0f;
matBillboard._24 = 0.0f;
matBillboard._34 = 0.0f;
matBillboard._44 = 1.0f;
D3DXMatrixInverse( &matBillboard, NULL, &matBillboard );
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetTexture( 0, m_ptexParticle );
g_pd3dDevice->SetVertexShader( D3DFVF_NLTVERTEX );
g_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(NLTVERTEX) );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
D3DXMATRIX matTranslate;
for ( INT i=0; i<m_iNumParticles; i++ )
{
matBillboard._41 = m_particle[i].v.x;
matBillboard._42 = m_particle[i].v.y;
matBillboard._43 = m_particle[i].v.z;
D3DXMatrixTranslation( &matTranslate, m_particle[i].v.x, m_particle[i].v.y, m_particle[i].v.z );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matTranslate );
if ( FAILED(hr = g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, (i*4), 2)) )
return hr;
}
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matIdentity );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
g_pd3dDevice->SetTexture( 0, NULL );
return hr;
}
//-----------------------------------------------------------------------------
// Name: CenterMesh()
// Desc: Finds the center of the mesh and then moves the mesh by vertex to origin.
//-----------------------------------------------------------------------------
HRESULT CenterMesh( CD3DMesh* pMesh, LPDIRECT3DVERTEXBUFFER8 pVB )
{
HRESULT hr = S_OK;
BYTE* pVertex = NULL;
BYTE* pVertices = NULL;
DWORD dwFVF = pMesh->GetSysMemMesh()->GetFVF();
DWORD dwStride = D3DXGetFVFVertexSize( dwFVF );
DWORD dwNumVerts = pMesh->GetSysMemMesh()->GetNumVertices();
D3DXVECTOR3 vCentre;
FLOAT fRadius;
if ( !pVB )
{
MessageBoxOK( _T("CenterMesh()\nA buffer pointer is NULL!") );
return E_FAIL;
}
if ( FAILED(pVB->Lock(0, NULL, &pVertices, NULL)) )
return E_FAIL;
D3DXComputeBoundingSphere( pVertices, dwNumVerts, dwFVF, &vCentre, &fRadius );
INT iVert=0;
for ( DWORD v=0; v<dwNumVerts; v++ )
{
iVert = v*dwStride;
pVertex = pVertices + iVert;
((ALLVERTEX*)pVertex)->x -= vCentre.x;
((ALLVERTEX*)pVertex)->y -= vCentre.y;
((ALLVERTEX*)pVertex)->z -= vCentre.z;
}
pVB->Unlock();
return hr;
}
//-----------------------------------------------------------------------------
// Name: CenterMeshFVF()
// Desc: Finds the center of the mesh and then moves the mesh by vertex to origin.
//-----------------------------------------------------------------------------
HRESULT CenterMeshFVF( LPD3DXMESH pMesh, DWORD dwFVF )
{
HRESULT hr = S_OK;
LPDIRECT3DVERTEXBUFFER8 pVB = NULL;
DWORD dwStride = D3DXGetFVFVertexSize( dwFVF );
DWORD dwNumVerts = pMesh->GetNumVertices();
D3DXVECTOR3 vCentre;
FLOAT fRadius;
pMesh->GetVertexBuffer( &pVB );
if ( !pVB )
{
MessageBoxOK( _T("CenterMesh()\nA buffer pointer is NULL!") );
return E_FAIL;
}
BYTE* pVertex = NULL;
BYTE* pVertices = NULL;
if ( FAILED(pVB->Lock(0, NULL, &pVertices, NULL)) )
return E_FAIL;
D3DXComputeBoundingSphere( pVertices, dwNumVerts, dwFVF, &vCentre, &fRadius );
INT iVert=0;
for ( DWORD v=0; v<dwNumVerts; v++ )
{
iVert = v*dwStride;
pVertex = pVertices + iVert;
((ALLVERTEX*)pVertex)->x -= vCentre.x;
((ALLVERTEX*)pVertex)->y -= vCentre.y;
((ALLVERTEX*)pVertex)->z -= vCentre.z;
}
pVB->Unlock();
return hr;
}
//-----------------------------------------------------------------------------
// Name: AddFlies()
// Desc: Adds flies to a firefly-group.
//-----------------------------------------------------------------------------
HRESULT CFireFlies::AddFlies( INT cNewFlies, D3DXVECTOR3 vPos, FLOAT fTimeStart, FLOAT fLocalTime, FLOAT fTimeDiff, LONG lRandSeed )
{
HRESULT hr = S_OK;
for ( INT i=m_iNumFlies; i<m_iNumFlies+cNewFlies; i++ )
{
for ( INT j=1; j<FIREFLY_GLOWLAYERS; j++ )
m_fly[i].v[j] = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); // Set history positions to 0.0f offset from start position
m_fly[i].v[0] = vPos; // start position
m_fly[i].fSize = 1.0f;
m_fly[i].fVisibility = 1.0f;
m_fly[i].fTimeDiff = fTimeDiff;
m_fly[i].fSegTStart = fTimeStart + ((i-m_iNumFlies)*fTimeDiff); // Start time of segment
m_fly[i].fSegTCurrent = 0.0f; // Current time in segment
m_fly[i].fSegProg = 0.0f; // Progress factor of curve
if ( fLocalTime < m_fly[i].fSegTStart )
m_fly[i].bExists = FALSE;
else
m_fly[i].bExists = TRUE;
m_fly[i].fSegTLength = RandRange( 2.0f, 3.0f );
m_fly[i].vSwirlV0 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + vPos;
m_fly[i].vSwirlV1 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + vPos;
m_fly[i].vSwirlV2 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
m_fly[i].vSwirlV3 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
}
m_iNumFlies += cNewFlies;
return hr;
}
//-----------------------------------------------------------------------------
// Name: Animate()
// Desc: Animates the group of fireflies
//-----------------------------------------------------------------------------
HRESULT CFireFlies::Animate( FLOAT fLocalTime )
{
HRESULT hr = S_OK;
D3DXVECTOR3 vOldGroupPos;
FLOAT fThisTimeKey;
FLOAT fNextTimeKey;
FLOAT fSegProg;
INT i = 0;
if ( m_iNumFlies <= 0 )
return S_OK;
//--------------------------------------------------------------------
// GROUP OF FLIES MOVEMENT
//--------------------------------------------------------------------
NLTVERTEX vTable[] =
{
{ -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 0.0f }, // x,y,z,nx,ny,nz,col,tu,tv
{ 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 1.0f, 0.0f },
{ 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 1.0f, 1.0f },
{ -1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0xffffffff, 0.0f, 1.0f },
};
for ( i=1; i<m_iNumWaypoints-1; i++ ) // Starting and ending within end-waypoints, because flies should never calculate splines to end-lines
{
if ( fLocalTime < m_wpWaypoint[i+1].fTime ) // if less, current time is between this and the previous waypoint
{
m_iCurrentWaypoint = i;
fThisTimeKey = m_wpWaypoint[i].fTime;
fNextTimeKey = m_wpWaypoint[i+1].fTime;
break;
}
}
fSegProg = (fLocalTime - fThisTimeKey) / (fNextTimeKey-fThisTimeKey);
// Group position moves along curved waypoints
vOldGroupPos = m_vGroupPos;
D3DXVec3CatmullRom( &m_vGroupPos, // Resulting interpolated point in curve
&m_wpWaypoint[m_iCurrentWaypoint-1].v, // Controlpoint for startpoint
&m_wpWaypoint[m_iCurrentWaypoint+0].v, // Startpoint in curve
&m_wpWaypoint[m_iCurrentWaypoint+1].v, // Endpoint in curve
&m_wpWaypoint[m_iCurrentWaypoint+2].v, // Controlpoint for endpoint
fSegProg );
//--------------------------------------------------------------------
// INDIVIDUAL FLY MOVEMENT
//--------------------------------------------------------------------
NLTVERTEX* pVertices;
if ( FAILED(hr = m_pVB->Lock(0, NULL, (BYTE**)&pVertices, NULL)) )
return hr;
for ( i=0; i<m_iNumFlies; i++ )
{
m_fly[i].fSegTCurrent = fLocalTime - m_fly[i].fSegTStart; // Currently spent time in segment
m_fly[i].fSegProg = m_fly[i].fSegTCurrent / m_fly[i].fSegTLength; // Progress of curve factor
if ( m_fly[i].bExists == FALSE ) // If fly doesn't exist, check if it should start existing
{
if ( fLocalTime > m_fly[i].fSegTStart )
{
m_fly[i].bExists = TRUE;
}
else
continue; // If not, bring on the next fly
}
// Individual fly movement (swirl around group position)
D3DXVECTOR3 vDistance;
if ( m_fly[i].fSegProg >= 1.0f ) // REMEMBER to include excess time
{
m_fly[i].fSegTStart = fLocalTime;
m_fly[i].fSegTCurrent = m_fly[i].fSegProg - 1.0f;
m_fly[i].fSegTLength = RandRange( 1.0f, 1.5f );
m_fly[i].fSegProg -= 1.0f;
m_fly[i].vSwirlV0 = m_fly[i].vSwirlV1;
m_fly[i].vSwirlV1 = m_fly[i].vSwirlV2;
m_fly[i].vSwirlV2 = m_fly[i].vSwirlV3;
// do
// {
m_fly[i].vSwirlV3 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius*3),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
// vDistance = m_fly[i].vSwirlV3 - m_fly[i].vSwirlV2;
// } while( (FLOAT)fabs(vDistance.x) < 2.0f || (FLOAT)fabs(vDistance.y) < 2.0f || (FLOAT)fabs(vDistance.z) < 2.0f ); // ensure that flies move at least a certain distance
}
//D3DXVECTOR3 vNewFlyPos;
D3DXVECTOR3 vGlowDist;
FLOAT fAlpha;
for ( INT j=0; j<FIREFLY_GLOWLAYERS; j++ )
{
D3DXVec3CatmullRom( &m_fly[i].v[j], // Resulting interpolated point in curve
&m_fly[i].vSwirlV0, // Controlpoint for startpoint
&m_fly[i].vSwirlV1, // Startpoint in curve
&m_fly[i].vSwirlV2, // Endpoint in curve
&m_fly[i].vSwirlV3, // Controlpoint for endpoint
max(0, m_fly[i].fSegProg - (0.02f*j)) );// Progress factor
if ( j>0 )
{
vGlowDist = m_fly[i].v[j]-m_fly[i].v[j-1];
FLOAT vScaleFactor = FIREFLY_MAX_GLOWDIST * j; // Rescales glow layers to within max_glow_dist
if ( D3DXVec3Length(&vGlowDist) > FIREFLY_MAX_GLOWDIST ) // Distance to actual point should not exceed this magic value (or else you get gaps between the textures)
{
D3DXVec3Normalize( &m_fly[i].v[j], &vGlowDist );
m_fly[i].v[j] *= vScaleFactor;
m_fly[i].v[j] += m_fly[i].v[0];
}
}
// Create glow layers by adjusting diffuse for each glow layer
fAlpha = (((1.0f - ((FLOAT)j/(FIREFLY_GLOWLAYERS-1))) * 255.0f) * (1.0f-((FLOAT)fabs(m_fly[i].v[j].z-(g_cam.GetEyePt().z+30.0f)) / 40.0f)) );
fAlpha = max( 0.0f, min(255.0f, fAlpha) ); // Make sure alpha value doesn't wrap around
vTable[0].diffuse = vTable[1].diffuse = vTable[2].diffuse = vTable[3].diffuse = D3DCOLOR_ARGB( (BYTE)fAlpha, 0xff, 0xff, 0xff );
memcpy( pVertices+(i*FIREFLY_GLOWLAYERS*4)+(j*FIREFLY_GLOWLAYERS), vTable, sizeof(vTable) );
}
}
m_pVB->Unlock();
m_vAveragePos += m_fly[i].v[0]; // Add all vectors together, to later find average vector
m_light.Position.x = m_fly[0].v[0].x; //m_vAveragePos.x;
m_light.Position.z = m_fly[0].v[0].z; //m_vAveragePos.z;
if ( m_fly[0].bExists )
m_light.Diffuse.r = m_light.Diffuse.g = m_light.Diffuse.b = LinearChange( 0.0f, 56.0f, 11.0f, fLocalTime, 13.0f );
g_pd3dDevice->SetLight( 4, &m_light );
return hr;
}
//-----------------------------------------------------------------------------
// Name: CFireFlies()
// Desc: Constructor
//-----------------------------------------------------------------------------
CFireFlies::CFireFlies( INT iStartFlies )
{
m_iNumFlies = iStartFlies;
m_fGroupRadius = 5.0f;
m_fSpeed = 1.0f;
m_ptexFirefly = NULL;
ZeroMemory( m_wpWaypoint, sizeof(m_wpWaypoint ) );
ZeroMemory( m_vAveragePos, sizeof(m_vAveragePos) );
FLOAT initWaypoints[] =
{
0.0f, 0.0f, 3.0f, 0.0f, // time key, x, y, z
1.0f, 2.0f, 3.0f, 4.0f,
5.0f, 10.0f, 3.0f, 15.0f,
10.0f, 2.0f, 3.0f, 5.0f,
15.0f, -10.0f, 3.0f, 15.0f,
20.0f, -5.0f, 3.0f, -5.0f,
25.0f, 10.0f, 3.0f, -10.0f,
30.0f, 2.0f, 3.0f, 10.0f,
35.0f, 12.0f, 3.0f, 5.0f,
40.0f, 0.0f, 3.0f, 0.0f,
42.0f, -10.0f, 3.0f, 10.0f,
50.0f, 10.0f, 3.0f, -5.0f,
55.0f, -5.0f, 5.0f, 5.0f,
57.0f, 10.0f, 7.0f, -5.0f,
58.0f, 0.0f, 12.0f, 0.0f,
59.0f, 0.0f,100.0f, 0.0f,
2000.0f, 0.0f,100.0f, 0.0f, // end point, not supposed to reach end time
};
m_iNumWaypoints = sizeof(initWaypoints) / sizeof(WAYPOINT3D);
/* for ( INT wayp=0; wayp<10; wayp++ )
{
initWaypoints[((wayp*4*4) + 3)] -= 20.0f; // Adjust Z-value of each waypoint (temporarily solution)
}
*/
memcpy( m_wpWaypoint, initWaypoints, sizeof(initWaypoints) );
m_iCurrentWaypoint = 0;
m_vGroupPos.x = m_wpWaypoint[0].v.x;
m_vGroupPos.y = m_wpWaypoint[0].v.y;
m_vGroupPos.z = m_wpWaypoint[0].v.z;
for ( INT j=0; j<1; j++ )
RandRange( 0.0f, 100.0f );
for ( INT i=0; i<MAX_FIREFLIES; i++ )
{
for ( INT j=0; j<FIREFLY_GLOWLAYERS; j++ ) // History points are same as start point
{
m_fly[i].v[j].x = 0.0f;
m_fly[i].v[j].y = 0.0f;
m_fly[i].v[j].z = 0.0f;
}
m_fly[i].fSize = 1.0f;
m_fly[i].fVisibility = 1.0f;
m_fly[i].fSegTStart = 0.0f; // Start time of segment
m_fly[i].fSegTCurrent = 0.0f; // Current time in segment
m_fly[i].fSegTLength = 1.0f; // Max time in seconds for duration of curve
m_fly[i].fSegProg = 0.0f; // Prog factor of curve
if ( i < m_iNumFlies )
m_fly[i].bExists = TRUE; // Set wheter fly exists or not
else
m_fly[i].bExists = FALSE;
m_fly[i].vSwirlV0 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius*3),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
m_fly[i].vSwirlV1 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius*3),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
m_fly[i].vSwirlV2 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius*3),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
m_fly[i].vSwirlV3 = D3DXVECTOR3( RandRange(-m_fGroupRadius, m_fGroupRadius),
RandRange(1.0f, m_fGroupRadius*3),
RandRange(-m_fGroupRadius, m_fGroupRadius) ) + m_vGroupPos;
}