]> git.tdb.fi Git - libs/gl.git/blob - source/animation/keyframe.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / animation / keyframe.cpp
1 #include <msp/datafile/collection.h>
2 #include <msp/fs/utils.h>
3 #include "keyframe.h"
4 #include "pose.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 void KeyFrame::set_transform(const Transform &t)
12 {
13         transform = t;
14 }
15
16 void KeyFrame::set_matrix(const Matrix &m)
17 {
18         transform = Transform::from_matrix(m);
19 }
20
21 void KeyFrame::set_uniform(const string &n, const AnimatedUniform &u)
22 {
23         uniforms.erase(n);
24         uniforms.insert(UniformMap::value_type(n, u));
25 }
26
27 void KeyFrame::set_pose(const Pose &p)
28 {
29         pose = &p;
30 }
31
32
33 KeyFrame::AnimatedUniform::AnimatedUniform(unsigned s, float v0, float v1, float v2, float v3):
34         size(s)
35 {
36         values[0] = v0;
37         values[1] = v1;
38         values[2] = v2;
39         values[3] = v3;
40 }
41
42
43 KeyFrame::Loader::Loader(KeyFrame &k, Collection *c):
44         DataFile::CollectionObjectLoader<KeyFrame>(k, c)
45 {
46         add("pose", &Loader::pose);
47         add("pose", &Loader::pose_inline);
48         add("transform", &Loader::transform);
49         add("uniforms", &Loader::uniforms);
50
51         // Deprecated; use the transform statement instead
52         add("position", &Loader::position);
53         add("rotation", &Loader::rotation);
54         add("scaling", &Loader::scaling_uniform);
55         add("scaling", &Loader::scaling);
56 }
57
58 void KeyFrame::Loader::set_inline_base_name(const string &n)
59 {
60         inline_base_name = n;
61 }
62
63 void KeyFrame::Loader::pose(const string &n)
64 {
65         obj.pose = &get_collection().get<Pose>(n);
66 }
67
68 void KeyFrame::Loader::pose_inline()
69 {
70         RefPtr<Pose> p = new Pose;
71         load_sub(*p, get_collection());
72         get_collection().add((inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name)+".pose", p.get());
73         obj.pose = p.release();
74 }
75
76 void KeyFrame::Loader::position(float x, float y, float z)
77 {
78         obj.transform.set_position(Vector3(x, y, z));
79 }
80
81 void KeyFrame::Loader::rotation(float a, float x, float y, float z)
82 {
83         obj.transform.set_rotation(Transform::Angle::from_degrees(a), Vector3(x, y, z));
84 }
85
86 void KeyFrame::Loader::scaling_uniform(float s)
87 {
88         obj.transform.set_scale(s);
89 }
90
91 void KeyFrame::Loader::scaling(float x, float y, float z)
92 {
93         obj.transform.set_scale(Vector3(x, y, z));
94 }
95
96 void KeyFrame::Loader::transform()
97 {
98         load_sub(obj.transform);
99 }
100
101 void KeyFrame::Loader::uniforms()
102 {
103         UniformsLoader ldr(obj);
104         load_sub_with(ldr);
105 }
106
107
108 KeyFrame::UniformsLoader::UniformsLoader(KeyFrame &k):
109         DataFile::ObjectLoader<KeyFrame>(k)
110 {
111         add("uniform", &UniformsLoader::uniform1f);
112         add("uniform", &UniformsLoader::uniform2f);
113         add("uniform", &UniformsLoader::uniform3f);
114         add("uniform", &UniformsLoader::uniform4f);
115
116         // Deprecated
117         add("uniform1f", &UniformsLoader::uniform1f);
118         add("uniform2f", &UniformsLoader::uniform2f);
119         add("uniform3f", &UniformsLoader::uniform3f);
120         add("uniform4f", &UniformsLoader::uniform4f);
121 }
122
123 void KeyFrame::UniformsLoader::uniform1f(const string &n, float v)
124 {
125         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(1, v)));
126 }
127
128 void KeyFrame::UniformsLoader::uniform2f(const string &n, float v0, float v1)
129 {
130         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(2, v0, v1)));
131 }
132
133 void KeyFrame::UniformsLoader::uniform3f(const string &n, float v0, float v1, float v2)
134 {
135         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(3, v0, v1, v2)));
136 }
137
138 void KeyFrame::UniformsLoader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
139 {
140         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(4, v0, v1, v2, v3)));
141 }
142
143 } // namespace GL
144 } // namespace Msp