#include "CSceneNodeAnimatorFlyCircle.h"
namespace irr
{
namespace scene
{
CSceneNodeAnimatorFlyCircle::CSceneNodeAnimatorFlyCircle(u32 time,
const core::vector3df& center, f32 radius, f32 speed,
const core::vector3df& direction, f32 radiusEllipsoid)
: Center(center), Direction(direction), Radius(radius),
RadiusEllipsoid(radiusEllipsoid), Speed(speed), StartTime(time)
{
#ifdef _DEBUG
setDebugName("CSceneNodeAnimatorFlyCircle");
#endif
init();
}
void CSceneNodeAnimatorFlyCircle::init()
{
Direction.normalize();
if (Direction.Y != 0)
VecV = core::vector3df(50,0,0).crossProduct(Direction).normalize();
else
VecV = core::vector3df(0,50,0).crossProduct(Direction).normalize();
VecU = VecV.crossProduct(Direction).normalize();
}
void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
{
if ( 0 == node )
return;
f32 time;
if(StartTime > timeMs)
time = ((s32)timeMs - (s32)StartTime) * Speed;
else
time = (timeMs-StartTime) * Speed;
f32 r2 = RadiusEllipsoid == 0.f ? Radius : RadiusEllipsoid;
node->setPosition(Center + (Radius*cosf(time)*VecU) + (r2*sinf(time)*VecV ) );
}
void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
out->addVector3d("Center", Center);
out->addFloat("Radius", Radius);
out->addFloat("Speed", Speed);
out->addVector3d("Direction", Direction);
out->addFloat("RadiusEllipsoid", Radius);
}
void CSceneNodeAnimatorFlyCircle::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
Center = in->getAttributeAsVector3d("Center");
Radius = in->getAttributeAsFloat("Radius");
Speed = in->getAttributeAsFloat("Speed");
Direction = in->getAttributeAsVector3d("Direction");
StartTime = 0;
if (Direction.equals(core::vector3df(0,0,0)))
Direction.set(0,1,0);
else
Direction.normalize();
RadiusEllipsoid = in->getAttributeAsFloat("RadiusEllipsoid");
init();
}
ISceneNodeAnimator* CSceneNodeAnimatorFlyCircle::createClone(ISceneNode* node, ISceneManager* newManager)
{
CSceneNodeAnimatorFlyCircle * newAnimator =
new CSceneNodeAnimatorFlyCircle(StartTime, Center, Radius, Speed, Direction, RadiusEllipsoid);
return newAnimator;
}
}
}