aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp
new file mode 100644
index 0000000..28730b8
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp
@@ -0,0 +1,112 @@
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 "CSceneNodeAnimatorFlyStraight.h"
6
7namespace irr
8{
9namespace scene
10{
11
12
13//! constructor
14CSceneNodeAnimatorFlyStraight::CSceneNodeAnimatorFlyStraight(const core::vector3df& startPoint,
15 const core::vector3df& endPoint, u32 timeForWay,
16 bool loop, u32 now, bool pingpong)
17: ISceneNodeAnimatorFinishing(now + timeForWay),
18 Start(startPoint), End(endPoint), TimeFactor(0.0f), StartTime(now),
19 TimeForWay(timeForWay), Loop(loop), PingPong(pingpong)
20{
21 #ifdef _DEBUG
22 setDebugName("CSceneNodeAnimatorFlyStraight");
23 #endif
24
25 recalculateIntermediateValues();
26}
27
28
29void CSceneNodeAnimatorFlyStraight::recalculateIntermediateValues()
30{
31 Vector = End - Start;
32 TimeFactor = (f32)Vector.getLength() / TimeForWay;
33 Vector.normalize();
34}
35
36
37//! animates a scene node
38void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
39{
40 if (!node)
41 return;
42
43 u32 t = (timeMs-StartTime);
44
45 core::vector3df pos;
46
47 if (!Loop && !PingPong && t >= TimeForWay)
48 {
49 pos = End;
50 HasFinished = true;
51 }
52 else if (!Loop && PingPong && t >= TimeForWay * 2.f )
53 {
54 pos = Start;
55 HasFinished = true;
56 }
57 else
58 {
59 f32 phase = fmodf( (f32) t, (f32) TimeForWay );
60 core::vector3df rel = Vector * phase * TimeFactor;
61 const bool pong = PingPong && fmodf( (f32) t, (f32) TimeForWay*2.f ) >= TimeForWay;
62
63 if ( !pong )
64 {
65 pos += Start + rel;
66 }
67 else
68 {
69 pos = End - rel;
70 }
71 }
72
73 node->setPosition(pos);
74}
75
76
77//! Writes attributes of the scene node animator.
78void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
79{
80 out->addVector3d("Start", Start);
81 out->addVector3d("End", End);
82 out->addInt("TimeForWay", TimeForWay);
83 out->addBool("Loop", Loop);
84 out->addBool("PingPong", PingPong);
85}
86
87
88//! Reads attributes of the scene node animator.
89void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
90{
91 Start = in->getAttributeAsVector3d("Start");
92 End = in->getAttributeAsVector3d("End");
93 TimeForWay = in->getAttributeAsInt("TimeForWay");
94 Loop = in->getAttributeAsBool("Loop");
95 PingPong = in->getAttributeAsBool("PingPong");
96
97 recalculateIntermediateValues();
98}
99
100
101ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node, ISceneManager* newManager)
102{
103 CSceneNodeAnimatorFlyStraight * newAnimator =
104 new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong);
105
106 return newAnimator;
107}
108
109
110} // end namespace scene
111} // end namespace irr
112