]> git.tdb.fi Git - libs/gl.git/blob - source/keyframe.cpp
Fix various issues with constant condition elimination
[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 // Avoid synthesizing RefPtr c'tor and d'tor in files including keyframe.h
11 KeyFrame::KeyFrame()
12 { }
13
14 KeyFrame::~KeyFrame()
15 { }
16
17 void KeyFrame::set_matrix(const Matrix &m)
18 {
19         matrix = m;
20 }
21
22 void KeyFrame::set_pose(const Pose &p)
23 {
24         pose = &p;
25         pose.keep();
26 }
27
28
29 KeyFrame::AnimatedUniform::AnimatedUniform(unsigned s, float v0, float v1, float v2, float v3):
30         size(s)
31 {
32         values[0] = v0;
33         values[1] = v1;
34         values[2] = v2;
35         values[3] = v3;
36 }
37
38
39 KeyFrame::Loader::Loader(KeyFrame &k):
40         DataFile::CollectionObjectLoader<KeyFrame>(k, 0)
41 {
42         init();
43 }
44
45 KeyFrame::Loader::Loader(KeyFrame &k, Collection &c):
46         DataFile::CollectionObjectLoader<KeyFrame>(k, &c)
47 {
48         init();
49 }
50
51 void KeyFrame::Loader::init()
52 {
53         add("pose", &Loader::pose);
54         add("pose", &Loader::pose_inline);
55         add("position", &Loader::position);
56         add("rotation", &Loader::rotation);
57         add("scaling", &Loader::scaling_uniform);
58         add("scaling", &Loader::scaling);
59         add("uniforms", &Loader::uniforms);
60 }
61
62 void KeyFrame::Loader::pose(const string &n)
63 {
64         obj.pose = &get_collection().get<Pose>(n);
65         obj.pose.keep();
66 }
67
68 void KeyFrame::Loader::pose_inline()
69 {
70         RefPtr<Pose> p = new Pose;
71         load_sub(*p, get_collection());
72         obj.pose = p;
73 }
74
75 void KeyFrame::Loader::position(float x, float y, float z)
76 {
77         obj.matrix.translate(x, y, z);
78 }
79
80 void KeyFrame::Loader::rotation(float a, float x, float y, float z)
81 {
82         obj.matrix.rotate_deg(a, x, y, z);
83 }
84
85 void KeyFrame::Loader::scaling_uniform(float s)
86 {
87         obj.matrix.scale(s);
88 }
89
90 void KeyFrame::Loader::scaling(float x, float y, float z)
91 {
92         obj.matrix.scale(x, y, z);
93 }
94
95 void KeyFrame::Loader::uniforms()
96 {
97         UniformsLoader ldr(obj);
98         load_sub_with(ldr);
99 }
100
101
102 KeyFrame::UniformsLoader::UniformsLoader(KeyFrame &k):
103         DataFile::ObjectLoader<KeyFrame>(k)
104 {
105         add("uniform1f", &UniformsLoader::uniform1f);
106         add("uniform2f", &UniformsLoader::uniform2f);
107         add("uniform3f", &UniformsLoader::uniform3f);
108         add("uniform4f", &UniformsLoader::uniform4f);
109 }
110
111 void KeyFrame::UniformsLoader::uniform1f(const string &n, float v)
112 {
113         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(1, v)));
114 }
115
116 void KeyFrame::UniformsLoader::uniform2f(const string &n, float v0, float v1)
117 {
118         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(2, v0, v1)));
119 }
120
121 void KeyFrame::UniformsLoader::uniform3f(const string &n, float v0, float v1, float v2)
122 {
123         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(3, v0, v1, v2)));
124 }
125
126 void KeyFrame::UniformsLoader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
127 {
128         obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(4, v0, v1, v2, v3)));
129 }
130
131 } // namespace GL
132 } // namespace Msp