Colobot
particle.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/engine/engine.h"
29 
30 #include "sound/sound.h"
31 
32 
33 class CRobotMain;
34 class CObject;
35 class CSoundInterface;
36 
37 
38 // Graphics module namespace
39 namespace Gfx {
40 
41 const short MAXPARTICULE = 500;
42 const short MAXPARTITYPE = 5;
43 const short MAXTRACK = 100;
44 const short MAXTRACKLEN = 10;
45 const short MAXPARTIFOG = 100;
46 const short MAXWHEELTRACE = 1000;
47 
48 const short SH_WORLD = 0; // particle in the world in the interface
49 const short SH_FRONT = 1; // particle in the world on the interface
50 const short SH_INTERFACE = 2; // particle in the interface
51 const short SH_MAX = 3;
52 
53 // type == 0 -> triangles
54 // type == 1 -> effect00 (black background)
55 // type == 2 -> effect01 (black background)
56 // type == 3 -> effect02 (black background)
57 // type == 4 -> text (white background)
58 
59 
61 {
62  PARTIEXPLOT = 1,
64  PARTIMOTOR = 3,
65  PARTIGLINT = 4,
66  PARTIBLITZ = 5,
67  PARTICRASH = 6,
68  PARTIGAS = 7,
69  PARTIFIRE = 9,
70  PARTIFIREZ = 10,
71  PARTIBLUE = 11,
72  PARTISELY = 12,
73  PARTISELR = 13,
74  PARTIGUN1 = 18,
75  PARTIGUN2 = 19,
76  PARTIGUN3 = 20,
77  PARTIGUN4 = 21,
78  PARTIFRAG = 22,
79  PARTIQUEUE = 23,
82  PARTISMOKE1 = 26,
83  PARTISMOKE2 = 27,
84  PARTISMOKE3 = 28,
85  PARTISMOKE4 = 29,
86  PARTIBLOOD = 30,
87  PARTIBLOODM = 31,
88  PARTIVAPOR = 32,
89  PARTIVIRUS1 = 33,
90  PARTIVIRUS2 = 34,
91  PARTIVIRUS3 = 35,
92  PARTIVIRUS4 = 36,
93  PARTIVIRUS5 = 37,
94  PARTIVIRUS6 = 38,
95  PARTIVIRUS7 = 39,
96  PARTIVIRUS8 = 40,
97  PARTIVIRUS9 = 41,
98  PARTIVIRUS10 = 42,
99  PARTIRAY1 = 43,
100  PARTIRAY2 = 44,
101  PARTIRAY3 = 45,
102  PARTIRAY4 = 46,
103  PARTIFLAME = 47,
104  PARTIBUBBLE = 48,
105  PARTIFLIC = 49,
106  PARTIEJECT = 50,
107  PARTISCRAPS = 51,
108  PARTITOTO = 52,
109  PARTIERROR = 53,
111  PARTIINFO = 54,
112  PARTIQUARTZ = 55,
123  PARTIGUNDEL = 66,
124  PARTIPART = 67,
125  PARTITRACK1 = 68,
126  PARTITRACK2 = 69,
127  PARTITRACK3 = 70,
128  PARTITRACK4 = 71,
129  PARTITRACK5 = 72,
130  PARTITRACK6 = 73,
131  PARTITRACK7 = 74,
132  PARTITRACK8 = 75,
133  PARTITRACK9 = 76,
145  PARTIGLINTb = 88,
146  PARTIGLINTr = 89,
147  PARTILENS1 = 90,
148  PARTILENS2 = 91,
149  PARTILENS3 = 92,
150  PARTILENS4 = 93,
152  PARTISHOW = 95,
153  PARTICHOC = 96,
154  PARTIGFLAT = 97,
156  PARTIROOT = 100,
157  PARTIPLOUF0 = 101,
158  PARTIPLOUF1 = 102,
159  PARTIPLOUF2 = 103,
160  PARTIPLOUF3 = 104,
161  PARTIPLOUF4 = 105,
162  PARTIDROP = 106,
163  PARTIFOG0 = 107,
164  PARTIFOG1 = 108,
165  PARTIFOG2 = 109,
166  PARTIFOG3 = 110,
167  PARTIFOG4 = 111,
168  PARTIFOG5 = 112,
169  PARTIFOG6 = 113,
170  PARTIFOG7 = 114,
171  PARTIFOG8 = 115,
172  PARTIFOG9 = 116,
173  PARTILIMIT1 = 117,
174  PARTILIMIT2 = 118,
175  PARTILIMIT3 = 119,
176  PARTILIMIT4 = 120,
177  PARTIWATER = 121,
178  PARTIEXPLOG1 = 122,
179  PARTIEXPLOG2 = 123,
180  PARTIBASE = 124,
181  PARTITRACE0 = 140,
182  PARTITRACE1 = 141,
183  PARTITRACE2 = 142,
184  PARTITRACE3 = 143,
185  PARTITRACE4 = 144,
186  PARTITRACE5 = 145,
187  PARTITRACE6 = 146,
188  PARTITRACE7 = 147,
189  PARTITRACE8 = 148,
190  PARTITRACE9 = 149,
191  PARTITRACE10 = 150,
192  PARTITRACE11 = 151,
193  PARTITRACE12 = 152,
194  PARTITRACE13 = 153,
195  PARTITRACE14 = 154,
196  PARTITRACE15 = 155,
197  PARTITRACE16 = 156,
198  PARTITRACE17 = 157,
199  PARTITRACE18 = 158,
200  PARTITRACE19 = 159,
201 };
202 
203 enum ParticlePhase
204 {
205  PARPHSTART = 0,
206  PARPHEND = 1,
207 };
208 
209 struct Particle
210 {
211  char used; // TRUE -> particle used
212  char ray; // TRUE -> ray with goal
213  unsigned short uniqueStamp; // unique mark
214  short sheet; // sheet (0..n)
215  ParticleType type; // type PARTI*
216  ParticlePhase phase; // phase PARPH*
217  float mass; // mass of the particle (in rebounding)
218  float weight; // weight of the particle (for noise)
219  float duration; // length of life
220  Math::Vector pos; // absolute position (relative if object links)
221  Math::Vector goal; // goal position (if ray)
222  Math::Vector speed; // speed of displacement
223  float windSensitivity;
224  short bounce; // number of rebounds
225  Math::Point dim; // dimensions of the rectangle
226  float zoom; // zoom (0..1)
227  float angle; // angle of rotation
228  float intensity; // intensity
229  Math::Point texSup; // coordinated upper texture
230  Math::Point texInf; // coordinated lower texture
231  float time; // age of the particle (0..n)
232  float phaseTime; // age at the beginning of phase
233  float testTime; // time since last test
234  CObject* objLink; // father object (for example reactor)
235  CObject* objFather; // father object (for example reactor)
236  short objRank; // rank of the object, or -1
237  short trackRank; // rank of the drag
238 };
239 
240 struct Track
241 {
242  char used; // TRUE -> drag used
243  char drawParticle;
244  float step; // duration of not
245  float last; // increase last not memorized
246  float intensity; // intensity at starting (0..1)
247  float width; // tail width
248  int posUsed; // number of positions in "pos"
249  int head; // head to write index
250  Math::Vector pos[MAXTRACKLEN];
251  float len[MAXTRACKLEN];
252 };
253 
255 {
256  ParticleType type; // type PARTI*
257  Math::Vector pos[4]; // rectangle positions
258  float startTime; // beginning of life
259 };
260 
261 
269 {
270 public:
271  CParticle(CEngine* engine);
272  ~CParticle();
273 
275  void SetDevice(CDevice* device);
276 
278  void FlushParticle();
279 
281  void FlushParticle(int sheet);
282 
285  ParticleType type, float duration = 1.0f, float mass = 0.0f,
286  float windSensitivity = 1.0f, int sheet = 0);
287 
289  int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle* triangle,
290  ParticleType type, float duration = 1.0f, float mass = 0.0f,
291  float windSensitivity = 1.0f, int sheet = 0);
292 
294  int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type,
295  float duration = 1.0f, float mass = 0.0f, float weight = 0.0f,
296  float windSensitivity = 1.0f, int sheet = 0);
297 
300  float duration = 1.0f, int sheet = 0);
301 
304  float duration = 1.0f, float mass = 0.0f, float length = 10.0f, float width = 1.0f);
305 
307  void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3,
308  const Math::Vector &p4, ParticleType type);
309 
311  void DeleteParticle(ParticleType type);
313  void DeleteParticle(int channel);
315  void SetObjectLink(int channel, CObject *object);
317  void SetObjectFather(int channel, CObject *object);
318  void SetPosition(int channel, Math::Vector pos);
319  void SetDimension(int channel, Math::Point dim);
320  void SetZoom(int channel, float zoom);
321  void SetAngle(int channel, float angle);
322  void SetIntensity(int channel, float intensity);
323  void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity);
324  void SetPhase(int channel, ParticlePhase phase, float duration);
325 
327  bool GetPosition(int channel, Math::Vector &pos);
328 
331 
333  void SetFrameUpdate(int sheet, bool update);
335  void FrameParticle(float rTime);
337  void DrawParticle(int sheet);
338 
340  bool WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur);
341 
342 protected:
344  void DeleteRank(int rank);
346  bool CheckChannel(int &channel);
348  void DrawParticleTriangle(int i);
350  void DrawParticleNorm(int i);
352  void DrawParticleFlat(int i);
354  void DrawParticleFog(int i);
356  void DrawParticleRay(int i);
358  void DrawParticleSphere(int i);
360  void DrawParticleCylinder(int i);
362  void DrawParticleWheel(int i);
368  void Play(Sound sound, Math::Vector pos, float amplitude);
370  bool TrackMove(int i, Math::Vector pos, float progress);
372  void TrackDraw(int i, ParticleType type);
373 
374 protected:
375  CEngine* m_engine;
376  CDevice* m_device;
377  CTerrain* m_terrain;
378  CWater* m_water;
379  CRobotMain* m_main;
380  CSoundInterface* m_sound;
381 
382  Particle m_particle[MAXPARTICULE*MAXPARTITYPE];
383  EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0
384  Track m_track[MAXTRACK];
385  int m_wheelTraceTotal;
386  int m_wheelTraceIndex;
387  WheelTrace m_wheelTrace[MAXWHEELTRACE];
388  int m_totalInterface[MAXPARTITYPE][SH_MAX];
389  bool m_frameUpdate[SH_MAX];
390  int m_fogTotal;
391  int m_fog[MAXPARTIFOG];
392  int m_uniqueStamp;
393  int m_exploGunCounter;
394  float m_lastTimeGunDel;
395  float m_absTime;
396 };
397 
398 
399 } // namespace Gfx
400 
< gravity root smoke
Definition: particle.h:157
< sphere
Definition: particle.h:122
< drag 20
Definition: particle.h:145
< drag 5
Definition: particle.h:130
< drag 19
Definition: particle.h:144
void DrawParticle(int sheet)
Draws all the particles.
Definition: particle.cpp:3527
< drag 13
Definition: particle.h:138
< black smoke
Definition: particle.h:84
< reflection
Definition: particle.h:66
< red selection
Definition: particle.h:74
< gas from the reactor
Definition: particle.h:69
< virus 3
Definition: particle.h:92
void FlushParticle()
Removes all particles.
Definition: particle.cpp:151
< fog 4
Definition: particle.h:168
ParticleType
Definition: particle.h:60
Sound plugin interface.
bool CheckChannel(int &channel)
Check a channel number.
Definition: particle.cpp:677
Main graphics engine - CEngine class.
< drag 10
Definition: particle.h:135
< drag 1
Definition: particle.h:126
< sphere
Definition: particle.h:121
< steam
Definition: particle.h:89
< dust after fall
Definition: particle.h:68
< trace
Definition: particle.h:188
< foo says blah
Definition: particle.h:111
< reactor of tot
Definition: particle.h:109
int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0)
Creates a new particle being a part of object.
Definition: particle.cpp:499
< shows a place
Definition: particle.h:153
< bullet destroyed by shield
Definition: particle.h:124
< trace
Definition: particle.h:184
< trace
Definition: particle.h:186
< black smoke
Definition: particle.h:83
< trace
Definition: particle.h:197
< virus 2
Definition: particle.h:91
< red reflection
Definition: particle.h:147
< bullet 4 (orgaball)
Definition: particle.h:78
void DrawParticleTriangle(int i)
Draws a triangular particle.
Definition: particle.cpp:2761
< drop of water
Definition: particle.h:178
bool GetPosition(int channel, Math::Vector &pos)
Returns the position of the particle.
Definition: particle.cpp:798
< splash
Definition: particle.h:159
< trace
Definition: particle.h:195
< trace
Definition: particle.h:193
< drop
Definition: particle.h:163
< human blood
Definition: particle.h:87
void DrawParticleCylinder(int i)
Draws a cylindrical particle.
Definition: particle.cpp:3301
< drag 9
Definition: particle.h:134
< toto says yes
Definition: particle.h:112
int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, float duration=1.0f, int sheet=0)
Creates a new linear particle (radius)
Definition: particle.cpp:547
< blood laying
Definition: particle.h:88
void DrawParticleFlat(int i)
Draw a particle flat (horizontal)
Definition: particle.cpp:2886
< trace
Definition: particle.h:189
< splash
Definition: particle.h:161
< the engine exhaust gas
Definition: particle.h:65
< black smoke
Definition: particle.h:85
< lightning recharging battery
Definition: particle.h:67
< shows if the ground is flat
Definition: particle.h:155
< brilliance 2 (yellow)
Definition: particle.h:149
< fog 8
Definition: particle.h:172
< virus 6
Definition: particle.h:95
< ray 4
Definition: particle.h:103
void Play(Sound sound, Math::Vector pos, float amplitude)
Sounded one.
Definition: particle.cpp:3822
< drag 6
Definition: particle.h:131
< inflamed tail
Definition: particle.h:80
< brilliance 1 (orange)
Definition: particle.h:148
bool WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur)
Writes a file containing all the tire tracks.
Definition: particle.cpp:3908
< shows the limits 1
Definition: particle.h:174
< virus 8
Definition: particle.h:97
< fog 6
Definition: particle.h:170
< reflection on button
Definition: particle.h:152
A triangle drawn by the graphics engine.
Definition: engine.h:146
void TrackDraw(int i, ParticleType type)
Draws a drag.
Definition: particle.cpp:2587
< information sphere (emit)
Definition: particle.h:118
< trace
Definition: particle.h:190
< yellow selection
Definition: particle.h:73
< drag 17
Definition: particle.h:142
< trace
Definition: particle.h:192
< drag 11
Definition: particle.h:136
< virus 9
Definition: particle.h:98
< organic ball mother
Definition: particle.h:81
bool TrackMove(int i, Math::Vector pos, float progress)
Moves a drag; returns true if the drag is finished.
Definition: particle.cpp:2546
< shows the limits 2
Definition: particle.h:175
Definition: robotmain.h:172
< drag 12
Definition: particle.h:137
Particle engine.
Definition: particle.h:268
< blue ball recycler
Definition: particle.h:156
< shows the limits 4
Definition: particle.h:177
void DrawParticleNorm(int i)
Draw a normal particle.
Definition: particle.cpp:2788
< fog 7
Definition: particle.h:171
< drag 15
Definition: particle.h:140
< information sphere (receive)
Definition: particle.h:120
< flame
Definition: particle.h:104
< trace
Definition: particle.h:182
Definition: particle.h:254
< drag 3
Definition: particle.h:128
void DeleteRank(int rank)
Removes a particle of given rank.
Definition: particle.cpp:700
< trace
Definition: particle.h:194
< explosion sphere
Definition: particle.h:114
< trace
Definition: particle.h:198
< gases of spaceship
Definition: particle.h:181
< blue reflection
Definition: particle.h:146
< technology explosion
Definition: particle.h:63
< ray 1 (turn)
Definition: particle.h:100
< ray 3
Definition: particle.h:102
2D point
Definition: point.h:49
< drag 14
Definition: particle.h:139
void SetObjectLink(int channel, CObject *object)
Specifies the object to which the particle is bound.
Definition: particle.cpp:737
int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0)
Creates a new particle.
Definition: particle.cpp:212
< drag 8
Definition: particle.h:133
< triangular fragment
Definition: particle.h:79
Sound
Sound enum representing sound file.
Definition: sound.h:44
void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, const Math::Vector &p4, ParticleType type)
Creates a tire mark.
Definition: particle.cpp:638
< drag 16
Definition: particle.h:141
void SetObjectFather(int channel, CObject *object)
Specifies the parent object that created the particle.
Definition: particle.cpp:743
< toto says no
Definition: particle.h:110
< fireball grows
Definition: particle.h:71
< splash
Definition: particle.h:160
< circles in the water
Definition: particle.h:106
Terrain loader/generator and manager.
Definition: terrain.h:222
void DrawParticleFog(int i)
Draw a particle to a flat sheet of fog.
Definition: particle.cpp:2949
void SetDevice(CDevice *device)
Sets the device to use.
Definition: particle.cpp:146
Definition: particle.h:240
< virus 7
Definition: particle.h:96
< black smoke
Definition: particle.h:86
< drag 4
Definition: particle.h:129
Namespace for (new) graphics code.
Definition: app.h:49
< fog 1
Definition: particle.h:165
< ball explosion 1
Definition: particle.h:179
The graphics engine.
Definition: engine.h:684
< fog 2
Definition: particle.h:166
< botanical sphere (gravity root)
Definition: particle.h:119
< splash
Definition: particle.h:162
< trace
Definition: particle.h:183
< shock wave
Definition: particle.h:154
< waste from the reactor
Definition: particle.h:108
< virus 5
Definition: particle.h:94
< virus 4
Definition: particle.h:93
< fireball shrinks
Definition: particle.h:70
void DrawParticleRay(int i)
Draw a particle in the form of radius.
Definition: particle.cpp:3036
< bubble
Definition: particle.h:105
Water manager/renderer.
Definition: water.h:118
< virus 1
Definition: particle.h:90
< fog 5
Definition: particle.h:169
< fog 9
Definition: particle.h:173
< energy sphere
Definition: particle.h:115
< trace
Definition: particle.h:199
< trace
Definition: particle.h:187
< ejection from the reactor
Definition: particle.h:107
3D (3x1) vector
Definition: vector.h:52
void SetFrameUpdate(int sheet, bool update)
Indicates whether a sheet is updated or not.
Definition: particle.cpp:805
void DeleteParticle(ParticleType type)
Removes all particles of a given type.
Definition: particle.cpp:712
Color GetFogColor(Math::Vector pos)
Returns the color if you're in the fog or black if you're not.
Definition: particle.cpp:3830
< fog 0
Definition: particle.h:164
< trace
Definition: particle.h:196
int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f)
Creates a particle with a trail.
Definition: particle.cpp:606
< organic ball daughter
Definition: particle.h:82
int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle, ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0)
Creates a new triangular particle (debris)
Definition: particle.cpp:394
< object part
Definition: particle.h:125
RGBA color.
Definition: color.h:38
CObject * SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father)
Seeks if an object collided with a ray.
Definition: particle.cpp:3767
< blue ball
Definition: particle.h:72
CObject * SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father)
Seeks if an object collided with a bullet.
Definition: particle.cpp:3636
< drag 7
Definition: particle.h:132
< bullet 3 (spider)
Definition: particle.h:77
< bullet 2 (ant)
Definition: particle.h:76
void FrameParticle(float rTime)
Updates all the particles.
Definition: particle.cpp:810
< trace
Definition: particle.h:185
< shield sphere
Definition: particle.h:117
< shows the limits 3
Definition: particle.h:176
< analysis sphere
Definition: particle.h:116
< reflection crystal
Definition: particle.h:113
< organic explosion
Definition: particle.h:64
< trace
Definition: particle.h:200
< drag 18
Definition: particle.h:143
void DrawParticleSphere(int i)
Draws a spherical particle.
Definition: particle.cpp:3193
< splash
Definition: particle.h:158
< virus 10
Definition: particle.h:99
Definition: object.h:357
< ray 2 (electric arc)
Definition: particle.h:101
< brilliance 3 (red)
Definition: particle.h:150
< brilliance 4 (violet)
Definition: particle.h:151
< a bullet (fireball)
Definition: particle.h:75
Sound plugin interface.
Definition: sound.h:151
< drag 2
Definition: particle.h:127
< fog 3
Definition: particle.h:167
Abstract interface of graphics device.
Definition: device.h:251
< ball explosion 2
Definition: particle.h:180
< trace
Definition: particle.h:191
void DrawParticleWheel(int i)
Draws a tire mark.
Definition: particle.cpp:3387
< sphere
Definition: particle.h:123
Definition: particle.h:209