From 2eee4c51764d0d73986f2aae64fbaf4c0beeb9c1 Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 8 May 2020 15:59:57 +0200 Subject: most of animation system done; little stuff here and there --- src/animation/AnimBlendNode.cpp | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'src/animation/AnimBlendNode.cpp') diff --git a/src/animation/AnimBlendNode.cpp b/src/animation/AnimBlendNode.cpp index 193e9176..4186e994 100644 --- a/src/animation/AnimBlendNode.cpp +++ b/src/animation/AnimBlendNode.cpp @@ -3,11 +3,13 @@ #include "AnimBlendAssociation.h" #include "AnimBlendNode.h" +//--MIAMI: file done + void CAnimBlendNode::Init(void) { - frameA = 0; - frameB = 0; + frameA = -1; + frameB = -1; remainingTime = 0.0f; sequence = nil; association = nil; @@ -92,7 +94,9 @@ CAnimBlendNode::FindKeyFrame(float t) frameA = 0; frameB = frameA; - if(sequence->numFrames >= 2){ + if(sequence->numFrames == 1){ + remainingTime = 0.0f; + }else{ frameA++; // advance until t is between frameB and frameA @@ -101,8 +105,11 @@ CAnimBlendNode::FindKeyFrame(float t) frameB = frameA++; if(frameA >= sequence->numFrames){ // reached end of animation - if(!association->IsRepeating()) + if(!association->IsRepeating()){ + CalcDeltas(); + remainingTime = 0.0f; return false; + } frameA = 0; frameB = 0; } @@ -115,6 +122,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) { @@ -129,6 +155,20 @@ CAnimBlendNode::CalcDeltas(void) invSin = theta == 0.0f ? 0.0f : 1.0f/Sin(theta); } +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) { @@ -138,7 +178,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; -- cgit v1.2.3