My Project
particle.h
1 #pragma once
2 
3 #include "animated.h"
4 #include "util/ParaMemPool.h"
5 #include "FileManager.h"
6 #include <list>
7 #include <map>
8 
9 
10 namespace ParaEngine
11 {
12 class ParticleSystem;
13 class RibbonEmitter;
14 class Bone;
15 class CParaXModel;
16 struct TextureEntity;
17 
18 struct Particle {
19  Vector3 pos, speed, down, origin;
20  //Vector3 tpos;
21  float size, life, maxlife, random_force, trail_length;
22  float rotation, rotSpeed;
23  int tile;
24  Vector4 color;
25 };
26 
27 typedef FixedSizedAllocator<Particle> DL_Allocator_ParticleList;
28 typedef std::list<Particle, DL_Allocator_ParticleList > ParticleListType;
33 {
34  ParticleListType particles;
37  bool m_bUseAbsCord:1;
41  bool m_bUpdated:1;
43  bool m_bRender:1;
45  int m_anim;
47  int m_time;
49  float m_rem;
51  void * m_pSceneState;
52 public:
53  ParticleList():m_pSceneState(NULL),m_bUseAbsCord(true), m_vLastRenderOrigin(0,0,0),m_bUpdated(false),m_anim(0), m_time(0),m_rem(0){};
54 };
55 
57 protected:
58  ParticleSystem *sys;
59 public:
60  enum{
61  TYPE_NONE=0,
62  TYPE_PLANE_PARTICLE_EMITTER=1,
63  TYPE_SPHERE_PARTICLE_EMITTER=2,
64  };
65  ParticleEmitter(ParticleSystem *sys): sys(sys) {}
66  virtual ~ParticleEmitter() {};
67  virtual Particle newParticle(int anim, int time) = 0;
68  virtual int GetEmitterType()=0;
69 };
70 
72 public:
74  virtual ~PlaneParticleEmitter() {};
75  Particle newParticle(int anim, int time);
76  virtual int GetEmitterType(){return (int)TYPE_PLANE_PARTICLE_EMITTER;};
77 };
78 
80 public:
82  virtual ~SphereParticleEmitter() {};
83  Particle newParticle(int anim, int time);
84  virtual int GetEmitterType(){return (int)TYPE_SPHERE_PARTICLE_EMITTER;};
85 };
86 
87 struct TexCoordSet {
88  Vector2 tc[4];
89 };
100 {
101  friend class PlaneParticleEmitter;
102  friend class SphereParticleEmitter;
103 public:
118 
125 
126 
130  float slowdown;
131 
132  // this parameter is only used for sphere emitter type It is the angle between the emitting direction and downward direction in range [-Pi/2, Pi/2]. Default value is 0, which is the downward direction like the plane emitter.
133  float rotation;
134 
141  float mid;
142  Vector4 colors[3];
143  float sizes[3];
144 
147 
150  int blend;
152  int order;
156  int type;
157 
159  bool billboard;
160 
162  // a new particle will use a random image at one of the rows*cols regions in the texture accociated with the particle system.
163  // if rows=1, cols=1, the entire texture is used.
165  int rows, cols;
166  // this is automatically generated from rows, cols
167  std::vector<TexCoordSet> tiles;
168  // the texture associated with this particle system.
169  int32 m_texture_index;
170 
172  // the bone to which the particle system is attached.
173  Bone *parent;
174 
176  // the emitter object
177  ParticleEmitter *emitter;
178 
179 public:
180  // the ParaX model in which the particle system is defined (contained).
181  CParaXModel *model;
182 
184  float tofs;
185 
189  map <void*, ParticleList*> m_instances;
190 
191  bool rotate2SpeedDirection;
192 public:
193  ParticleSystem();
194  ~ParticleSystem();
195 
196  // update existing particles and spawn new ones
197  void update(SceneState * pSceneState, float dt);
198 
200  void ClearAllInstances();
201 
203  DeviceTexturePtr_type GetDeviceTexture();
204  TextureEntity* GetTexture();
205 
214  bool AnimateExistingParticles(float dt, const Vector3& vOffset, ParticleList* instancePS);
215 
219  ParticleList* GetCurrentInstance(SceneState * pSceneState, bool bForceCreate=true);
220 
222  bool DeleteInstance(void * owner);
223 
225  void setup(SceneState * pSceneState, int anim, int time);
227  void draw(SceneState * pSceneState);
229  void drawInstance(ParticleList* instancePS);
231  void drawAllAbsInstances();
232 
234  CParaXModel * GetParent() {return model;}
235 
236  // only called by drawInstance();
237  void DrawInstanceSub(ParticleList* instancePS);
241  void SetTextureRowsCols(int nRows, int nCols);
242 };
243 
245  Vector3 pos, up, back;
246  float len,len0;
247 };
248 
254 {
255 public:
256  Animated<Vector3> color;
257  AnimatedShort opacity;
258  Animated<float> above, below;
259 
260  Bone *parent;
261  float f1, f2;
262 
263  Vector3 pos;
264 
265  int manim, mtime;
266  float length, seglen;
267  int numsegs;
268 
269  Vector3 tpos;
270  Vector4 tcolor;
271  float tabove, tbelow;
274  bool m_bUseAbsCord:1;
275 
276  int32 m_texture_index;
277 
278  std::list<RibbonSegment> segs;
279 
280 public:
281  CParaXModel *model;
282  RibbonEmitter() :m_bUseAbsCord(true), m_texture_index(0){};
283 
284  void setup(SceneState * pSceneState, int anim, int time);
285  void draw(SceneState * pSceneState);
286 
287 
289  DeviceTexturePtr_type GetDeviceTexture();
290  TextureEntity* GetTexture();
291 };
292 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
Vector3 m_vLastRenderOrigin
the last render origin when the update() function is called.
Definition: particle.h:39
map< void *, ParticleList * > m_instances
instances of the particle systems.
Definition: particle.h:189
int blend
how the texture blending is applied to each particle.
Definition: particle.h:150
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
int m_time
current frame
Definition: particle.h:47
4-dimensional homogeneous vector.
Definition: ParaVector4.h:10
bool billboard
whether using billboard when during the particles. In most cases, this is true, because particles are...
Definition: particle.h:159
this is another kind of particle system.
Definition: particle.h:253
Animated< float > speed
initial speed, the initial speed magnitude of a particle is V(0) = speed + variation * rand(-1...
Definition: particle.h:105
Definition: particle.h:56
different physics engine has different winding order.
Definition: EventBinding.h:32
float m_rem
remaining time to spawn new particles
Definition: particle.h:49
Animated< float > lifespan
maxlife of a newly born particle in seconds
Definition: particle.h:111
a single animated bone, it contains both the bone instance data and all animation data of the bone...
Definition: ParaXBone.h:15
Definition: particle.h:71
int order
the triangle winding order of the quad: whether it is CCW(-1) or CW(0). It does not matter if particl...
Definition: particle.h:152
int m_anim
current animation
Definition: particle.h:45
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
it represents the instance of the particle system.
Definition: particle.h:32
Definition: particle.h:244
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
Animated< float > variation
initial speed variation, the initial speed magnitude of a particle is V(0) = speed + variation * rand...
Definition: particle.h:107
The particle class keeps a list of all of its instances.A particle system instance is always associat...
Definition: particle.h:99
CParaXModel * GetParent()
get the parent model.
Definition: particle.h:234
Animated< float > areaw
the half width of the emitter plane
Definition: particle.h:117
Animated< float > spread
RESERVED: this parameter is reserved for other emitter types.
Definition: particle.h:120
Definition: particle.h:87
float tofs
this is just a rand seed for this particle system.
Definition: particle.h:184
float slowdown
it controls how fast the speed magnitude of a particle dwindles as its life is approaching the end...
Definition: particle.h:130
float mid
the color[0] and sizes[0] is the color and size of a particle at its birth the color[1] and sizes[1] ...
Definition: particle.h:141
Animated< float > lat
RESERVED: this parameter is reserved for other emitter types.
Definition: particle.h:122
Animated< float > areal
the half length of the emitter plane
Definition: particle.h:115
Animated< float > grav2
RESERVED: this parameter is reserved for other emitter types.
Definition: particle.h:124
Definition: particle.h:18
ParaX model is the model file for character animation, etc in the game world.
Definition: ParaXModel.h:30
Animated< float > gravity
particle acceleration magnitude along their current directions, shared by all existing particles at a...
Definition: particle.h:109
int type
this is 0,1,2.
Definition: particle.h:156
void * m_pSceneState
to which scene state this particle instance is associated.
Definition: particle.h:51
Animated< float > rate
how many particles to spawn per second.
Definition: particle.h:113
Vector3 pos
all particles are offset by this value at its birth. this is usually V(0,0,0).
Definition: particle.h:146
Definition: particle.h:79