-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimationPlayer.cpp
60 lines (51 loc) · 1.16 KB
/
AnimationPlayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "AnimationPlayer.h"
#include "AnimationClip.h"
#include "Rig.h"
AnimationPlayer::AnimationPlayer(Node *parent) : Node(parent)
{
_rig = NULL;
_anim = NULL;
setType("Animation");
setName("Animation");
DOF* speed = new DOF(DOF::AnimSpeed, true);
speed->setMin(-2);
speed->setMax(2);
speed->setValue(1);
setDOF(DOF::AnimSpeed, speed);
}
AnimationPlayer::~AnimationPlayer()
{
}
void AnimationPlayer::update(float elapsed)
{
if (!_anim || !_rig)
return ;
DOF* speed = getDOF(DOF::AnimSpeed);
_elapsed += speed ? (elapsed * speed->value()) : elapsed;
Pose newPose;
_anim->evaluate(_elapsed, newPose);
_rig->applyPose(newPose);
Node::update(elapsed);
}
void AnimationPlayer::setRig(Rig *rig)
{
_rig = rig;
}
void AnimationPlayer::setAnimation(AnimationClip *anim)
{
_anim = anim;
}
Channel *AnimationPlayer::channel(DOF *dof) const
{
if (!_rig || !_anim)
return NULL;
int idx = _rig->index(dof);
if (idx == -1)
return NULL;
return _anim->channel(idx);
}
void AnimationPlayer::saveToFile(const QString &filename)
{
if (_anim)
_anim->saveToFile(filename);
}