]> git.tdb.fi Git - libs/gl.git/blob - source/keyframe.cpp
Support for armature-based animation
[libs/gl.git] / source / keyframe.cpp
1 #include <msp/datafile/collection.h>
2 #include "keyframe.h"
3 #include "pose.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 void KeyFrame::set_matrix(const Matrix &m)
11 {
12         matrix = m;
13 }
14
15 void KeyFrame::set_pose(const Pose &p)
16 {
17         pose = &p;
18         pose.keep();
19 }
20
21
22 KeyFrame::Loader::Loader(KeyFrame &k):
23         DataFile::CollectionObjectLoader<KeyFrame>(k, 0)
24 {
25         init();
26 }
27
28 KeyFrame::Loader::Loader(KeyFrame &k, Collection &c):
29         DataFile::CollectionObjectLoader<KeyFrame>(k, &c)
30 {
31         init();
32 }
33
34 void KeyFrame::Loader::init()
35 {
36         add("pose", &Loader::pose);
37         add("pose", &Loader::pose_inline);
38         add("position", &Loader::position);
39         add("rotation", &Loader::rotation);
40         add("scaling", &Loader::scaling_uniform);
41         add("scaling", &Loader::scaling);
42 }
43
44 void KeyFrame::Loader::pose(const string &n)
45 {
46         obj.pose = &get_collection().get<Pose>(n);
47         obj.pose.keep();
48 }
49
50 void KeyFrame::Loader::pose_inline()
51 {
52         RefPtr<Pose> p = new Pose;
53         load_sub(*p, get_collection());
54         obj.pose = p;
55 }
56
57 void KeyFrame::Loader::position(float x, float y, float z)
58 {
59         obj.matrix.translate(x, y, z);
60 }
61
62 void KeyFrame::Loader::rotation(float a, float x, float y, float z)
63 {
64         obj.matrix.rotate_deg(a, x, y, z);
65 }
66
67 void KeyFrame::Loader::scaling_uniform(float s)
68 {
69         obj.matrix.scale(s);
70 }
71
72 void KeyFrame::Loader::scaling(float x, float y, float z)
73 {
74         obj.matrix.scale(x, y, z);
75 }
76
77 } // namespace GL
78 } // namespace Msp