aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp
new file mode 100644
index 0000000..83887c9
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CParticleAttractionAffector.cpp
@@ -0,0 +1,84 @@
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 "CParticleAttractionAffector.h"
6#include "IAttributes.h"
7
8namespace irr
9{
10namespace scene
11{
12
13//! constructor
14CParticleAttractionAffector::CParticleAttractionAffector(
15 const core::vector3df& point, f32 speed, bool attract,
16 bool affectX, bool affectY, bool affectZ )
17 : Point(point), Speed(speed), AffectX(affectX), AffectY(affectY),
18 AffectZ(affectZ), Attract(attract), LastTime(0)
19{
20 #ifdef _DEBUG
21 setDebugName("CParticleAttractionAffector");
22 #endif
23}
24
25
26//! Affects an array of particles.
27void CParticleAttractionAffector::affect(u32 now, SParticle* particlearray, u32 count)
28{
29 if( LastTime == 0 )
30 {
31 LastTime = now;
32 return;
33 }
34
35 f32 timeDelta = ( now - LastTime ) / 1000.0f;
36 LastTime = now;
37
38 if( !Enabled )
39 return;
40
41 for(u32 i=0; i<count; ++i)
42 {
43 core::vector3df direction = (Point - particlearray[i].pos).normalize();
44 direction *= Speed * timeDelta;
45
46 if( !Attract )
47 direction *= -1.0f;
48
49 if( AffectX )
50 particlearray[i].pos.X += direction.X;
51
52 if( AffectY )
53 particlearray[i].pos.Y += direction.Y;
54
55 if( AffectZ )
56 particlearray[i].pos.Z += direction.Z;
57 }
58}
59
60//! Writes attributes of the object.
61void CParticleAttractionAffector::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
62{
63 out->addVector3d("Point", Point);
64 out->addFloat("Speed", Speed);
65 out->addBool("AffectX", AffectX);
66 out->addBool("AffectY", AffectY);
67 out->addBool("AffectZ", AffectZ);
68 out->addBool("Attract", Attract);
69}
70
71//! Reads attributes of the object.
72void CParticleAttractionAffector::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
73{
74 Point = in->getAttributeAsVector3d("Point");
75 Speed = in->getAttributeAsFloat("Speed");
76 AffectX = in->getAttributeAsBool("AffectX");
77 AffectY = in->getAttributeAsBool("AffectY");
78 AffectZ = in->getAttributeAsBool("AffectZ");
79 Attract = in->getAttributeAsBool("Attract");
80}
81
82} // end namespace scene
83} // end namespace irr
84