aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp354
1 files changed, 177 insertions, 177 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp
index 5f398cd..dfe3068 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CParticleRingEmitter.cpp
@@ -1,177 +1,177 @@
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 "CParticleRingEmitter.h" 5#include "CParticleRingEmitter.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
15CParticleRingEmitter::CParticleRingEmitter( 15CParticleRingEmitter::CParticleRingEmitter(
16 const core::vector3df& center, f32 radius, f32 ringThickness, 16 const core::vector3df& center, f32 radius, f32 ringThickness,
17 const core::vector3df& direction, u32 minParticlesPerSecond, 17 const core::vector3df& direction, u32 minParticlesPerSecond,
18 u32 maxParticlesPerSecond, const video::SColor& minStartColor, 18 u32 maxParticlesPerSecond, const video::SColor& minStartColor,
19 const video::SColor& maxStartColor, u32 lifeTimeMin, u32 lifeTimeMax, 19 const video::SColor& maxStartColor, u32 lifeTimeMin, u32 lifeTimeMax,
20 s32 maxAngleDegrees, 20 s32 maxAngleDegrees,
21 const core::dimension2df& minStartSize, 21 const core::dimension2df& minStartSize,
22 const core::dimension2df& maxStartSize ) 22 const core::dimension2df& maxStartSize )
23 : Center(center), Radius(radius), RingThickness(ringThickness), 23 : Center(center), Radius(radius), RingThickness(ringThickness),
24 Direction(direction), 24 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 Time(0), Emitted(0), MaxAngleDegrees(maxAngleDegrees) 30 Time(0), Emitted(0), MaxAngleDegrees(maxAngleDegrees)
31{ 31{
32 #ifdef _DEBUG 32 #ifdef _DEBUG
33 setDebugName("CParticleRingEmitter"); 33 setDebugName("CParticleRingEmitter");
34 #endif 34 #endif
35} 35}
36 36
37 37
38//! Prepares an array with new particles to emitt into the system 38//! Prepares an array with new particles to emitt into the system
39//! and returns how much new particles there are. 39//! and returns how much new particles there are.
40s32 CParticleRingEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray) 40s32 CParticleRingEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray)
41{ 41{
42 Time += timeSinceLastCall; 42 Time += timeSinceLastCall;
43 43
44 u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond); 44 u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond);
45 f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond; 45 f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond;
46 f32 everyWhatMillisecond = 1000.0f / perSecond; 46 f32 everyWhatMillisecond = 1000.0f / perSecond;
47 47
48 if(Time > everyWhatMillisecond) 48 if(Time > everyWhatMillisecond)
49 { 49 {
50 Particles.set_used(0); 50 Particles.set_used(0);
51 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f); 51 u32 amount = (u32)((Time / everyWhatMillisecond) + 0.5f);
52 Time = 0; 52 Time = 0;
53 SParticle p; 53 SParticle p;
54 54
55 if(amount > MaxParticlesPerSecond*2) 55 if(amount > MaxParticlesPerSecond*2)
56 amount = MaxParticlesPerSecond * 2; 56 amount = MaxParticlesPerSecond * 2;
57 57
58 for(u32 i=0; i<amount; ++i) 58 for(u32 i=0; i<amount; ++i)
59 { 59 {
60 f32 distance = os::Randomizer::frand() * RingThickness * 0.5f; 60 f32 distance = os::Randomizer::frand() * RingThickness * 0.5f;
61 if (os::Randomizer::rand() % 2) 61 if (os::Randomizer::rand() % 2)
62 distance -= Radius; 62 distance -= Radius;
63 else 63 else
64 distance += Radius; 64 distance += Radius;
65 65
66 p.pos.set(Center.X + distance, Center.Y, Center.Z + distance); 66 p.pos.set(Center.X + distance, Center.Y, Center.Z + distance);
67 p.pos.rotateXZBy(os::Randomizer::frand() * 360, Center ); 67 p.pos.rotateXZBy(os::Randomizer::frand() * 360, Center );
68 68
69 p.startTime = now; 69 p.startTime = now;
70 p.vector = Direction; 70 p.vector = Direction;
71 71
72 if(MaxAngleDegrees) 72 if(MaxAngleDegrees)
73 { 73 {
74 core::vector3df tgt = Direction; 74 core::vector3df tgt = Direction;
75 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees, Center ); 75 tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees, Center );
76 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees, Center ); 76 tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees, Center );
77 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees, Center ); 77 tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees, Center );
78 p.vector = tgt; 78 p.vector = tgt;
79 } 79 }
80 80
81 p.endTime = now + MinLifeTime; 81 p.endTime = now + MinLifeTime;
82 if (MaxLifeTime != MinLifeTime) 82 if (MaxLifeTime != MinLifeTime)
83 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime); 83 p.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime);
84 84
85 if (MinStartColor==MaxStartColor) 85 if (MinStartColor==MaxStartColor)
86 p.color=MinStartColor; 86 p.color=MinStartColor;
87 else 87 else
88 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand()); 88 p.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand());
89 89
90 p.startColor = p.color; 90 p.startColor = p.color;
91 p.startVector = p.vector; 91 p.startVector = p.vector;
92 92
93 if (MinStartSize==MaxStartSize) 93 if (MinStartSize==MaxStartSize)
94 p.startSize = MinStartSize; 94 p.startSize = MinStartSize;
95 else 95 else
96 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand()); 96 p.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand());
97 p.size = p.startSize; 97 p.size = p.startSize;
98 98
99 Particles.push_back(p); 99 Particles.push_back(p);
100 } 100 }
101 101
102 outArray = Particles.pointer(); 102 outArray = Particles.pointer();
103 103
104 return Particles.size(); 104 return Particles.size();
105 } 105 }
106 106
107 return 0; 107 return 0;
108} 108}
109 109
110//! Writes attributes of the object. 110//! Writes attributes of the object.
111void CParticleRingEmitter::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const 111void CParticleRingEmitter::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
112{ 112{
113 out->addVector3d("Center", Center); 113 out->addVector3d("Center", Center);
114 out->addFloat("Radius", Radius); 114 out->addFloat("Radius", Radius);
115 out->addFloat("RingThickness", RingThickness); 115 out->addFloat("RingThickness", RingThickness);
116 116
117 out->addVector3d("Direction", Direction); 117 out->addVector3d("Direction", Direction);
118 out->addFloat("MinStartSizeWidth", MinStartSize.Width); 118 out->addFloat("MinStartSizeWidth", MinStartSize.Width);
119 out->addFloat("MinStartSizeHeight", MinStartSize.Height); 119 out->addFloat("MinStartSizeHeight", MinStartSize.Height);
120 out->addFloat("MaxStartSizeWidth", MaxStartSize.Width); 120 out->addFloat("MaxStartSizeWidth", MaxStartSize.Width);
121 out->addFloat("MaxStartSizeHeight", MaxStartSize.Height); 121 out->addFloat("MaxStartSizeHeight", MaxStartSize.Height);
122 out->addInt("MinParticlesPerSecond", MinParticlesPerSecond); 122 out->addInt("MinParticlesPerSecond", MinParticlesPerSecond);
123 out->addInt("MaxParticlesPerSecond", MaxParticlesPerSecond); 123 out->addInt("MaxParticlesPerSecond", MaxParticlesPerSecond);
124 out->addColor("MinStartColor", MinStartColor); 124 out->addColor("MinStartColor", MinStartColor);
125 out->addColor("MaxStartColor", MaxStartColor); 125 out->addColor("MaxStartColor", MaxStartColor);
126 out->addInt("MinLifeTime", MinLifeTime); 126 out->addInt("MinLifeTime", MinLifeTime);
127 out->addInt("MaxLifeTime", MaxLifeTime); 127 out->addInt("MaxLifeTime", MaxLifeTime);
128 out->addInt("MaxAngleDegrees", MaxAngleDegrees); 128 out->addInt("MaxAngleDegrees", MaxAngleDegrees);
129} 129}
130 130
131//! Reads attributes of the object. 131//! Reads attributes of the object.
132void CParticleRingEmitter::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) 132void CParticleRingEmitter::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
133{ 133{
134 Center = in->getAttributeAsVector3d("Center"); 134 Center = in->getAttributeAsVector3d("Center");
135 Radius = in->getAttributeAsFloat("Radius"); 135 Radius = in->getAttributeAsFloat("Radius");
136 RingThickness = in->getAttributeAsFloat("RingThickness"); 136 RingThickness = in->getAttributeAsFloat("RingThickness");
137 137
138 Direction = in->getAttributeAsVector3d("Direction"); 138 Direction = in->getAttributeAsVector3d("Direction");
139 if (Direction.getLength() == 0) 139 if (Direction.getLength() == 0)
140 Direction.set(0,0.01f,0); 140 Direction.set(0,0.01f,0);
141 141
142 int idx = -1; 142 int idx = -1;
143 idx = in->findAttribute("MinStartSizeWidth"); 143 idx = in->findAttribute("MinStartSizeWidth");
144 if ( idx >= 0 ) 144 if ( idx >= 0 )
145 MinStartSize.Width = in->getAttributeAsFloat(idx); 145 MinStartSize.Width = in->getAttributeAsFloat(idx);
146 idx = in->findAttribute("MinStartSizeHeight"); 146 idx = in->findAttribute("MinStartSizeHeight");
147 if ( idx >= 0 ) 147 if ( idx >= 0 )
148 MinStartSize.Height = in->getAttributeAsFloat(idx); 148 MinStartSize.Height = in->getAttributeAsFloat(idx);
149 idx = in->findAttribute("MaxStartSizeWidth"); 149 idx = in->findAttribute("MaxStartSizeWidth");
150 if ( idx >= 0 ) 150 if ( idx >= 0 )
151 MaxStartSize.Width = in->getAttributeAsFloat(idx); 151 MaxStartSize.Width = in->getAttributeAsFloat(idx);
152 idx = in->findAttribute("MaxStartSizeHeight"); 152 idx = in->findAttribute("MaxStartSizeHeight");
153 if ( idx >= 0 ) 153 if ( idx >= 0 )
154 MaxStartSize.Height = in->getAttributeAsFloat(idx); 154 MaxStartSize.Height = in->getAttributeAsFloat(idx);
155 155
156 MinParticlesPerSecond = in->getAttributeAsInt("MinParticlesPerSecond"); 156 MinParticlesPerSecond = in->getAttributeAsInt("MinParticlesPerSecond");
157 MaxParticlesPerSecond = in->getAttributeAsInt("MaxParticlesPerSecond"); 157 MaxParticlesPerSecond = in->getAttributeAsInt("MaxParticlesPerSecond");
158 158
159 MinParticlesPerSecond = core::max_(1u, MinParticlesPerSecond); 159 MinParticlesPerSecond = core::max_(1u, MinParticlesPerSecond);
160 MaxParticlesPerSecond = core::max_(MaxParticlesPerSecond, 1u); 160 MaxParticlesPerSecond = core::max_(MaxParticlesPerSecond, 1u);
161 MaxParticlesPerSecond = core::min_(MaxParticlesPerSecond, 200u); 161 MaxParticlesPerSecond = core::min_(MaxParticlesPerSecond, 200u);
162 MinParticlesPerSecond = core::min_(MinParticlesPerSecond, MaxParticlesPerSecond); 162 MinParticlesPerSecond = core::min_(MinParticlesPerSecond, MaxParticlesPerSecond);
163 163
164 MinStartColor = in->getAttributeAsColor("MinStartColor"); 164 MinStartColor = in->getAttributeAsColor("MinStartColor");
165 MaxStartColor = in->getAttributeAsColor("MaxStartColor"); 165 MaxStartColor = in->getAttributeAsColor("MaxStartColor");
166 MinLifeTime = in->getAttributeAsInt("MinLifeTime"); 166 MinLifeTime = in->getAttributeAsInt("MinLifeTime");
167 MaxLifeTime = in->getAttributeAsInt("MaxLifeTime"); 167 MaxLifeTime = in->getAttributeAsInt("MaxLifeTime");
168 MinLifeTime = core::max_(0u, MinLifeTime); 168 MinLifeTime = core::max_(0u, MinLifeTime);
169 MaxLifeTime = core::max_(MaxLifeTime, MinLifeTime); 169 MaxLifeTime = core::max_(MaxLifeTime, MinLifeTime);
170 MinLifeTime = core::min_(MinLifeTime, MaxLifeTime); 170 MinLifeTime = core::min_(MinLifeTime, MaxLifeTime);
171 171
172 MaxAngleDegrees = in->getAttributeAsInt("MaxAngleDegrees"); 172 MaxAngleDegrees = in->getAttributeAsInt("MaxAngleDegrees");
173} 173}
174 174
175} // end namespace scene 175} // end namespace scene
176} // end namespace irr 176} // end namespace irr
177 177