1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CSceneNodeAnimatorFlyStraight.h"
14
CSceneNodeAnimatorFlyStraight::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)
22
setDebugName("CSceneNodeAnimatorFlyStraight");
25
recalculateIntermediateValues();
29
void CSceneNodeAnimatorFlyStraight::recalculateIntermediateValues()
32
TimeFactor = (f32)Vector.getLength() / TimeForWay;
37
//! animates a scene node
38
void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
43
u32 t = (timeMs-StartTime);
47
if (!Loop && !PingPong && t >= TimeForWay)
52
else if (!Loop && PingPong && t >= TimeForWay * 2.f )
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;
73
node->setPosition(pos);
77
//! Writes attributes of the scene node animator.
78
void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
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);
88
//! Reads attributes of the scene node animator.
89
void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
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");
97
recalculateIntermediateValues();
101
ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node, ISceneManager* newManager)
103
CSceneNodeAnimatorFlyStraight * newAnimator =
104
new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong);
110
} // end namespace scene
111
} // end namespace irr