public void moveKeyframeMotion()
{
if (IsDeleted || m_rootPart.KeyframeAnimation == null || m_rootPart.KeyframeAnimation.TimeList.Length == 0)
{
m_scene.EventManager.OnFrame -= moveKeyframeMotion;
return;
}
try
{
if (m_rootPart.KeyframeAnimation.CurrentFrame == 0)
m_rootPart.KeyframeAnimation.CurrentFrame = Environment.TickCount;
float timeAmt = m_rootPart.KeyframeAnimation.TimeList[m_rootPart.KeyframeAnimation.CurrentAnimationPosition];
int currentTime = (int)(timeAmt * 1000);
Vector3 currentTarget = m_rootPart.KeyframeAnimation.PositionList.Length == 0
? Vector3.Zero
: m_rootPart.KeyframeAnimation.PositionList[
m_rootPart.KeyframeAnimation.CurrentAnimationPosition];
Quaternion target = m_rootPart.KeyframeAnimation.RotationList.Length == 0
? Quaternion.Identity
: m_rootPart.KeyframeAnimation.RotationList[
m_rootPart.KeyframeAnimation.CurrentAnimationPosition];
//Add one to the current frame so that we know when to stops
bool AllDoneMoving = false;
bool MadeItToCheckpoint = false;
int timeSinceEpoch = Environment.TickCount;
if (m_rootPart.KeyframeAnimation.CurrentFrame + currentTime < timeSinceEpoch)
{
if (m_rootPart.KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Forward)
{
m_rootPart.KeyframeAnimation.CurrentAnimationPosition += 1;
if (m_rootPart.KeyframeAnimation.CurrentAnimationPosition ==
m_rootPart.KeyframeAnimation.TimeList.Length)
{
//All done moving...
AllDoneMoving = true;
m_scene.EventManager.OnFrame -= moveKeyframeMotion;
}
}
else if (m_rootPart.KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Reverse)
{
m_rootPart.KeyframeAnimation.CurrentAnimationPosition -= 1;
if (m_rootPart.KeyframeAnimation.CurrentAnimationPosition < 0)
{
//All done moving...
AllDoneMoving = true;
m_scene.EventManager.OnFrame -= moveKeyframeMotion;
}
}
else if (m_rootPart.KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Loop)
{
m_rootPart.KeyframeAnimation.CurrentAnimationPosition += 1;
if (m_rootPart.KeyframeAnimation.CurrentAnimationPosition ==
m_rootPart.KeyframeAnimation.TimeList.Length)
m_rootPart.KeyframeAnimation.CurrentAnimationPosition = 0;
}
else if (m_rootPart.KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.PingPong)
{
if (m_rootPart.KeyframeAnimation.PingPongForwardMotion)
{
m_rootPart.KeyframeAnimation.CurrentAnimationPosition += 1;
if (m_rootPart.KeyframeAnimation.CurrentAnimationPosition ==
m_rootPart.KeyframeAnimation.TimeList.Length)
{
m_rootPart.KeyframeAnimation.PingPongForwardMotion =
!m_rootPart.KeyframeAnimation.PingPongForwardMotion;
m_rootPart.KeyframeAnimation.CurrentAnimationPosition -= 2;
}
}
else
{
m_rootPart.KeyframeAnimation.CurrentAnimationPosition -= 1;
if (m_rootPart.KeyframeAnimation.CurrentAnimationPosition < 0)
{
m_rootPart.KeyframeAnimation.PingPongForwardMotion =
!m_rootPart.KeyframeAnimation.PingPongForwardMotion;
m_rootPart.KeyframeAnimation.CurrentAnimationPosition += 2;
}
}
}
m_rootPart.KeyframeAnimation.CurrentFrame = Environment.TickCount;
MadeItToCheckpoint = true;
}
float progress = (((float)(timeSinceEpoch - m_rootPart.KeyframeAnimation.CurrentFrame)) / (float)currentTime);
if (m_rootPart.KeyframeAnimation.PositionList.Length != 0)
{
Vector3 _target_velocity = Vector3.Lerp(Vector3.Zero, currentTarget, progress);
if (MadeItToCheckpoint)
{
if (AllDoneMoving)
Velocity = Vector3.Zero;
SetAbsolutePosition(true, m_rootPart.KeyframeAnimation.InitialPosition + currentTarget);
m_rootPart.KeyframeAnimation.InitialPosition = m_rootPart.KeyframeAnimation.InitialPosition + currentTarget;
}
else
{
Velocity = ((m_rootPart.KeyframeAnimation.InitialPosition + _target_velocity) - AbsolutePosition) * -1f;
SetAbsolutePosition(true, m_rootPart.KeyframeAnimation.InitialPosition + _target_velocity);
}
}
if (m_rootPart.KeyframeAnimation.RotationList.Length != 0)
{
target = m_rootPart.KeyframeAnimation.InitialRotation * target;
Quaternion newInterpolation = Quaternion.Slerp(m_rootPart.KeyframeAnimation.InitialRotation, target, progress);
newInterpolation.Normalize();
m_rootPart.UpdateRotation(newInterpolation);
if (MadeItToCheckpoint)
{
//Force set it to the right position, just to be sure
m_rootPart.UpdateRotation(target);
m_rootPart.KeyframeAnimation.InitialRotation = target;
}
}
}
catch
{
m_scene.EventManager.OnFrame -= moveKeyframeMotion;
}
ScheduleGroupTerseUpdate();
}