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