From 39bbf3854a5c91e3d8e410d01b34d4e88df20879 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Wed, 1 Jun 2011 07:42:40 +0000 Subject: BGE Animations: Reimplemented the continuous function of the action actuator. * To do this, I've added Get/SetFrame() functions. * I've also cleaned up a little bit of the wrap around logic in BL_Action.cpp. --- source/gameengine/Ketsji/BL_Action.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'source/gameengine/Ketsji/BL_Action.cpp') diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index 5630179a049..77cb5de1398 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -27,6 +27,8 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include + #include "BL_Action.h" #include "BL_ArmatureObject.h" #include "KX_IpoConvert.h" @@ -106,6 +108,33 @@ void BL_Action::InitIPO() m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, false); } +float BL_Action::GetFrame() +{ + return m_localtime; +} + +void BL_Action::SetFrame(float frame) +{ + float dt; + + // Clamp the frame to the start and end frame + if (frame < min(m_startframe, m_endframe)) + frame = min(m_startframe, m_endframe); + else if (frame > max(m_startframe, m_endframe)) + frame = max(m_startframe, m_endframe); + + // We don't set m_localtime directly since it's recalculated + // in the next update. So, we modify the value (m_starttime) + // used to calculate m_localtime the next time SetLocalTime() is called. + + dt = frame-m_startframe; + + if (m_endframe < m_startframe) + dt = -dt; + + m_starttime -= dt / (KX_KetsjiEngine::GetAnimFrameRate()*m_speed); +} + void BL_Action::SetLocalTime(float curtime) { float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate()*m_speed; @@ -127,9 +156,7 @@ void BL_Action::Update(float curtime) SetLocalTime(curtime); // Handle wrap around - bool bforward = m_startframe < m_endframe; - if (bforward && (m_localtime < m_startframe || m_localtime > m_endframe) || - !bforward && (m_localtime > m_startframe || m_localtime < m_endframe)) + if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) { switch(m_playmode) { -- cgit v1.2.3