aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp380
1 files changed, 190 insertions, 190 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp
index 74d5af1..0c95e8b 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CParticleMeshEmitter.cpp
@@ -1,190 +1,190 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "IrrCompileConfig.h" 5#include "IrrCompileConfig.h"
6#include "CParticleMeshEmitter.h" 6#include "CParticleMeshEmitter.h"
7#include "os.h" 7#include "os.h"
8 8
9namespace irr 9namespace irr
10{ 10{
11namespace scene 11namespace scene
12{ 12{
13 13
14//! constructor 14//! constructor
15CParticleMeshEmitter::CParticleMeshEmitter( 15CParticleMeshEmitter::CParticleMeshEmitter(
16 IMesh* mesh, bool useNormalDirection, 16 IMesh* mesh, bool useNormalDirection,
17 const core::vector3df& direction, f32 normalDirectionModifier, 17 const core::vector3df& direction, f32 normalDirectionModifier,
18 s32 mbNumber, bool everyMeshVertex, 18 s32 mbNumber, bool everyMeshVertex,
19 u32 minParticlesPerSecond, u32 maxParticlesPerSecond, 19 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
20 const video::SColor& minStartColor, const video::SColor& maxStartColor, 20 const video::SColor& minStartColor, const video::SColor& maxStartColor,
21 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees, 21 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
22 const core::dimension2df& minStartSize, 22 const core::dimension2df& minStartSize,
23 const core::dimension2df& maxStartSize ) 23 const core::dimension2df& maxStartSize )
24 : Mesh(0), TotalVertices(0), MBCount(0), MBNumber(mbNumber), 24 : Mesh(0), TotalVertices(0), MBCount(0), MBNumber(mbNumber),
25 NormalDirectionModifier(normalDirectionModifier), Direction(direction), 25 NormalDirectionModifier(normalDirectionModifier), Direction(direction),
26 MaxStartSize(maxStartSize), MinStartSize(minStartSize), 26 MaxStartSize(maxStartSize), MinStartSize(minStartSize),
27 MinParticlesPerSecond(minParticlesPerSecond), MaxParticlesPerSecond(maxParticlesPerSecond), 27 MinParticlesPerSecond(minParticlesPerSecond), MaxParticlesPerSecond(maxParticlesPerSecond),
28 MinStartColor(minStartColor), MaxStartColor(maxStartColor), 28 MinStartColor(minStartColor), MaxStartColor(maxStartColor),
29 MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax), 29 MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax),
30 Time(0), Emitted(0), MaxAngleDegrees(maxAngleDegrees), 30 Time(0), Emitted(0), MaxAngleDegrees(maxAngleDegrees),
31 EveryMeshVertex(everyMeshVertex), UseNormalDirection(useNormalDirection) 31 EveryMeshVertex(everyMeshVertex), UseNormalDirection(useNormalDirection)
32{ 32{
33 #ifdef _DEBUG 33 #ifdef _DEBUG
34 setDebugName("CParticleMeshEmitter"); 34 setDebugName("CParticleMeshEmitter");
35 #endif 35 #endif
36 setMesh(mesh); 36 setMesh(mesh);
37} 37}
38 38
39 39
40//! Prepares an array with new particles to emitt into the system 40//! Prepares an array with new particles to emitt into the system
41//! and returns how much new particles there are. 41//! and returns how much new particles there are.
42s32 CParticleMeshEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray) 42s32 CParticleMeshEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray)
43{ 43{
44 Time += timeSinceLastCall; 44 Time += timeSinceLastCall;
45 45
46 const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond); 46 const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond);
47 const f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond; 47 const f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond;
48 const f32 everyWhatMillisecond = 1000.0f / perSecond; 48 const f32 everyWhatMillisecond = 1000.0f / perSecond;
49 49
50 if(Time > everyWhatMillisecond) 50 if(Time > everyWhatMillisecond)
51 { 51 {
52 Particles.set_used(0); 52 Particles.set_used(0);
53 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f); 53 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f);
54 Time = 0; 54 Time = 0;
55 SParticle p; 55 SParticle p;
56 56
57 if(amount > MaxParticlesPerSecond * 2) 57 if(amount > MaxParticlesPerSecond * 2)
58 amount = MaxParticlesPerSecond * 2; 58 amount = MaxParticlesPerSecond * 2;
59 59
60 for(u32 i=0; i<amount; ++i) 60 for(u32 i=0; i<amount; ++i)
61 { 61 {
62 if( EveryMeshVertex ) 62 if( EveryMeshVertex )
63 { 63 {
64 for( u32 j=0; j<Mesh->getMeshBufferCount(); ++j ) 64 for( u32 j=0; j<Mesh->getMeshBufferCount(); ++j )
65 { 65 {
66 for( u32 k=0; k<Mesh->getMeshBuffer(j)->getVertexCount(); ++k ) 66 for( u32 k=0; k<Mesh->getMeshBuffer(j)->getVertexCount(); ++k )
67 { 67 {
68 p.pos = Mesh->getMeshBuffer(j)->getPosition(k); 68 p.pos = Mesh->getMeshBuffer(j)->getPosition(k);
69 if( UseNormalDirection ) 69 if( UseNormalDirection )
70 p.vector = Mesh->getMeshBuffer(j)->getNormal(k) / 70 p.vector = Mesh->getMeshBuffer(j)->getNormal(k) /
71 NormalDirectionModifier; 71 NormalDirectionModifier;
72 else 72 else
73 p.vector = Direction; 73 p.vector = Direction;
74 74
75 p.startTime = now; 75 p.startTime = now;
76 76
77 if( MaxAngleDegrees ) 77 if( MaxAngleDegrees )
78 { 78 {
79 core::vector3df tgt = p.vector; 79 core::vector3df tgt = p.vector;
80 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees); 80 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees);
81 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees); 81 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees);
82 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees); 82 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees);
83 p.vector = tgt; 83 p.vector = tgt;
84 } 84 }
85 85
86 p.endTime = now + MinLifeTime; 86 p.endTime = now + MinLifeTime;
87 if (MaxLifeTime != MinLifeTime) 87 if (MaxLifeTime != MinLifeTime)
88 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime); 88 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime);
89 89
90 if (MinStartColor==MaxStartColor) 90 if (MinStartColor==MaxStartColor)
91 p.color=MinStartColor; 91 p.color=MinStartColor;
92 else 92 else
93 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand()); 93 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand());
94 94
95 p.startColor = p.color; 95 p.startColor = p.color;
96 p.startVector = p.vector; 96 p.startVector = p.vector;
97 97
98 if (MinStartSize==MaxStartSize) 98 if (MinStartSize==MaxStartSize)
99 p.startSize = MinStartSize; 99 p.startSize = MinStartSize;
100 else 100 else
101 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand()); 101 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand());
102 p.size = p.startSize; 102 p.size = p.startSize;
103 103
104 Particles.push_back(p); 104 Particles.push_back(p);
105 } 105 }
106 } 106 }
107 } 107 }
108 else 108 else
109 { 109 {
110 const s32 randomMB = (MBNumber < 0) ? (os::Randomizer::rand() % MBCount) : MBNumber; 110 const s32 randomMB = (MBNumber < 0) ? (os::Randomizer::rand() % MBCount) : MBNumber;
111 111
112 u32 vertexNumber = Mesh->getMeshBuffer(randomMB)->getVertexCount(); 112 u32 vertexNumber = Mesh->getMeshBuffer(randomMB)->getVertexCount();
113 if (!vertexNumber) 113 if (!vertexNumber)
114 continue; 114 continue;
115 vertexNumber = os::Randomizer::rand() % vertexNumber; 115 vertexNumber = os::Randomizer::rand() % vertexNumber;
116 116
117 p.pos = Mesh->getMeshBuffer(randomMB)->getPosition(vertexNumber); 117 p.pos = Mesh->getMeshBuffer(randomMB)->getPosition(vertexNumber);
118 if( UseNormalDirection ) 118 if( UseNormalDirection )
119 p.vector = Mesh->getMeshBuffer(randomMB)->getNormal(vertexNumber) / 119 p.vector = Mesh->getMeshBuffer(randomMB)->getNormal(vertexNumber) /
120 NormalDirectionModifier; 120 NormalDirectionModifier;
121 else 121 else
122 p.vector = Direction; 122 p.vector = Direction;
123 123
124 p.startTime = now; 124 p.startTime = now;
125 125
126 if( MaxAngleDegrees ) 126 if( MaxAngleDegrees )
127 { 127 {
128 core::vector3df tgt = Direction; 128 core::vector3df tgt = Direction;
129 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees); 129 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees);
130 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees); 130 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees);
131 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees); 131 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees);
132 p.vector = tgt; 132 p.vector = tgt;
133 } 133 }
134 134
135 p.endTime = now + MinLifeTime; 135 p.endTime = now + MinLifeTime;
136 if (MaxLifeTime != MinLifeTime) 136 if (MaxLifeTime != MinLifeTime)
137 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime); 137 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime);
138 138
139 if (MinStartColor==MaxStartColor) 139 if (MinStartColor==MaxStartColor)
140 p.color=MinStartColor; 140 p.color=MinStartColor;
141 else 141 else
142 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand()); 142 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand());
143 143
144 p.startColor = p.color; 144 p.startColor = p.color;
145 p.startVector = p.vector; 145 p.startVector = p.vector;
146 146
147 if (MinStartSize==MaxStartSize) 147 if (MinStartSize==MaxStartSize)
148 p.startSize = MinStartSize; 148 p.startSize = MinStartSize;
149 else 149 else
150 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand()); 150 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand());
151 p.size = p.startSize; 151 p.size = p.startSize;
152 152
153 Particles.push_back(p); 153 Particles.push_back(p);
154 } 154 }
155 } 155 }
156 156
157 outArray = Particles.pointer(); 157 outArray = Particles.pointer();
158 158
159 return Particles.size(); 159 return Particles.size();
160 } 160 }
161 161
162 return 0; 162 return 0;
163} 163}
164 164
165 165
166//! Set Mesh to emit particles from 166//! Set Mesh to emit particles from
167void CParticleMeshEmitter::setMesh(IMesh* mesh) 167void CParticleMeshEmitter::setMesh(IMesh* mesh)
168{ 168{
169 Mesh = mesh; 169 Mesh = mesh;
170 170
171 TotalVertices = 0; 171 TotalVertices = 0;
172 MBCount = 0; 172 MBCount = 0;
173 VertexPerMeshBufferList.clear(); 173 VertexPerMeshBufferList.clear();
174 174
175 if ( !Mesh ) 175 if ( !Mesh )
176 return; 176 return;
177 177
178 MBCount = Mesh->getMeshBufferCount(); 178 MBCount = Mesh->getMeshBufferCount();
179 VertexPerMeshBufferList.reallocate(MBCount); 179 VertexPerMeshBufferList.reallocate(MBCount);
180 for( u32 i = 0; i < MBCount; ++i ) 180 for( u32 i = 0; i < MBCount; ++i )
181 { 181 {
182 VertexPerMeshBufferList.push_back( Mesh->getMeshBuffer(i)->getVertexCount() ); 182 VertexPerMeshBufferList.push_back( Mesh->getMeshBuffer(i)->getVertexCount() );
183 TotalVertices += Mesh->getMeshBuffer(i)->getVertexCount(); 183 TotalVertices += Mesh->getMeshBuffer(i)->getVertexCount();
184 } 184 }
185} 185}
186 186
187 187
188} // end namespace scene 188} // end namespace scene
189} // end namespace irr 189} // end namespace irr
190 190