2009-01-14 04:37:51 -08:00
|
|
|
// Copyright (C) 2002-2009 Nikolaus Gebhardt
|
2007-05-20 11:03:49 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "CSceneNodeAnimatorFlyStraight.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CSceneNodeAnimatorFlyStraight::CSceneNodeAnimatorFlyStraight(const core::vector3df& startPoint,
|
|
|
|
const core::vector3df& endPoint, u32 timeForWay,
|
2009-02-05 07:33:55 -08:00
|
|
|
bool loop, u32 now, bool pingpong)
|
2008-12-19 15:21:26 -08:00
|
|
|
: ISceneNodeAnimatorFinishing(now + timeForWay),
|
2009-03-30 08:45:59 -07:00
|
|
|
Start(startPoint), End(endPoint), TimeFactor(0.0f), StartTime(now),
|
|
|
|
TimeForWay(timeForWay), Loop(loop), PingPong(pingpong)
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CSceneNodeAnimatorFlyStraight");
|
|
|
|
#endif
|
|
|
|
|
2008-12-19 15:21:26 -08:00
|
|
|
recalculateIntermediateValues();
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 15:21:26 -08:00
|
|
|
void CSceneNodeAnimatorFlyStraight::recalculateIntermediateValues()
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
Vector = End - Start;
|
2009-03-30 08:45:59 -07:00
|
|
|
TimeFactor = (f32)Vector.getLength() / TimeForWay;
|
2007-05-20 11:03:49 -07:00
|
|
|
Vector.normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! animates a scene node
|
|
|
|
void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
|
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u32 t = (timeMs-StartTime);
|
|
|
|
|
2010-01-08 03:46:38 -08:00
|
|
|
core::vector3df pos;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2010-01-08 03:46:38 -08:00
|
|
|
if (!Loop && !PingPong && t >= TimeForWay)
|
2008-12-19 15:21:26 -08:00
|
|
|
{
|
2007-05-20 11:03:49 -07:00
|
|
|
pos = End;
|
2008-12-19 15:21:26 -08:00
|
|
|
HasFinished = true;
|
|
|
|
}
|
2010-01-08 03:46:38 -08:00
|
|
|
else if (!Loop && PingPong && t >= TimeForWay * 2.f )
|
|
|
|
{
|
|
|
|
pos = Start;
|
|
|
|
HasFinished = true;
|
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
else
|
2008-12-19 15:21:26 -08:00
|
|
|
{
|
2009-02-05 07:33:55 -08:00
|
|
|
f32 phase = fmodf( (f32) t, (f32) TimeForWay );
|
|
|
|
core::vector3df rel = Vector * phase * TimeFactor;
|
2010-01-08 03:46:38 -08:00
|
|
|
const bool pong = PingPong && fmodf( (f32) t, (f32) TimeForWay*2.f ) >= TimeForWay;
|
2009-02-05 07:33:55 -08:00
|
|
|
|
2010-01-08 03:46:38 -08:00
|
|
|
if ( !pong )
|
2009-02-05 07:33:55 -08:00
|
|
|
{
|
2010-01-08 03:46:38 -08:00
|
|
|
pos += Start + rel;
|
2009-02-05 07:33:55 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = End - rel;
|
|
|
|
}
|
2008-12-19 15:21:26 -08:00
|
|
|
}
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
node->setPosition(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Writes attributes of the scene node animator.
|
2007-09-14 15:25:59 -07:00
|
|
|
void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
|
2007-05-20 11:03:49 -07:00
|
|
|
{
|
|
|
|
out->addVector3d("Start", Start);
|
|
|
|
out->addVector3d("End", End);
|
|
|
|
out->addInt("TimeForWay", TimeForWay);
|
|
|
|
out->addBool("Loop", Loop);
|
2009-02-05 07:33:55 -08:00
|
|
|
out->addBool("PingPong", PingPong);
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Reads attributes of the scene node animator.
|
|
|
|
void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
|
|
|
|
{
|
|
|
|
Start = in->getAttributeAsVector3d("Start");
|
|
|
|
End = in->getAttributeAsVector3d("End");
|
|
|
|
TimeForWay = in->getAttributeAsInt("TimeForWay");
|
|
|
|
Loop = in->getAttributeAsBool("Loop");
|
2009-02-05 07:33:55 -08:00
|
|
|
PingPong = in->getAttributeAsBool("PingPong");
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-12-19 15:21:26 -08:00
|
|
|
recalculateIntermediateValues();
|
2007-05-20 11:03:49 -07:00
|
|
|
}
|
|
|
|
|
2009-03-30 02:18:36 -07:00
|
|
|
|
2008-10-12 19:55:54 -07:00
|
|
|
ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node, ISceneManager* newManager)
|
|
|
|
{
|
2009-03-30 08:45:59 -07:00
|
|
|
CSceneNodeAnimatorFlyStraight * newAnimator =
|
2009-02-05 07:33:55 -08:00
|
|
|
new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong);
|
2008-10-12 19:55:54 -07:00
|
|
|
|
|
|
|
return newAnimator;
|
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2009-03-30 02:18:36 -07:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|