-
Notifications
You must be signed in to change notification settings - Fork 2
/
gl_rpart.cpp
1998 lines (1673 loc) · 69.1 KB
/
gl_rpart.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) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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.
*/
/*******************************************************
QMB: 2.10
FEATURES:
Basic physics, including: world colisions, velocity and constant acceleration.
Easy extendable particle types.
Drawing optimised for speed (not correctness).
THINGS TO DO:
Particle emitters.
Depth Sorting (maybe) (uses too much time in current form).
More advansed physics such as area effects, point gravity etc...
Add Fuh's enhancments.
maybe add some more documentation (never too many comments)
REQUIREMENTS:
**32bit texture loading (from www.quakesrc.org)**
*include this file (gl_rpart.c and gl_rpart.h) in your source code
*remove particle_t etc from glquake.h
*remove the old r_part.c
*compile :D
*customise to taste
*******************************************************/
#include "quakedef.h"
#include "gl_rpart.h"
#include "Texture.h"
#ifdef JAVA
#include "java_vm.h"
#endif
//sin and cos tables for the particle triangle fans
static double sint[7] = {0.000000, 0.781832, 0.974928, 0.433884, -0.433884, -0.974928, -0.781832};
static double cost[7] = {1.000000, 0.623490, -0.222521, -0.900969, -0.900969, -0.222521, 0.623490};
//linked lists pointers for the first of the active, free and the a spare list for
//particles
particle_t *active_particles, *free_particles, *particles;
//particle emitters
particle_tree_t *particle_type_active, *particle_type_free, *particle_types;
//particle emitters
particle_emitter_t *particle_emitter_active, *particle_emitter_free, *particle_emitter;
//Holder of the particle texture
//FIXME: wont work for custom particles
// needs a structure system with {id, custom id, tex num}
int part_tex, blood_tex, smoke_tex, trail_tex, bubble_tex, lightning_tex, spark_tex;
int r_numparticles; //number of particles in total
int r_numparticletype; //number of particle types
int r_numparticleemitter; //number of particle emitters
int numParticles; //current number of alive particles (used in fps display)
double timepassed, timetemp; //for use with emitters when programmed right
//these will allow for calculating how many particle to add
vec3_t zerodir = {1, 1, 1}; //particles with no direction bias. (really a const)
vec3_t zero = {0, 0, 0};
vec3_t coord[4]; //used in drawing, saves working it out for each particle
float grav;
//was to stop particles not draw particles which were too close to the screen currently not used
//may be used again after depth sorting is implemented
CVar gl_clipparticles("gl_clipparticles", "0", true);
CVar gl_smoketrail("gl_smoketrail", "0", true);
//internal functions
void TraceLineN(vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int accurate); //Physics, checks to see if a particle hit the world
void R_UpdateAll(void); //used to run the particle update (do accelration and kill of old particles)
void MakeParticleTexure(void); //loads the builtin textures
void DrawParticles(void); //draws the particles
int CL_TruePointContents(vec3_t p) {
return SV_HullPointContents(&cl.worldmodel->hulls[0], 0, p);
}
__inline void RGBtoGrayscalef(vec3_t rgb) {
float value;
if (gl_sincity.getBool()) {
//value = min(255,rgb[0] * 0.2125 + rgb[1] * 0.7154 + rgb[2] * 0.0721);
//value = min(255,max(max(rgb[0],rgb[1]),rgb[2]));
value = min(1, rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114);
rgb[0] = value;
rgb[1] = value;
rgb[2] = value;
}
}
/** R_ClearParticles
* Reset all the pointers, reset the linklists
* Clear all the particle data
* Remake all the particle types
*/
//FIXME: needs to call qc to get custom particle types remade
void R_ClearParticles(void) {
int i;
numParticles = 0; //no particles alive
timepassed = cl.time; //reset emitter times
timetemp = cl.time;
//particles
free_particles = &particles[0];
particle_type_active = NULL; //no active particles
for (i = 0; i < r_numparticles; i++) //reset all particles
{
particles[i].next = &particles[i + 1];
}
particles[r_numparticles - 1].next = NULL;
//particle types
particle_type_free = &particle_types[0];
particle_type_active = NULL;
for (i = 0; i < r_numparticletype; i++) //reset all particle types
{
particle_types[i].start = NULL;
particle_types[i].next = &particle_types[i + 1];
}
particle_types[r_numparticletype - 1].next = NULL; //no next particle type for last type...
//particle emitters
for (i = 0; i < r_numparticleemitter; i++)
particle_emitter[i].next = &particle_emitter[i + 1];
particle_emitter_active = NULL;
particle_emitter_free = particle_emitter;
/*
particles are drawn in order here...
some orders may look strange when particles overlap
to add a new type:
AddParticleType(int src, int dst, part_move_t move, part_grav_t grav, part_type_t id, int custom_id, int texture, float startalpha)
//blend mode
//some examples are (gl_one,gl_one), (gl_src_alpha,gl_one_minus_src_alpha)
src = GL_SRC_ALPHA;
dst = GL_ONE;
//colision&physics: pm_static :particle ignroes velocity
pm_nophysics :particle with velocity but ignores the map
pm_normal :particle with velocity, stops moving when it hits a wall
pm_float :particle with velocity, only alive in the water
pm_bounce :particle with velocity, bounces off the world
pm_bounce_fast :particle with velocity, bounces off the world (no energy loss)
pm_shrink :particle with velocity, shrinks over time
pm_die :particle with velocity, dies after touching the map
pm_grow :particle with velocity, grows over time
move = pm_die;
//gravity effects: pg_none :no gravity acceleration
pg_grav_low :low gravity acceleration
pg_grav_belownormal :below normal gravity acceleration
pg_grav_normal :normal gravity acceleration
pg_grav_abovenormal :above normal gravity acceleration
pg_grav_high :high gravity acceleration
pg_rise_low :low negitive gravity
pg_rise :normal negitive gravity
pg_rise_high :high negitive gravity
grav = pg_none;
//type of particle
//list of set particles:
built in to engine:
p_sparks, p_smoke, p_fire, p_blood, p_chunks, p_lightning, p_bubble, p_trail
for use with QC customisation
p_custom
id = p_fire;
//will be used for QC custom controled particle types
this field is ignored unless the 'id' field has p_custom
used to uniquely define diffrent custom particles
custom_id = 0;
//what texture to use
texture = part_tex;
//the starting alpha value of the particles
startalpha = 1;
*/
//make new particle types : sparks, blood, fire, chunks, bubble smoke, trail
AddParticleType(GL_SRC_ALPHA, GL_ONE, pm_die, pg_none, p_fire, 0, part_tex, 1); //fire
AddParticleType(GL_SRC_ALPHA, GL_ONE, pm_bounce, pg_grav_high, p_sparks, 0, spark_tex, 1); //sparks
AddParticleType(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, pm_normal, pg_grav_normal, p_blood, 0, blood_tex, 1); //blood
AddParticleType(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, pm_normal, pg_rise_low, p_smoke, 0, smoke_tex, 0.75f); //smoke
AddParticleType(GL_SRC_ALPHA, GL_ONE, pm_bounce_fast, pg_grav_normal, p_chunks, 0, part_tex, 1); //chunks
AddParticleType(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, pm_float, pg_rise, p_bubble, 0, bubble_tex, 1); //bubble
AddParticleType(GL_SRC_ALPHA, GL_ONE, pm_nophysics, pg_none, p_trail, 0, trail_tex, 1); //trail
AddParticleType(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, pm_nophysics, pg_none, p_lightning, 0, lightning_tex, 1); //lightning
AddParticleType(GL_SRC_ALPHA, GL_ONE, pm_decal, pg_grav_high, p_decal, 0, part_tex, 1);
//FIXME: add QC function call to reset the QC Custom particles
}
void AddParticleType(int src, int dst, part_move_t move, part_grav_t grav, part_type_t id, int custom_id, int texture, float startalpha) {
particle_tree_t *p;
p = particle_type_free;
particle_type_free = p->next;
p->next = particle_type_active;
particle_type_active = p;
particle_type_active->SrcBlend = src;
particle_type_active->DstBlend = dst;
particle_type_active->move = move;
particle_type_active->grav = grav;
particle_type_active->id = id;
particle_type_active->custom_id = custom_id;
particle_type_active->texture = texture;
particle_type_active->startalpha = startalpha;
}
/*
===============
R_InitParticles
===============
*/
void R_InitParticles(void) {
extern CVar sv_gravity;
int i;
//check the command line to see if a number of particles was given particle
i = COM_CheckParm("-particles");
if (i) {
r_numparticles = (int) (atoi(com_argv[i + 1]));
if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
r_numparticles = ABSOLUTE_MIN_PARTICLES; //cant have less than set min
} else {
r_numparticles = MAX_PARTICLES / 2; //defualt to set half the 'max'
}
r_numparticletype = MAX_PARTICLE_TYPES;
r_numparticleemitter = MAX_PARTICLE_EMITTER;
//allocate memory for the particles and particle type linked lists
particles = (particle_t *) Hunk_AllocName(r_numparticles * sizeof (particle_t), "particles");
particle_types = (particle_tree_t *) Hunk_AllocName(r_numparticletype * sizeof (particle_tree_t), "particlestype");
particle_emitter = (particle_emitter_t *) Hunk_AllocName(r_numparticleemitter * sizeof (particle_emitter_t), "particleemitters");
//make the particle textures
MakeParticleTexure();
//reset the particles
R_ClearParticles();
//Regester particle cvars
CVar::registerCVar(&gl_clipparticles);
CVar::registerCVar(&gl_smoketrail);
grav = 9.8 * (sv_gravity.getFloat() / 800.0f);
}
/*
===============
R_EntityParticles
===============
*/
#define NUMVERTEXNORMALS 162
extern float r_avertexnormals[NUMVERTEXNORMALS][3];
vec3_t avelocities[NUMVERTEXNORMALS];
float beamlength = 16;
void R_EntityParticles(entity_t *ent) {
int *colour = (int *) &d_8to24table[0x6f];
R_ParticleExplosion2(ent->origin, *colour, 1);
/*
int count;
int i;
particle_t *p;
float angle;
float sr, sp, sy, cr, cp, cy;
vec3_t forward;
float dist;
byte *colourByte;
dist = 64;
count = 50;
if (!avelocities[0][0])
{
for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
avelocities[0][i] = (rand()&255) * 0.01;
}
for (i=0 ; i<NUMVERTEXNORMALS ; i++)
{
angle = cl.time * avelocities[i][0];
sy = sin(angle);
cy = cos(angle);
angle = cl.time * avelocities[i][1];
sp = sin(angle);
cp = cos(angle);
angle = cl.time * avelocities[i][2];
sr = sin(angle);
cr = cos(angle);
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
if (!free_particles)
return;
p = free_particles;
free_particles = p->next;
p->next = active_particles;
active_particles = p;
p->hit = 0;
p->die = cl.time + 0.01;
colourByte = (byte *)&d_8to24table[0x6f];
p->colour[0] = colourByte[0]/255.0;
p->colour[1] = colourByte[1]/255.0;
p->colour[2] = colourByte[2]/255.0;
//p->type = pt_explode;
p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;
p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;
p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;
}
Con_Printf ("EntityParticles");*/
}
//==========================================================
//Particle emitter code
//==========================================================
/** R_AddParticleEmitter
* Will add a new emitter
* Emitters will be able to be linked to a entity
*/
void R_AddParticleEmitter(vec3_t org, int count, int type, int size, float time, vec3_t colour, vec3_t dir) {
particle_emitter_t *p;
if (!particle_emitter_free)
return;
p = particle_emitter_free;
particle_emitter_free = p->next;
p->next = particle_emitter_active;
particle_emitter_active = p;
VectorCopy(org, p->org);
p->count = count;
p->type = type;
p->size = size;
p->time = time;
VectorCopy(colour, p->colour);
VectorCopy(dir, p->dir);
}
/** R_UpdateEmitters
* Lets the emitters emit the particles :)
* will be called every frame
*/
void R_UpdateEmitters(void) {
particle_emitter_t *p;
double frametime;
if (cl.time == cl.oldtime)
return;
frametime = (cl.time - cl.oldtime);
for (p = particle_emitter_active; p; p = p->next) {
AddParticleColor(p->org, zero, max(1, (int) (p->count * frametime)), p->size, p->time, p->type, p->colour, p->dir);
}
}
//==========================================================================
//Old particle calling code
//Now the functions call the new ones to make the particles
//This saves changing the whole engine, and makes it easy just to drop in
//the particle system.
//==========================================================================
/*
===============
R_ParseParticleEffect
Parse an effect out of the server message
===============
*/
void R_ParseParticleEffect(void) {
vec3_t org, dir;
int i, count, msgcount, colour;
for (i = 0; i < 3; i++) //read in org
org[i] = MSG_ReadCoord();
for (i = 0; i < 3; i++) //read in direction
dir[i] = MSG_ReadChar() * (1.0 / 16);
msgcount = MSG_ReadByte(); //read in number
colour = MSG_ReadByte(); //read in 8bit colour
if (msgcount == 255) //255 is a special number
count = 1024; //its actually a particle explosion
else
count = msgcount;
R_RunParticleEffect(org, dir, colour, count);
}
/*===============
R_ParticleExplosion
===============*/
void R_ParticleExplosion(vec3_t org) {
vec3_t black;
black[0] = 1;
black[1] = 0;
black[2] = 0;
switch (CL_TruePointContents(org)) {
case CONTENTS_WATER:
case CONTENTS_SLIME:
case CONTENTS_LAVA:
AddParticle(org, 12, 14, 0.8f, p_fire, zerodir);
AddParticle(org, 6, 3.4f, 2.5, p_bubble, zerodir);
AddParticle(org, 64, 100, 0.75, p_sparks, zerodir);
AddParticle(org, 32, 60, 0.75, p_sparks, zerodir);
break;
default:
AddParticle(org, 18, 16, 1, p_fire, zerodir);
AddParticle(org, 64, 300, 0.925f, p_sparks, zerodir);
AddParticle(org, 32, 200, 0.925f, p_sparks, zerodir);
}
//AddParticle(org, 64, 300, 1.5f, p_sparks, zerodir);
//AddParticle(org, 32, 200, 1.5f, p_sparks, zerodir);
//AddParticle(org, 20, 25, 2.0f, p_fire, zerodir);
}
/*===============
R_ParticleExplosion2
===============*/
//Needs to be made to call new functions so that old ones can be removed
void R_ParticleExplosion2(vec3_t org, int colorStart, int colorLength) {
vec3_t colour;
byte *colourByte;
colourByte = (byte *) & d_8to24table[colorStart];
colour[0] = (float) colourByte[0] / 255.0;
colour[1] = (float) colourByte[1] / 255.0;
colour[2] = (float) colourByte[2] / 255.0;
RGBtoGrayscalef(colour);
AddParticleColor(org, zero, 64, 200, 1.5f, p_sparks, colour, zerodir);
AddParticle(org, 64, 1, 3, p_smoke, zerodir);
}
/*===============
R_BlobExplosion
===============*/
//also do colored fires
//JHL; tweaked to look better
void R_BlobExplosion(vec3_t org) {
vec3_t colour;
int i;
colour[0] = colour[1] = 0.1f;
colour[2] = 1;
RGBtoGrayscalef(colour);
AddParticleColor(org, zero, 20, 2, 2.0f, p_blood, colour, zerodir);
colour[0] = colour[1] = 0.4f;
AddParticleColor(org, zero, 444, 200, 1.5f, p_sparks, colour, zerodir);
for (i = 0; i < 10; i++) {
colour[0] = colour[1] = (rand() % 90) / 255.0;
AddParticleColor(org, zero, 1, 25, 1, p_fire, colour, zerodir);
}
}
/*===============
R_RunParticleEffect
===============*/
void R_RunParticleEffect(vec3_t org, vec3_t dir, int color, int count) {
byte *colourByte;
vec3_t colour, tempdir;
int i;
if ((dir[0] == 0) && (dir[1] == 0) && (dir[2] == 0))
VectorCopy(zerodir, tempdir);
else
VectorCopy(dir, tempdir);
colourByte = (byte *) & d_8to24table[color];
colour[0] = colourByte[0] / 255.0;
colour[1] = colourByte[1] / 255.0;
colour[2] = colourByte[2] / 255.0;
RGBtoGrayscalef(colour);
//QMB :REMOVE FOR OTHER ENGINES
//START :REMOVE block comment "/* */" out this whole section
//JHL:HACK; do qmb specific particles
if (color > 240 && color < 255 && qmb_mod) {
//JHL:NOTE; ADD THE BUBBLE!!
if (color == 241) // water bubbles
AddParticle(org, count, 2, 6, p_bubble, tempdir);
else if (color == 242) // sparks
AddParticle(org, count, 100, 1.0f, p_sparks, tempdir);
else if (color == 243) // chunks
{
/*
for (i=0; i<count; i++)
{
colour[0] = colour[1] = colour[2] = (rand()%128)/255.0+64;
AddParticleColor (org, zero, 1, 1, 4, p_chunks, colour, tempdir);
}
*/
} //JHL:NOTE; ADD ELECTRIC BUZZ (p_lightning?)!!
else if (color == 244) // electric sparks
{
colour[2] = 1.0f;
for (i = 0; i < count; i++) {
colour[0] = colour[1] = 0.4 + ((rand() % 90) / 255.0);
AddParticleColor(org, zero, 1, 100, 1.0f, p_sparks, colour, tempdir);
}
} //JHL:NOTE; ADD WATER DROPS!!
else if (color == 245) // rain
AddParticle(org, count, 100, 1.0f, p_sparks, tempdir);
} else
//END :REMOVE
{
if (count == 15) { //JHL:HACK; better looking gunshot (?)
colour[0] = colour[1] = colour[2] = 0.6f;
AddParticleColor(org, zero, 1, 2, 1, p_smoke, colour, tempdir);
//JHL:HACK; keept comptability with other mods (done QC side in qmb mod)
if (!qmb_mod) //QMB :REMOVE FOR OTHER ENGINES JUST THIS LINE
{
for (i = 0; i < 8; i++) {
colour[0] = colour[1] = colour[2] = (rand() % 90) / 255.0;
AddParticleColor(org, zero, 1, 1, 4, p_chunks, colour, tempdir);
}
AddParticle(org, 1, 100, 1.0f, p_sparks, tempdir);
}
} else if (count == 10) {
//AddParticleColor(org, zero, 10, 1, 4, p_chunks, colour, tempdir);
AddParticle(org, 3, 100, 1.0f, p_sparks, tempdir);
} else if (count == 20) {
//AddParticleColor(org, zero, 10, 1, 4, p_chunks, colour, tempdir);
AddParticle(org, 10, 100, 1.0f, p_sparks, zerodir);
} else if (count == 30) {
//AddParticleColor(org, zero, 10, 1, 4, p_chunks, colour, tempdir);
AddParticle(org, 5, 100, 1.0f, p_sparks, zerodir);
AddParticle(org, 50, 200, 0.5f, p_sparks, zerodir);
} else if (count == 1024)
R_ParticleExplosion(org);
else {
//JHL:HACK; make blood brighter...
if (color == 73) {
if (gl_sincity.getBool())
colour[0] = max(1.0f, colour[0]*2);
//colour[1] = 0f;
//colour[2] = 0f;
}
AddParticleColor(org, zero, count * 2, 3, 3, p_blood, colour, tempdir);
}
}
}
/*===============
R_LavaSplash
===============*/
//Need to find out when this is called
//JHL:NOTE; When Chthon sinks to lava...
//QMB: yep i worked that out, thanx (found out its also used in TF for the spy gren...)
void R_LavaSplash(vec3_t org) {
AddParticle(org, 1000, 250, 10, p_sparks, zerodir);
AddParticle(org, 1000, 500, 10, p_sparks, zerodir);
AddParticle(org, 100, 50, 6, p_fire, zerodir);
}
/*===============
R_TeleportSplash
===============*/
//Need to be changed so that they spin down into the ground
//whould look very cool
//maybe coloured blood (new type?)
void R_TeleportSplash(vec3_t org) {
vec3_t colour;
colour[0] = 0.9f;
colour[1] = 0.9f;
colour[2] = 0.9f;
AddParticleColor(org, zero, 256, 200, 1.0f, p_sparks, colour, zerodir);
}
//Should be made to call the new functions to keep compatablity
void R_RocketTrail(vec3_t start, vec3_t end, int type) {
vec3_t colour;
switch (type) {
case 0: // rocket trail
AddTrail(start, end, p_fire, 0.1f, 6, zerodir);
AddTrail(start, end, p_smoke, 1, 6, zerodir);
AddTrail(start, end, p_sparks, 0.2f, 1, zerodir);
break;
case 1: // smoke smoke
AddTrail(start, end, p_smoke, 1, 2, zerodir);
break;
case 2: // blood
AddTrail(start, end, p_blood, 2, 3, zerodir);
break;
case 3: //tracer 1
colour[0] = 0.1f;
colour[1] = 0.75f;
colour[2] = 0.1f;
RGBtoGrayscalef(colour);
AddTrailColor(start, end, p_sparks, 2, 2, colour, zerodir);
break;
case 5: // tracer 2
colour[0] = 1;
colour[1] = 0.85f;
colour[2] = 0;
RGBtoGrayscalef(colour);
AddTrailColor(start, end, p_sparks, 2, 2, colour, zerodir);
break;
case 4: // slight blood
AddParticle(end, 10, 1, 2, p_blood, zerodir);
break;
case 6: // voor trail
colour[0] = 1;
colour[1] = 0;
colour[2] = 0.75f;
RGBtoGrayscalef(colour);
AddTrailColor(start, end, p_sparks, 2, 2, colour, zerodir);
break;
}
}
//============================================================
//Particle drawing code
//============================================================
/*
===============
R_DrawParticles
===============
*/
void R_DrawParticles(void) {
if (cl.time != cl.oldtime)
R_UpdateAll();
glDepthMask(0); //not depth sorted so dont let particles block other particles...
glEnable(GL_BLEND); //all particles are blended
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
DrawParticles();
glDepthMask(1);
glDisable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
#ifdef JAVA
void Java_DrawParticle(JNIEnv *env, jclass this, float x, float y, float z, float size, float r, float g, float b, float a, float rotation) {
vec3_t org;
vec3_t distance;
org[0] = x;
org[1] = y;
org[2] = z;
//test to see if particle is too close to the screen (high fill rate usage)
if (gl_clipparticles.value) {
VectorSubtract(org, r_origin, distance);
if (distance[0] * distance[0] + distance[1] * distance[1] + distance[2] * distance[2] < 3200)
return;
}
glColor4f(r, g, b, a);
glPushMatrix();
glTranslatef(org[0], org[1], org[2]);
glScalef(size, size, size);
glRotatef(rotation, vpn[0], vpn[1], vpn[2]);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex3fv(coord[0]);
glTexCoord2f(0, 0);
glVertex3fv(coord[1]);
glTexCoord2f(1, 0);
glVertex3fv(coord[2]);
glTexCoord2f(1, 1);
glVertex3fv(coord[3]);
glEnd();
glPopMatrix();
}
#endif
/** GL_QuadPointsForBeam
* Draws a beam sprite between 2 points
* LH's code
*/
void GL_QuadPointsForBeam(vec3_t start, vec3_t end, vec3_t offset, float t1, float t2) {
vec3_t temp;
VectorAdd(start, offset, temp);
glTexCoord2f(1 + t1, 0);
glVertex3fv(temp);
VectorSubtract(start, offset, temp);
glTexCoord2f(1 + t1, 1);
glVertex3fv(temp);
VectorSubtract(end, offset, temp);
glTexCoord2f(0 + t2, 1);
glVertex3fv(temp);
VectorAdd(end, offset, temp);
glTexCoord2f(0 + t2, 0);
glVertex3fv(temp);
}
/** DrawParticles
* Main drawing code...
*/
void DrawParticles(void) {
particle_tree_t *pt;
particle_t *p;
vec3_t decal_vec[4], decal_up, decal_right, v, normal;
vec3_t distance;
int drawncount;
int lasttype = 0;
//point sprite thingo
static GLfloat constant[3] = {1.0f, 0.0f, 0.0f};
static GLfloat linear[3] = {0.0f, 1.0f, 0.0f};
static GLfloat quadratic[3] = {0.25f, 0.0f, -1.0f};
if (gl_point_sprite) {
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, constant);
//glPointParameterfEXT( GL_POINT_SIZE_MAX_EXT, 260.0f);
//glPointParameterfEXT( GL_POINT_SIZE_MIN_EXT, 1.0f);
}
VectorAdd(vup, vright, coord[2]);
VectorSubtract(vright, vup, coord[3]);
VectorNegate(coord[2], coord[0]);
VectorNegate(coord[3], coord[1]);
for (pt = particle_type_active; pt; pt = pt->next) {
glBlendFunc(pt->SrcBlend, pt->DstBlend);
if (pt->texture != 0 && pt->id != p_sparks && pt->move != pm_decal) {
glBindTexture(GL_TEXTURE_2D, pt->texture);
if ((pt->id != p_trail) && (pt->id != p_lightning)) {
//all textured particles except trails and lightning
drawncount = 0;
for (p = pt->start; p; p = p->next) {
//test to see if particle is too close to the screen (high fill rate usage)
if (gl_clipparticles.getBool() && drawncount >= 4) {
VectorSubtract(p->org, r_origin, distance);
if (distance[0] * distance[0] + distance[1] * distance[1] + distance[2] * distance[2] < 3200)
continue;
}
drawncount++;
glColor4f(p->colour[0], p->colour[1], p->colour[2], p->ramp);
if (p->hit == 0) {
/***NV_point_sprits***/
//Should work but is fucked
//They scale the wrong way
//Shrinking as they get close insted of growing
if (gl_point_sprite && false) {
glTexEnvf(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, GL_TRUE);
glEnable(GL_POINT_SPRITE_NV);
//glEnable(GL_POINT_SMOOTH);
glPointSize(100); //p->size);
glColor4f(p->colour[0], p->colour[1], p->colour[2], p->ramp);
glBegin(GL_POINTS);
glVertex3fv(p->org);
glEnd();
glDisable(GL_POINT_SPRITE_NV);
} else {
glPushMatrix();
glTranslatef(p->org[0], p->org[1], p->org[2]);
glScalef(p->size, p->size, p->size);
if (p->rotation_speed)
glRotatef(p->rotation, vpn[0], vpn[1], vpn[2]);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex3fv(coord[0]);
glTexCoord2f(0, 0);
glVertex3fv(coord[1]);
glTexCoord2f(1, 0);
glVertex3fv(coord[2]);
glTexCoord2f(1, 1);
glVertex3fv(coord[3]);
glEnd();
glPopMatrix();
}
} else {
//check what side the of the decal we are drawing
VectorNormalize2(p->vel, normal);
if (DotProduct(normal, r_origin) > DotProduct(normal, p->org)) {
VectorNegate(normal, v);
VectorVectors(v, decal_right, decal_up);
} else
VectorVectors(normal, decal_right, decal_up);
VectorScale(decal_right, p->size, decal_right);
VectorScale(decal_up, p->size, decal_up);
decal_vec[0][0] = p->org[0] - decal_right[0] - decal_up[0];
decal_vec[0][1] = p->org[1] - decal_right[1] - decal_up[1];
decal_vec[0][2] = p->org[2] - decal_right[2] - decal_up[2];
decal_vec[1][0] = p->org[0] - decal_right[0] + decal_up[0];
decal_vec[1][1] = p->org[1] - decal_right[1] + decal_up[1];
decal_vec[1][2] = p->org[2] - decal_right[2] + decal_up[2];
decal_vec[2][0] = p->org[0] + decal_right[0] + decal_up[0];
decal_vec[2][1] = p->org[1] + decal_right[1] + decal_up[1];
decal_vec[2][2] = p->org[2] + decal_right[2] + decal_up[2];
decal_vec[3][0] = p->org[0] + decal_right[0] - decal_up[0];
decal_vec[3][1] = p->org[1] + decal_right[1] - decal_up[1];
decal_vec[3][2] = p->org[2] + decal_right[2] - decal_up[2];
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex3fv(decal_vec[0]);
glTexCoord2f(0, 0);
glVertex3fv(decal_vec[1]);
glTexCoord2f(1, 0);
glVertex3fv(decal_vec[2]);
glTexCoord2f(1, 1);
glVertex3fv(decal_vec[3]);
glEnd();
}
}
} else {
//trails and lightning
int lengthscale;
float t1, t2, scrollspeed, radius, length;
vec3_t temp, offset;
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
for (p = pt->start; p; p = p->next) {
glColor4f(p->colour[0], p->colour[1], p->colour[2], p->ramp);
VectorSubtract(p->org2, p->org, temp);
length = sqrt(DotProduct(temp, temp)); // pythagoran theorm for 3D distance
// configurable numbers
radius = p->size; // thickness of beam
scrollspeed = -3.0; // scroll speed, 1 means it scrolls the entire height of the texture each second
lengthscale = 40; // how much distance in quake units it takes for the texture to repeat once
t1 = cl.time * scrollspeed + p->size;
t1 -= (int) t1; // remove the unnecessary integer portion of the number
t2 = t1 + (length / lengthscale);
VectorMA(vright, radius, vright, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
VectorAdd(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, radius, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
VectorSubtract(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, radius, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
// configurable numbers
radius = p->size * 1.5; // thickness of beam
scrollspeed = -1.5; // scroll speed, 1 means it scrolls the entire height of the texture each second
lengthscale = 80; // how much distance in quake units it takes for the texture to repeat once
t1 = cl.time * scrollspeed + p->size;
t1 -= (int) t1; // remove the unnecessary integer portion of the number
t2 = t1 + (length / lengthscale);
VectorMA(vright, radius, vright, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
VectorAdd(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, radius, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
VectorSubtract(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, radius, offset);
GL_QuadPointsForBeam(p->org, p->org2, offset, t1, t2);
}
glEnd();
if (gl_cull.getBool())
glEnable(GL_CULL_FACE);
}
} else {
if (pt->id != p_decal) {
//Sparks...
glDisable(GL_CULL_FACE);
glBindTexture(GL_TEXTURE_2D, pt->texture);
for (p = pt->start; p; p = p->next) {
vec3_t dup, offset;
VectorScale(p->vel, 0.125f, dup);
VectorSubtract(p->org, dup, dup);
glBegin(GL_QUADS);
glColor4f(p->ramp * p->colour[0], p->ramp * p->colour[1], p->ramp * p->colour[2], p->ramp);
//glColor4f (0,0,p->ramp*1.0f,p->ramp);
VectorMA(vright, p->size, vright, offset);
GL_QuadPointsForBeam(p->org, dup, offset, 1.0f, 1.0f);
VectorAdd(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, p->size, offset);
GL_QuadPointsForBeam(p->org, dup, offset, 1.0f, 1.0f);
VectorSubtract(vright, vup, offset);
VectorNormalize(offset);
VectorScale(offset, p->size, offset);
GL_QuadPointsForBeam(p->org, dup, offset, 1.0f, 1.0f);
glEnd();
}
if (gl_cull.getBool())
glEnable(GL_CULL_FACE);
} else {
glBindTexture(GL_TEXTURE_2D, pt->texture);
glEnable(GL_POLYGON_OFFSET_FILL);