aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp374
1 files changed, 187 insertions, 187 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp
index a2078f9..3e7eafc 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CParticleCylinderEmitter.cpp
@@ -1,187 +1,187 @@
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 "CParticleCylinderEmitter.h" 5#include "CParticleCylinderEmitter.h"
6#include "os.h" 6#include "os.h"
7#include "IAttributes.h" 7#include "IAttributes.h"
8 8
9namespace irr 9namespace irr
10{ 10{
11namespace scene 11namespace scene
12{ 12{
13 13
14//! constructor 14//! constructor
15CParticleCylinderEmitter::CParticleCylinderEmitter( 15CParticleCylinderEmitter::CParticleCylinderEmitter(
16 const core::vector3df& center, f32 radius, 16 const core::vector3df& center, f32 radius,
17 const core::vector3df& normal, f32 length, 17 const core::vector3df& normal, f32 length,
18 bool outlineOnly, const core::vector3df& direction, 18 bool outlineOnly, const core::vector3df& direction,
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 : Center(center), Normal(normal), Direction(direction), 24 : Center(center), Normal(normal), Direction(direction),
25 MaxStartSize(maxStartSize), MinStartSize(minStartSize), 25 MaxStartSize(maxStartSize), MinStartSize(minStartSize),
26 MinParticlesPerSecond(minParticlesPerSecond), 26 MinParticlesPerSecond(minParticlesPerSecond),
27 MaxParticlesPerSecond(maxParticlesPerSecond), 27 MaxParticlesPerSecond(maxParticlesPerSecond),
28 MinStartColor(minStartColor), MaxStartColor(maxStartColor), 28 MinStartColor(minStartColor), MaxStartColor(maxStartColor),
29 MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax), 29 MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax),
30 Radius(radius), Length(length), Time(0), Emitted(0), 30 Radius(radius), Length(length), Time(0), Emitted(0),
31 MaxAngleDegrees(maxAngleDegrees), OutlineOnly(outlineOnly) 31 MaxAngleDegrees(maxAngleDegrees), OutlineOnly(outlineOnly)
32{ 32{
33 #ifdef _DEBUG 33 #ifdef _DEBUG
34 setDebugName("CParticleCylinderEmitter"); 34 setDebugName("CParticleCylinderEmitter");
35 #endif 35 #endif
36} 36}
37 37
38 38
39//! Prepares an array with new particles to emitt into the system 39//! Prepares an array with new particles to emitt into the system
40//! and returns how much new particles there are. 40//! and returns how much new particles there are.
41s32 CParticleCylinderEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray) 41s32 CParticleCylinderEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray)
42{ 42{
43 Time += timeSinceLastCall; 43 Time += timeSinceLastCall;
44 44
45 const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond); 45 const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond);
46 const f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond; 46 const f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond;
47 const f32 everyWhatMillisecond = 1000.0f / perSecond; 47 const f32 everyWhatMillisecond = 1000.0f / perSecond;
48 48
49 if(Time > everyWhatMillisecond) 49 if(Time > everyWhatMillisecond)
50 { 50 {
51 Particles.set_used(0); 51 Particles.set_used(0);
52 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f); 52 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f);
53 Time = 0; 53 Time = 0;
54 SParticle p; 54 SParticle p;
55 55
56 if(amount > MaxParticlesPerSecond*2) 56 if(amount > MaxParticlesPerSecond*2)
57 amount = MaxParticlesPerSecond * 2; 57 amount = MaxParticlesPerSecond * 2;
58 58
59 for(u32 i=0; i<amount; ++i) 59 for(u32 i=0; i<amount; ++i)
60 { 60 {
61 // Random distance from center if outline only is not true 61 // Random distance from center if outline only is not true
62 const f32 distance = (!OutlineOnly) ? (os::Randomizer::frand() * Radius) : Radius; 62 const f32 distance = (!OutlineOnly) ? (os::Randomizer::frand() * Radius) : Radius;
63 63
64 // Random direction from center 64 // Random direction from center
65 p.pos.set(Center.X + distance, Center.Y, Center.Z + distance); 65 p.pos.set(Center.X + distance, Center.Y, Center.Z + distance);
66 p.pos.rotateXZBy(os::Randomizer::frand() * 360, Center); 66 p.pos.rotateXZBy(os::Randomizer::frand() * 360, Center);
67 67
68 // Random length 68 // Random length
69 const f32 length = os::Randomizer::frand() * Length; 69 const f32 length = os::Randomizer::frand() * Length;
70 70
71 // Random point along the cylinders length 71 // Random point along the cylinders length
72 p.pos += Normal * length; 72 p.pos += Normal * length;
73 73
74 p.startTime = now; 74 p.startTime = now;
75 p.vector = Direction; 75 p.vector = Direction;
76 76
77 if( MaxAngleDegrees ) 77 if( MaxAngleDegrees )
78 { 78 {
79 core::vector3df tgt = Direction; 79 core::vector3df tgt = Direction;
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 outArray = Particles.pointer(); 107 outArray = Particles.pointer();
108 108
109 return Particles.size(); 109 return Particles.size();
110 } 110 }
111 111
112 return 0; 112 return 0;
113} 113}
114 114
115//! Writes attributes of the object. 115//! Writes attributes of the object.
116void CParticleCylinderEmitter::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const 116void CParticleCylinderEmitter::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
117{ 117{
118 out->addVector3d("Center", Center); 118 out->addVector3d("Center", Center);
119 out->addVector3d("Normal", Normal); 119 out->addVector3d("Normal", Normal);
120 out->addVector3d("Direction", Direction); 120 out->addVector3d("Direction", Direction);
121 out->addFloat("MinStartSizeWidth", MinStartSize.Width); 121 out->addFloat("MinStartSizeWidth", MinStartSize.Width);
122 out->addFloat("MinStartSizeHeight", MinStartSize.Height); 122 out->addFloat("MinStartSizeHeight", MinStartSize.Height);
123 out->addFloat("MaxStartSizeWidth", MaxStartSize.Width); 123 out->addFloat("MaxStartSizeWidth", MaxStartSize.Width);
124 out->addFloat("MaxStartSizeHeight", MaxStartSize.Height); 124 out->addFloat("MaxStartSizeHeight", MaxStartSize.Height);
125 out->addInt("MinParticlesPerSecond", MinParticlesPerSecond); 125 out->addInt("MinParticlesPerSecond", MinParticlesPerSecond);
126 out->addInt("MaxParticlesPerSecond", MaxParticlesPerSecond); 126 out->addInt("MaxParticlesPerSecond", MaxParticlesPerSecond);
127 out->addColor("MinStartColor", MinStartColor); 127 out->addColor("MinStartColor", MinStartColor);
128 out->addColor("MaxStartColor", MaxStartColor); 128 out->addColor("MaxStartColor", MaxStartColor);
129 out->addInt("MinLifeTime", MinLifeTime); 129 out->addInt("MinLifeTime", MinLifeTime);
130 out->addInt("MaxLifeTime", MaxLifeTime); 130 out->addInt("MaxLifeTime", MaxLifeTime);
131 out->addFloat("Radius", Radius); 131 out->addFloat("Radius", Radius);
132 out->addFloat("Length", Length); 132 out->addFloat("Length", Length);
133 out->addInt("MaxAngleDegrees", MaxAngleDegrees); 133 out->addInt("MaxAngleDegrees", MaxAngleDegrees);
134 out->addBool("OutlineOnly", OutlineOnly); 134 out->addBool("OutlineOnly", OutlineOnly);
135} 135}
136 136
137//! Reads attributes of the object. 137//! Reads attributes of the object.
138void CParticleCylinderEmitter::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) 138void CParticleCylinderEmitter::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
139{ 139{
140 Center = in->getAttributeAsVector3d("Center"); 140 Center = in->getAttributeAsVector3d("Center");
141 Normal = in->getAttributeAsVector3d("Normal"); 141 Normal = in->getAttributeAsVector3d("Normal");
142 if (Normal.getLength() == 0) 142 if (Normal.getLength() == 0)
143 Normal.set(0,1.f,0); 143 Normal.set(0,1.f,0);
144 Direction = in->getAttributeAsVector3d("Direction"); 144 Direction = in->getAttributeAsVector3d("Direction");
145 if (Direction.getLength() == 0) 145 if (Direction.getLength() == 0)
146 Direction.set(0,0.01f,0); 146 Direction.set(0,0.01f,0);
147 147
148 int idx = -1; 148 int idx = -1;
149 idx = in->findAttribute("MinStartSizeWidth"); 149 idx = in->findAttribute("MinStartSizeWidth");
150 if ( idx >= 0 ) 150 if ( idx >= 0 )
151 MinStartSize.Width = in->getAttributeAsFloat(idx); 151 MinStartSize.Width = in->getAttributeAsFloat(idx);
152 idx = in->findAttribute("MinStartSizeHeight"); 152 idx = in->findAttribute("MinStartSizeHeight");
153 if ( idx >= 0 ) 153 if ( idx >= 0 )
154 MinStartSize.Height = in->getAttributeAsFloat(idx); 154 MinStartSize.Height = in->getAttributeAsFloat(idx);
155 idx = in->findAttribute("MaxStartSizeWidth"); 155 idx = in->findAttribute("MaxStartSizeWidth");
156 if ( idx >= 0 ) 156 if ( idx >= 0 )
157 MaxStartSize.Width = in->getAttributeAsFloat(idx); 157 MaxStartSize.Width = in->getAttributeAsFloat(idx);
158 idx = in->findAttribute("MaxStartSizeHeight"); 158 idx = in->findAttribute("MaxStartSizeHeight");
159 if ( idx >= 0 ) 159 if ( idx >= 0 )
160 MaxStartSize.Height = in->getAttributeAsFloat(idx); 160 MaxStartSize.Height = in->getAttributeAsFloat(idx);
161 161
162 MinParticlesPerSecond = in->getAttributeAsInt("MinParticlesPerSecond"); 162 MinParticlesPerSecond = in->getAttributeAsInt("MinParticlesPerSecond");
163 MaxParticlesPerSecond = in->getAttributeAsInt("MaxParticlesPerSecond"); 163 MaxParticlesPerSecond = in->getAttributeAsInt("MaxParticlesPerSecond");
164 164
165 MinParticlesPerSecond = core::max_(1u, MinParticlesPerSecond); 165 MinParticlesPerSecond = core::max_(1u, MinParticlesPerSecond);
166 MaxParticlesPerSecond = core::max_(MaxParticlesPerSecond, 1u); 166 MaxParticlesPerSecond = core::max_(MaxParticlesPerSecond, 1u);
167 MaxParticlesPerSecond = core::min_(MaxParticlesPerSecond, 200u); 167 MaxParticlesPerSecond = core::min_(MaxParticlesPerSecond, 200u);
168 MinParticlesPerSecond = core::min_(MinParticlesPerSecond, MaxParticlesPerSecond); 168 MinParticlesPerSecond = core::min_(MinParticlesPerSecond, MaxParticlesPerSecond);
169 169
170 MinStartColor = in->getAttributeAsColor("MinStartColor"); 170 MinStartColor = in->getAttributeAsColor("MinStartColor");
171 MaxStartColor = in->getAttributeAsColor("MaxStartColor"); 171 MaxStartColor = in->getAttributeAsColor("MaxStartColor");
172 MinLifeTime = in->getAttributeAsInt("MinLifeTime"); 172 MinLifeTime = in->getAttributeAsInt("MinLifeTime");
173 MaxLifeTime = in->getAttributeAsInt("MaxLifeTime"); 173 MaxLifeTime = in->getAttributeAsInt("MaxLifeTime");
174 MinLifeTime = core::max_(0u, MinLifeTime); 174 MinLifeTime = core::max_(0u, MinLifeTime);
175 MaxLifeTime = core::max_(MaxLifeTime, MinLifeTime); 175 MaxLifeTime = core::max_(MaxLifeTime, MinLifeTime);
176 MinLifeTime = core::min_(MinLifeTime, MaxLifeTime); 176 MinLifeTime = core::min_(MinLifeTime, MaxLifeTime);
177 177
178 Radius = in->getAttributeAsFloat("Radius"); 178 Radius = in->getAttributeAsFloat("Radius");
179 Length = in->getAttributeAsFloat("Length"); 179 Length = in->getAttributeAsFloat("Length");
180 MaxAngleDegrees = in->getAttributeAsInt("MaxAngleDegrees"); 180 MaxAngleDegrees = in->getAttributeAsInt("MaxAngleDegrees");
181 OutlineOnly = in->getAttributeAsBool("OutlineOnly"); 181 OutlineOnly = in->getAttributeAsBool("OutlineOnly");
182} 182}
183 183
184 184
185} // end namespace scene 185} // end namespace scene
186} // end namespace irr 186} // end namespace irr
187 187