]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/particles.qc
particles: volume weighting = negative count, absolute weighting = positive count
[divverent/nexuiz.git] / data / qcsrc / client / particles.qc
1 vector PointInBrush_vec;
2 float PointInBrush_Recurse()
3 {
4         float s;
5         entity se;
6         float f;
7
8         traceline(PointInBrush_vec, PointInBrush_vec, 0, world);
9         if not(trace_ent)
10                 return 0;
11         if(trace_ent == self)
12                 return 1;
13
14         se = trace_ent;
15         s = se.solid;
16         se.solid = SOLID_NOT;
17         f = PointInBrush_Recurse();
18         se.solid = s;
19
20         return f;
21 }
22 float PointInBrush(entity brush, vector point)
23 {
24         float f, s;
25
26         if not(self.modelindex)
27                 return 1;
28
29         s = self.solid;
30         self.solid = SOLID_BSP;
31         PointInBrush_vec = point;
32         f = PointInBrush_Recurse();
33         self.solid = s;
34
35         return f;
36 }
37
38 .float cnt; // effect number
39 .vector velocity; // particle velocity
40 .float waterlevel; // direction jitter
41 .float count; // count multiplier
42 .float glow_color; // palette color
43 .float impulse; // density
44 .string noise; // sound
45
46 void Draw_PointParticles()
47 {
48         float n, i;
49         vector p;
50         vector sz;
51         vector o;
52         o = self.origin;
53         sz = self.maxs - self.mins;
54         n = self.impulse * drawframetime;
55         for(i = random(); i <= n; ++i)
56         {
57                 p = o + self.mins;
58                 p_x += random() * sz_x;
59                 p_y += random() * sz_y;
60                 p_z += random() * sz_z;
61                 if(PointInBrush(self, p))
62                 {
63                         pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count, self.glow_color);
64                         if(self.noise != "")
65                         {
66                                 self.origin = p;
67                                 sound(self, CHAN_AUTO, self.noise, 1, ATTN_NORM);
68                         }
69                 }
70         }
71         self.origin = o;
72 }
73
74 .vector velocity; // particle velocity
75 .float waterlevel; // direction jitter
76 .float count; // count multiplier
77 .float glow_color; // palette color
78 .float impulse; // density
79 .string noise; // sound
80 void Ent_PointParticles()
81 {
82         self.modelindex = ReadShort();
83         self.origin_x = ReadCoord();
84         self.origin_y = ReadCoord();
85         self.origin_z = ReadCoord();
86         self.maxs_x = ReadCoord();
87         self.maxs_y = ReadCoord();
88         self.maxs_z = ReadCoord();
89         self.cnt = ReadShort(); // effect number
90         self.impulse = ReadCoord(); // density (<0: point, >0: volume)
91         if(self.impulse == 0)
92                 self.impulse = 1; // one per sec
93         self.velocity_x = ReadCoord();
94         self.velocity_y = ReadCoord();
95         self.velocity_z = ReadCoord();
96         self.waterlevel = ReadCoord();
97         self.count = ReadCoord();
98         self.glow_color = ReadByte();
99         if(self.noise)
100                 strunzone(self.noise);
101         self.noise = strzone(ReadString());
102
103         if(self.impulse < 0) // negative = volume weighted: impulse = particles/100qu^3 cube
104                 self.impulse *= -(self.maxs_x * self.maxs_y * self.maxs_z) / 1000000;
105
106         self.mins    = -0.5 * self.maxs;
107         self.maxs    =  0.5 * self.maxs;
108         self.origin  = self.origin - self.mins;
109
110         setorigin(self, self.origin);
111         setsize(self, self.mins, self.maxs);
112         self.solid = SOLID_NOT;
113         self.draw = Draw_PointParticles;
114 }