mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
#include "animationController.h"
|
|
#include "animationChannel.h"
|
|
#include "skeleton.h"
|
|
|
|
using namespace std;
|
|
|
|
namespace vb01{
|
|
void AnimationController::update(){
|
|
for(AnimationChannel *channel : channels){
|
|
channel->update();
|
|
transform(channel);
|
|
}
|
|
}
|
|
|
|
void AnimationController::transform(AnimationChannel *channel){
|
|
Animation *animation = getAnimation(channel->getAnimationName());
|
|
for(Animatable *animatable : channel->getAnimatables()){
|
|
vector<KeyframeChannel> keyframeChannels = animation->getKeyframeChannelsByAnimatable(animatable);
|
|
for(KeyframeChannel keyframeChannel : keyframeChannels){
|
|
int currentFrame = channel->getCurrentFrame();
|
|
Keyframe pastKeyframe = KeyframeChannel::findKeyframe(currentFrame, keyframeChannel, true);
|
|
Keyframe nextKeyframe = KeyframeChannel::findKeyframe(currentFrame, keyframeChannel, false);
|
|
int pastFrame = pastKeyframe.frame;
|
|
int nextFrame = nextKeyframe.frame;
|
|
|
|
float ratio = (float)(max(0, currentFrame - pastFrame)) / (nextFrame - pastFrame);
|
|
Keyframe::Interpolation interp = pastKeyframe.interpolation;
|
|
float value = KeyframeChannel::interpolate(pastKeyframe, nextKeyframe, ratio);
|
|
animatable->animate(value, keyframeChannel);
|
|
}
|
|
}
|
|
}
|
|
|
|
Animation* AnimationController::getAnimation(string name){
|
|
Animation *anim = nullptr;
|
|
for(Animation *a : animations)
|
|
if(a->getName() == name){
|
|
anim = a;
|
|
break;
|
|
}
|
|
return anim;
|
|
}
|
|
|
|
void AnimationController::addAnimationChannel(AnimationChannel *channel){
|
|
channels.push_back(channel);
|
|
channel->setAnimationController(this);
|
|
}
|
|
}
|