1 // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 // This file is part of the "Irrlicht Engine". 3 // For conditions of distribution and use, see copyright notice in irrlicht.h 4 5 #ifndef __C_PARTICLE_SYSTEM_SCENE_NODE_H_INCLUDED__ 6 #define __C_PARTICLE_SYSTEM_SCENE_NODE_H_INCLUDED__ 7 8 #include "IParticleSystemSceneNode.h" 9 #include "irrArray.h" 10 #include "irrList.h" 11 #include "SMeshBuffer.h" 12 13 namespace irr 14 { 15 namespace scene 16 { 17 18 //! A particle system scene node. 19 /** A scene node controlling a particle system. The behavior of the particles 20 can be controlled by setting the right particle emitters and affectors. 21 */ 22 class CParticleSystemSceneNode : public IParticleSystemSceneNode 23 { 24 public: 25 26 //! constructor 27 CParticleSystemSceneNode(bool createDefaultEmitter, 28 ISceneNode* parent, ISceneManager* mgr, s32 id, 29 const core::vector3df& position, 30 const core::vector3df& rotation, 31 const core::vector3df& scale); 32 33 //! destructor 34 virtual ~CParticleSystemSceneNode(); 35 36 //! Gets the particle emitter, which creates the particles. 37 virtual IParticleEmitter* getEmitter(); 38 39 //! Sets the particle emitter, which creates the particles. 40 virtual void setEmitter(IParticleEmitter* emitter); 41 42 //! Adds new particle affector to the particle system. 43 virtual void addAffector(IParticleAffector* affector); 44 45 //! Get a list of all particle affectors. 46 virtual const core::list<IParticleAffector*>& getAffectors() const; 47 48 //! Removes all particle affectors in the particle system. 49 virtual void removeAllAffectors(); 50 51 //! Returns the material based on the zero based index i. 52 virtual video::SMaterial& getMaterial(u32 i); 53 54 //! Returns amount of materials used by this scene node. 55 virtual u32 getMaterialCount() const; 56 57 //! pre render event 58 virtual void OnRegisterSceneNode(); 59 60 //! render 61 virtual void render(); 62 63 //! Draw billboard particle 64 void drawBillboardParticle( 65 const irr::s32 &idx, 66 const scene::SParticle &particle, 67 const core::vector3df &view, 68 const irr::core::matrix4 &m); 69 70 //! returns the axis aligned bounding box of this node 71 virtual const core::aabbox3d<f32>& getBoundingBox() const; 72 73 //! Creates a particle emitter for an animated mesh scene node 74 virtual IParticleAnimatedMeshSceneNodeEmitter* createAnimatedMeshSceneNodeEmitter( 75 scene::IAnimatedMeshSceneNode* node, bool useNormalDirection = true, 76 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 77 f32 normalDirectionModifier = 100.0f, s32 mbNumber = -1, 78 bool everyMeshVertex = false, u32 minParticlesPerSecond = 5, 79 u32 maxParticlesPerSecond = 10, 80 const video::SColor& minStartColor = video::SColor(255,0,0,0), 81 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 82 u32 lifeTimeMin = 2000, u32 lifeTimeMax = 4000, 83 s32 maxAngleDegrees = 0, 84 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 85 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 86 87 //! Creates a box particle emitter. 88 virtual IParticleBoxEmitter* createBoxEmitter( 89 const core::aabbox3df& box = core::aabbox3d<f32>(-10,0,-10,5,30,10), 90 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 91 u32 minParticlesPerSecond = 5, 92 u32 maxParticlesPerSecond = 10, 93 const video::SColor& minStartColor = video::SColor(255,0,0,0), 94 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 95 u32 lifeTimeMin=2000, u32 lifeTimeMax=4000, 96 s32 maxAngleDegrees=0, 97 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 98 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 99 100 //! Creates a particle emitter for emitting from a cylinder 101 virtual IParticleCylinderEmitter* createCylinderEmitter( 102 const core::vector3df& center, f32 radius, 103 const core::vector3df& normal, f32 length, 104 bool outlineOnly = false, const core::vector3df& direction = core::vector3df(0.0f,0.5f,0.0f), 105 u32 minParticlesPerSecond = 5, u32 maxParticlesPersSecond = 10, 106 const video::SColor& minStartColor = video::SColor(255,0,0,0), 107 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 108 u32 lifeTimeMin = 2000, u32 lifeTimeMax = 4000, 109 s32 maxAngleDegrees = 0, 110 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 111 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 112 113 //! Creates a mesh particle emitter. 114 virtual IParticleMeshEmitter* createMeshEmitter( 115 scene::IMesh* mesh, bool useNormalDirection = true, 116 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 117 f32 normalDirectionModifier = 100.0f, s32 mbNumber = -1, 118 bool everyMeshVertex = false, 119 u32 minParticlesPerSecond = 5, 120 u32 maxParticlesPerSecond = 10, 121 const video::SColor& minStartColor = video::SColor(255,0,0,0), 122 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 123 u32 lifeTimeMin = 2000, u32 lifeTimeMax = 4000, 124 s32 maxAngleDegrees = 0, 125 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 126 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 127 128 //! Creates a point particle emitter. 129 virtual IParticlePointEmitter* createPointEmitter( 130 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 131 u32 minParticlesPerSecond = 5, 132 u32 maxParticlesPerSecond = 10, 133 const video::SColor& minStartColor = video::SColor(255,0,0,0), 134 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 135 u32 lifeTimeMin=2000, u32 lifeTimeMax=4000, 136 s32 maxAngleDegrees=0, 137 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 138 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 139 140 //! Creates a ring particle emitter. 141 virtual IParticleRingEmitter* createRingEmitter( 142 const core::vector3df& center, f32 radius, f32 ringThickness, 143 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 144 u32 minParticlesPerSecond = 5, 145 u32 maxParticlesPerSecond = 10, 146 const video::SColor& minStartColor = video::SColor(255,0,0,0), 147 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 148 u32 lifeTimeMin=2000, u32 lifeTimeMax=4000, 149 s32 maxAngleDegrees=0, 150 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 151 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 152 153 //! Creates a sphere particle emitter. 154 virtual IParticleSphereEmitter* createSphereEmitter( 155 const core::vector3df& center, f32 radius, 156 const core::vector3df& direction = core::vector3df(0.0f,0.03f,0.0f), 157 u32 minParticlesPerSecond = 5, 158 u32 maxParticlesPerSecond = 10, 159 const video::SColor& minStartColor = video::SColor(255,0,0,0), 160 const video::SColor& maxStartColor = video::SColor(255,255,255,255), 161 u32 lifeTimeMin=2000, u32 lifeTimeMax=4000, 162 s32 maxAngleDegrees=0, 163 const core::dimension2df& minStartSize = core::dimension2df(5.0f,5.0f), 164 const core::dimension2df& maxStartSize = core::dimension2df(5.0f,5.0f) ); 165 166 //! Creates a point attraction affector. This affector modifies the positions of the 167 //! particles and attracts them to a specified point at a specified speed per second. 168 virtual IParticleAttractionAffector* createAttractionAffector( 169 const core::vector3df& point, f32 speed = 1.0f, bool attract = true, 170 bool affectX = true, bool affectY = true, bool affectZ = true); 171 172 //! Creates a scale particle affector. 173 virtual IParticleAffector* createScaleParticleAffector(const core::dimension2df& scaleTo = core::dimension2df(1.0f, 1.0f)); 174 175 //! Creates a fade out particle affector. 176 virtual IParticleFadeOutAffector* createFadeOutParticleAffector( 177 const video::SColor& targetColor = video::SColor(0,0,0,0), 178 u32 timeNeededToFadeOut = 1000); 179 180 //! Creates a gravity affector. 181 virtual IParticleGravityAffector* createGravityAffector( 182 const core::vector3df& gravity = core::vector3df(0.0f,-0.03f,0.0f), 183 u32 timeForceLost = 1000); 184 185 //! Creates a rotation affector. This affector rotates the particles 186 //! around a specified pivot point. The speed is in Degrees per second. 187 virtual IParticleRotationAffector* createRotationAffector( 188 const core::vector3df& speed = core::vector3df(5.0f,5.0f,5.0f), 189 const core::vector3df& pivotPoint = core::vector3df(0.0f,0.0f,0.0f) ); 190 191 //! Sets the size of all particles. 192 virtual void setParticleSize( 193 const core::dimension2d<f32> &size = core::dimension2d<f32>(5.0f, 5.0f)); 194 195 //! Sets if the particles should be global. If they are, the particles are affected by 196 //! the movement of the particle system scene node too, otherwise they completely 197 //! ignore it. Default is true. 198 virtual void setParticlesAreGlobal(bool global=true); 199 200 //! Remove all currently visible particles 201 virtual void clearParticles(); 202 203 //! Do manually update the particles. 204 //! This should only be called when you want to render the node outside the scenegraph, 205 //! as the node will care about this otherwise automatically. 206 virtual void doParticleSystem(u32 time); 207 208 //! Writes attributes of the scene node. 209 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const; 210 211 //! Reads attributes of the scene node. 212 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0); 213 214 //! Returns type of the scene node getType()215 virtual ESCENE_NODE_TYPE getType() const { return ESNT_PARTICLE_SYSTEM; } 216 217 protected: 218 219 void reallocateBuffers(); 220 221 core::list<IParticleAffector*> AffectorList; 222 IParticleEmitter* Emitter; 223 core::array<SParticle> Particles; 224 core::dimension2d<f32> ParticleSize; 225 u32 LastEmitTime; 226 s32 MaxParticles; 227 228 SMeshBuffer* Buffer; 229 230 enum E_PARTICLES_PRIMITIVE 231 { 232 EPP_POINT=0, 233 EPP_BILLBOARD, 234 EPP_POINTSPRITE 235 }; 236 E_PARTICLES_PRIMITIVE ParticlePrimitive; 237 238 bool ParticlesAreGlobal; 239 }; 240 241 } // end namespace scene 242 } // end namespace irr 243 244 245 #endif 246 247