]> git.tdb.fi Git - libs/gl.git/blob - source/animation/animatedobject.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / animation / animatedobject.cpp
1 #include <algorithm>
2 #include <msp/strings/format.h>
3 #include "animatedobject.h"
4 #include "error.h"
5 #include "object.h"
6 #include "programdata.h"
7 #include "renderer.h"
8 #include "technique.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace GL {
14
15 AnimatedObject::AnimatedObject(const Object &o):
16         ObjectInstance(o)
17 { }
18
19 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
20 {
21         if(link*16>=pose_data.size())
22                 pose_data.resize((link+1)*16);
23         copy(m.data(), m.data()+16, &pose_data[link*16]);
24         shdata.uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
25 }
26
27 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
28 {
29         if(uni.size==1)
30                 shdata.uniform(name, uni.values[0]);
31         else if(uni.size==2)
32                 shdata.uniform2(name, uni.values);
33         else if(uni.size==3)
34                 shdata.uniform3(name, uni.values);
35         else if(uni.size==4)
36                 shdata.uniform4(name, uni.values);
37         else
38                 throw invalid_argument("AnimatedObject::set_uniform");
39 }
40
41 void AnimatedObject::setup_render(Renderer &renderer, Tag) const
42 {
43         renderer.set_matrix(matrix);
44         renderer.add_shader_data(shdata);
45 }
46
47
48 AnimatedObject::Loader::Loader(AnimatedObject &o):
49         DataFile::DerivedObjectLoader<AnimatedObject, ObjectInstance::Loader>(o)
50 {
51         // Deprecated; Use the transform statement defined in ObjectInstance instead
52         add("position", &Loader::position);
53         add("rotation", &Loader::rotation);
54         add("scale", &Loader::scale);
55         add("scale", &Loader::scale_uniform);
56 }
57
58 void AnimatedObject::Loader::position(float x, float y, float z)
59 {
60         obj.matrix.translate(x, y, z);
61 }
62
63 void AnimatedObject::Loader::rotation(float a, float x, float y, float z)
64 {
65         obj.matrix.rotate_deg(a, x, y, z);
66 }
67
68 void AnimatedObject::Loader::scale(float x, float y, float z)
69 {
70         obj.matrix.scale(x, y, z);
71 }
72
73 void AnimatedObject::Loader::scale_uniform(float s)
74 {
75         obj.matrix.scale(s);
76 }
77
78 } // namespace GL
79 } // namespace Msp