diff options
Diffstat (limited to 'src/animation/AnimBlendNode.cpp')
-rw-r--r-- | src/animation/AnimBlendNode.cpp | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/src/animation/AnimBlendNode.cpp b/src/animation/AnimBlendNode.cpp index df6cd1d5..ac1328eb 100644 --- a/src/animation/AnimBlendNode.cpp +++ b/src/animation/AnimBlendNode.cpp @@ -3,6 +3,8 @@ #include "AnimBlendAssociation.h" #include "AnimBlendNode.h" +//--MIAMI: file done + void CAnimBlendNode::Init(void) { @@ -92,20 +94,22 @@ CAnimBlendNode::FindKeyFrame(float t) frameA = 0; frameB = frameA; - if(sequence->numFrames >= 2){ - frameA++; - + if(sequence->numFrames == 1){ + remainingTime = 0.0f; + }else{ // advance until t is between frameB and frameA - while(t > sequence->GetKeyFrame(frameA)->deltaTime){ + while (t > sequence->GetKeyFrame(++frameA)->deltaTime) { t -= sequence->GetKeyFrame(frameA)->deltaTime; - frameB = frameA++; - if(frameA >= sequence->numFrames){ + if (frameA + 1 >= sequence->numFrames) { // reached end of animation - if(!association->IsRepeating()) + if (!association->IsRepeating()) { + CalcDeltas(); + remainingTime = 0.0f; return false; + } frameA = 0; - frameB = 0; } + frameB = frameA; } remainingTime = sequence->GetKeyFrame(frameA)->deltaTime - t; @@ -115,6 +119,25 @@ CAnimBlendNode::FindKeyFrame(float t) return true; } +bool +CAnimBlendNode::SetupKeyFrameCompressed(void) +{ + if(sequence->numFrames < 1) + return false; + + frameA = 1; + frameB = 0; + + if(sequence->numFrames == 1){ + frameA = 0; + remainingTime = 0.0f; + }else + remainingTime = sequence->GetKeyFrameCompressed(frameA)->deltaTime/60.0f; + + CalcDeltasCompressed(); + return true; +} + void CAnimBlendNode::CalcDeltas(void) { @@ -130,6 +153,20 @@ CAnimBlendNode::CalcDeltas(void) } void +CAnimBlendNode::CalcDeltasCompressed(void) +{ + if((sequence->type & CAnimBlendSequence::KF_ROT) == 0) + return; + KeyFrame *kfA = sequence->GetKeyFrameCompressed(frameA); + KeyFrame *kfB = sequence->GetKeyFrameCompressed(frameB); + float cos = DotProduct(kfA->rotation, kfB->rotation); + if(cos > 1.0f) + cos = 1.0f; + theta = Acos(cos); + invSin = theta == 0.0f ? 0.0f : 1.0f/Sin(theta); +} + +void CAnimBlendNode::GetCurrentTranslation(CVector &trans, float weight) { trans = CVector(0.0f, 0.0f, 0.0f); @@ -138,7 +175,7 @@ CAnimBlendNode::GetCurrentTranslation(CVector &trans, float weight) if(blend > 0.0f){ KeyFrameTrans *kfA = (KeyFrameTrans*)sequence->GetKeyFrame(frameA); KeyFrameTrans *kfB = (KeyFrameTrans*)sequence->GetKeyFrame(frameB); - float t = (kfA->deltaTime - remainingTime)/kfA->deltaTime; + float t = kfA->deltaTime == 0.0f ? 0.0f : (kfA->deltaTime - remainingTime)/kfA->deltaTime; if(sequence->type & CAnimBlendSequence::KF_TRANS){ trans = kfB->translation + t*(kfA->translation - kfB->translation); trans *= blend; |