diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CParticlePointEmitter.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CParticlePointEmitter.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CParticlePointEmitter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CParticlePointEmitter.cpp new file mode 100644 index 0000000..34dc51d --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CParticlePointEmitter.cpp | |||
@@ -0,0 +1,147 @@ | |||
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 | #include "CParticlePointEmitter.h" | ||
6 | #include "os.h" | ||
7 | #include "IAttributes.h" | ||
8 | |||
9 | namespace irr | ||
10 | { | ||
11 | namespace scene | ||
12 | { | ||
13 | |||
14 | //! constructor | ||
15 | CParticlePointEmitter::CParticlePointEmitter( | ||
16 | const core::vector3df& direction, u32 minParticlesPerSecond, | ||
17 | u32 maxParticlesPerSecond, video::SColor minStartColor, | ||
18 | video::SColor maxStartColor, u32 lifeTimeMin, u32 lifeTimeMax, | ||
19 | s32 maxAngleDegrees, | ||
20 | const core::dimension2df& minStartSize, | ||
21 | const core::dimension2df& maxStartSize) | ||
22 | : Direction(direction), | ||
23 | MinStartSize(minStartSize), MaxStartSize(maxStartSize), | ||
24 | MinParticlesPerSecond(minParticlesPerSecond), | ||
25 | MaxParticlesPerSecond(maxParticlesPerSecond), | ||
26 | MinStartColor(minStartColor), MaxStartColor(maxStartColor), | ||
27 | MinLifeTime(lifeTimeMin), MaxLifeTime(lifeTimeMax), | ||
28 | MaxAngleDegrees(maxAngleDegrees), Time(0), Emitted(0) | ||
29 | { | ||
30 | #ifdef _DEBUG | ||
31 | setDebugName("CParticlePointEmitter"); | ||
32 | #endif | ||
33 | } | ||
34 | |||
35 | |||
36 | //! Prepares an array with new particles to emitt into the system | ||
37 | //! and returns how much new particles there are. | ||
38 | s32 CParticlePointEmitter::emitt(u32 now, u32 timeSinceLastCall, SParticle*& outArray) | ||
39 | { | ||
40 | Time += timeSinceLastCall; | ||
41 | |||
42 | const u32 pps = (MaxParticlesPerSecond - MinParticlesPerSecond); | ||
43 | const f32 perSecond = pps ? ((f32)MinParticlesPerSecond + os::Randomizer::frand() * pps) : MinParticlesPerSecond; | ||
44 | const f32 everyWhatMillisecond = 1000.0f / perSecond; | ||
45 | |||
46 | if (Time > everyWhatMillisecond) | ||
47 | { | ||
48 | Time = 0; | ||
49 | Particle.startTime = now; | ||
50 | Particle.vector = Direction; | ||
51 | |||
52 | if (MaxAngleDegrees) | ||
53 | { | ||
54 | core::vector3df tgt = Direction; | ||
55 | tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees); | ||
56 | tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees); | ||
57 | tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees); | ||
58 | Particle.vector = tgt; | ||
59 | } | ||
60 | |||
61 | Particle.endTime = now + MinLifeTime; | ||
62 | if (MaxLifeTime != MinLifeTime) | ||
63 | Particle.endTime += os::Randomizer::rand() % (MaxLifeTime - MinLifeTime); | ||
64 | |||
65 | if (MinStartColor==MaxStartColor) | ||
66 | Particle.color=MinStartColor; | ||
67 | else | ||
68 | Particle.color = MinStartColor.getInterpolated(MaxStartColor, os::Randomizer::frand()); | ||
69 | |||
70 | Particle.startColor = Particle.color; | ||
71 | Particle.startVector = Particle.vector; | ||
72 | |||
73 | if (MinStartSize==MaxStartSize) | ||
74 | Particle.startSize = MinStartSize; | ||
75 | else | ||
76 | Particle.startSize = MinStartSize.getInterpolated(MaxStartSize, os::Randomizer::frand()); | ||
77 | Particle.size = Particle.startSize; | ||
78 | |||
79 | outArray = &Particle; | ||
80 | return 1; | ||
81 | } | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | |||
87 | //! Writes attributes of the object. | ||
88 | void CParticlePointEmitter::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const | ||
89 | { | ||
90 | out->addVector3d("Direction", Direction); | ||
91 | out->addFloat("MinStartSizeWidth", MinStartSize.Width); | ||
92 | out->addFloat("MinStartSizeHeight", MinStartSize.Height); | ||
93 | out->addFloat("MaxStartSizeWidth", MaxStartSize.Width); | ||
94 | out->addFloat("MaxStartSizeHeight", MaxStartSize.Height); | ||
95 | out->addInt("MinParticlesPerSecond", MinParticlesPerSecond); | ||
96 | out->addInt("MaxParticlesPerSecond", MaxParticlesPerSecond); | ||
97 | out->addColor("MinStartColor", MinStartColor); | ||
98 | out->addColor("MaxStartColor", MaxStartColor); | ||
99 | out->addInt("MinLifeTime", MinLifeTime); | ||
100 | out->addInt("MaxLifeTime", MaxLifeTime); | ||
101 | out->addInt("MaxAngleDegrees", MaxAngleDegrees); | ||
102 | } | ||
103 | |||
104 | //! Reads attributes of the object. | ||
105 | void CParticlePointEmitter::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) | ||
106 | { | ||
107 | Direction = in->getAttributeAsVector3d("Direction"); | ||
108 | if (Direction.getLength() == 0) | ||
109 | Direction.set(0,0.01f,0); | ||
110 | |||
111 | int idx = -1; | ||
112 | idx = in->findAttribute("MinStartSizeWidth"); | ||
113 | if ( idx >= 0 ) | ||
114 | MinStartSize.Width = in->getAttributeAsFloat(idx); | ||
115 | idx = in->findAttribute("MinStartSizeHeight"); | ||
116 | if ( idx >= 0 ) | ||
117 | MinStartSize.Height = in->getAttributeAsFloat(idx); | ||
118 | idx = in->findAttribute("MaxStartSizeWidth"); | ||
119 | if ( idx >= 0 ) | ||
120 | MaxStartSize.Width = in->getAttributeAsFloat(idx); | ||
121 | idx = in->findAttribute("MaxStartSizeHeight"); | ||
122 | if ( idx >= 0 ) | ||
123 | MaxStartSize.Height = in->getAttributeAsFloat(idx); | ||
124 | |||
125 | MinParticlesPerSecond = in->getAttributeAsInt("MinParticlesPerSecond"); | ||
126 | MaxParticlesPerSecond = in->getAttributeAsInt("MaxParticlesPerSecond"); | ||
127 | |||
128 | MinParticlesPerSecond = core::max_(1u, MinParticlesPerSecond); | ||
129 | MaxParticlesPerSecond = core::max_(MaxParticlesPerSecond, 1u); | ||
130 | MaxParticlesPerSecond = core::min_(MaxParticlesPerSecond, 200u); | ||
131 | MinParticlesPerSecond = core::min_(MinParticlesPerSecond, MaxParticlesPerSecond); | ||
132 | |||
133 | MinStartColor = in->getAttributeAsColor("MinStartColor"); | ||
134 | MaxStartColor = in->getAttributeAsColor("MaxStartColor"); | ||
135 | MinLifeTime = in->getAttributeAsInt("MinLifeTime"); | ||
136 | MaxLifeTime = in->getAttributeAsInt("MaxLifeTime"); | ||
137 | MaxAngleDegrees = in->getAttributeAsInt("MaxAngleDegrees"); | ||
138 | |||
139 | MinLifeTime = core::max_(0u, MinLifeTime); | ||
140 | MaxLifeTime = core::max_(MaxLifeTime, MinLifeTime); | ||
141 | MinLifeTime = core::min_(MinLifeTime, MaxLifeTime); | ||
142 | } | ||
143 | |||
144 | |||
145 | } // end namespace scene | ||
146 | } // end namespace irr | ||
147 | |||