public void UpdateKeyframeInterpolation() { m_CurrentTime = (float)m_Timer.GetElapsedTime(); //Check to see if animation has played to the end, roll over if (m_CurrentTime > m_AniEndTime) { if (m_bLooping) { m_Timer.ResetTimer(); m_CurrentTime = 0; m_NextKeyFrame = 0; } else { m_CurrentTime = m_AniEndTime; } } //Find out what the nearest "next" frame is while ((m_NextKeyFrame < m_NumKeyFrames) && ((float)(m_NextKeyFrame / ANIMATION_FPS) < m_CurrentTime)) { m_NextKeyFrame++; } if (m_NextKeyFrame == 0) { m_PrevKeyFrame = 0; m_Interp = 0f; } else if (m_NextKeyFrame == m_NumKeyFrames) { m_NextKeyFrame = m_NumKeyFrames - 1; m_PrevKeyFrame = m_NumKeyFrames - 1; m_Interp = 0f; } else { float timeDelta = 1.0f / ANIMATION_FPS; m_Interp = (float)((m_CurrentTime - (m_NextKeyFrame - 1) / ANIMATION_FPS) / timeDelta); m_PrevKeyFrame = m_NextKeyFrame - 1; } //Trace.Write("Elapsed time: "+m_CurrentTime.ToString()+" next KF="+m_NextKeyFrame.ToString()+ // " interp= "+m_Interp.ToString()+"\n"); }
public void MovementActivated(bool bMoved) { float dt = 0; float acc_speed = 0; MAX_CAM_SPEED = OptionsManager.CameraSpeed; //test comment CAM_ACC = 5.0f * (OptionsManager.CameraSpeed / 10f); CAM_COAST_ACC = 4.0f * (OptionsManager.CameraSpeed / 10f); switch (m_Mode) { case CamMode.Idle: if (bMoved == true) { m_LaunchTimer.ResetTimer(); m_Mode = CamMode.KeyOn; } break; case CamMode.KeyOn: if (bMoved == false) { //m_CurrentSpeed *= -0.2f;//COAST_CAM_INITIAL_SPEED; m_CurrentSpeed *= -0.2f;//OptionsManager.CameraSpeed/20;//COAST_CAM_INITIAL_SPEED; m_CoastTimer.ResetTimer(); m_Mode = CamMode.Coast; } break; case CamMode.Coast: if (bMoved == true) { m_Mode = CamMode.KeyOn; m_CurrentSpeed = 0; } if (m_CurrentSpeed > 0) { m_CurrentSpeed = 0; m_Mode = CamMode.Idle; } break; } //Trace.WriteLine("mode = " + m_Mode.ToString() + "spd = " + m_CurrentSpeed.ToString()); //update camera speed switch (m_Mode) { case CamMode.Idle: break; case CamMode.KeyOn: dt = (float)m_LaunchTimer.GetElapsedTime(); acc_speed = CAM_ACC * dt; if (acc_speed > MAX_CAM_SPEED) { m_CurrentSpeed = MAX_CAM_SPEED; } else { m_CurrentSpeed = acc_speed; } break; case CamMode.Coast: dt = (float)m_CoastTimer.GetElapsedTime(); acc_speed = m_CurrentSpeed + CAM_COAST_ACC * dt; if (m_bRotateMode) { if (acc_speed < 0) { m_Mode = CamMode.Idle; m_CurrentSpeed = 0; } else { m_CurrentSpeed = acc_speed; } } else { if (acc_speed > 0) { m_Mode = CamMode.Idle; m_CurrentSpeed = 0; } else { m_CurrentSpeed = acc_speed; } } break; } }