Cafu Engine
ParticleEngineMS.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 // TODO: REMOVE ALL THE "MATSYS" and "MS" SUFFIXES!
8 #ifndef CAFU_PARTICLE_ENGINE_MATSYS_HPP_INCLUDED
9 #define CAFU_PARTICLE_ENGINE_MATSYS_HPP_INCLUDED
10 
11 #include "Templates/Array.hpp"
12 #include <string>
13 
14 
15 namespace MatSys { class RenderMaterialT; }
16 struct ParticleMST;
17 
18 
19 /// This is a pointer to a function that moves a given particle over time.
20 /// Returns 'true' if the particle is still alive, 'false' otherwise (it will then be removed from the set of alive particles).
21 typedef bool (*ParticleMoveFunctionMST)(ParticleMST* Particle, float Time);
22 
23 
24 /// This structure describes a single particle.
26 {
27  float Origin[3]; ///< Origin of the particle in Cafu world coordinates.
28  float Velocity[3]; ///< Velocity vector of the particle.
29  float Age; ///< Age of the particle, in seconds.
30  unsigned char Color[4]; ///< ?? REMOVE (MatSys respects ambient light color already) ?? The RGBA color with which this particles texture is modulated.
31  float Radius; ///< Billboard radius in world coords.
32  unsigned char Rotation; ///< Rotation angle of the billboard in the "screen plane". A value of 256 corresponds to 360 degrees.
33  // bool AsBillboard; ///< Is this particle drawn as a billboard, or in world coordinates? (In the latter case we also need more data, e.g. a normal.)
34  float StretchY; ///< Length of the Y-axis relative to the X-axis, e.g. for sparks, flashes etc.
35  ArrayT<MatSys::RenderMaterialT*>* AllRMs; ///< The list of all render materials possibly used with this particle.
36  MatSys::RenderMaterialT* RenderMat; ///< The particles RenderMaterial ID.
37  ParticleMoveFunctionMST MoveFunction; ///< Pointer to the function that moves this particle through time.
38  float AuxData[8]; ///< Auxiliary particle data.
39 };
40 
41 
42 /// These are the functions of the particle engine.
43 /// To make it as fast as possible, dynamic memory allocation only takes place during initialization (when registering the textures).
44 /// Later, when huge amounts of particles must be handled, everything takes place in "static" memory.
45 namespace ParticleEngineMS
46 {
47  /// Registers a new particle with the particle engine.
48  void RegisterNewParticle(const ParticleMST& Particle);
49 
50  /// Calls the move function for each particle and then removes dead particles.
51  void MoveParticles(float Time);
52 
53  /// Draws all currently known (alive) particles.
54  void DrawParticles();
55 }
56 
57 
58 /// This class represents a set of (render-)materials.
59 /// The materials in one such set are typically used for implementing an animated particle, e.g. an explosion.
61 {
62  public:
63 
64  ParticleMaterialSetT(const char* SetName, const char* MatNamePattern);
65 
67 
68  ArrayT<MatSys::RenderMaterialT*>& GetRenderMats() { return m_RenderMats; }
69 
70 
71  private:
72 
73  const std::string m_SetName;
75 };
76 
77 #endif
This class represents a surface render material.
Definition: RenderMaterial.hpp:25
float Radius
Billboard radius in world coords.
Definition: ParticleEngineMS.hpp:31
float Age
Age of the particle, in seconds.
Definition: ParticleEngineMS.hpp:29
unsigned char Color[4]
?? REMOVE (MatSys respects ambient light color already) ?? The RGBA color with which this particles t...
Definition: ParticleEngineMS.hpp:30
void DrawParticles()
Draws all currently known (alive) particles.
Definition: ParticleEngineMS.cpp:163
This class represents a set of (render-)materials.
Definition: ParticleEngineMS.hpp:60
MatSys::RenderMaterialT * RenderMat
The particles RenderMaterial ID.
Definition: ParticleEngineMS.hpp:36
ArrayT< MatSys::RenderMaterialT * > * AllRMs
The list of all render materials possibly used with this particle.
Definition: ParticleEngineMS.hpp:35
float Velocity[3]
Velocity vector of the particle.
Definition: ParticleEngineMS.hpp:28
ParticleMoveFunctionMST MoveFunction
Pointer to the function that moves this particle through time.
Definition: ParticleEngineMS.hpp:37
unsigned char Rotation
Rotation angle of the billboard in the "screen plane". A value of 256 corresponds to 360 degrees...
Definition: ParticleEngineMS.hpp:32
void RegisterNewParticle(const ParticleMST &Particle)
Registers a new particle with the particle engine.
Definition: ParticleEngineMS.cpp:74
void MoveParticles(float Time)
Calls the move function for each particle and then removes dead particles.
Definition: ParticleEngineMS.cpp:99
This structure describes a single particle.
Definition: ParticleEngineMS.hpp:25
float Origin[3]
Origin of the particle in Cafu world coordinates.
Definition: ParticleEngineMS.hpp:27
float StretchY
Length of the Y-axis relative to the X-axis, e.g. for sparks, flashes etc.
Definition: ParticleEngineMS.hpp:34
float AuxData[8]
Auxiliary particle data.
Definition: ParticleEngineMS.hpp:38