goat3dgfx

view src/xform_node.h @ 21:7c593721547f

integrated support for the multiple animation system of libanim
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Dec 2013 11:59:32 +0200
parents 7d6b667821cf
children 92bfb0206969
line source
1 #ifndef XFORM_NODE_H_
2 #define XFORM_NODE_H_
4 #include <vector>
5 #include "vmath/vector.h"
6 #include "vmath/quat.h"
7 #include "vmath/matrix.h"
10 struct anm_node;
11 struct anm_track;
13 namespace goatgfx {
15 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
16 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
18 // NOTE: all time arguments are milliseconds
20 class XFormNode {
21 private:
22 struct anm_node *anm;
23 std::vector<XFormNode*> children;
25 Interp interp;
26 Extrap extrap;
28 Matrix4x4 local_matrix;
29 Matrix4x4 bone_matrix;
31 XFormNode(const XFormNode &node) {}
32 XFormNode &operator =(const XFormNode &node) { return *this; }
34 public:
35 XFormNode();
36 virtual ~XFormNode();
38 void set_name(const char *name);
39 const char *get_name() const;
41 void set_interpolator(Interp in);
42 Interp get_interpolator() const;
43 void set_extrapolator(Extrap ex);
44 Extrap get_extrapolator() const;
46 // children management
47 void add_child(XFormNode *child);
48 void remove_child(XFormNode *child);
50 int get_children_count() const;
51 XFormNode *get_child(int idx);
52 const XFormNode *get_child(int idx) const;
55 void use_animation(int idx);
56 void use_animation(const char *name);
57 void use_animation(int aidx, int bidx, float t);
58 void use_animation(const char *aname, const char *bname, float t);
60 int get_active_animation_index(int which = 0) const;
61 float get_active_animation_mix() const;
63 int get_animation_count() const;
65 // add a new empty animation slot (recursive)
66 void add_animation(const char *name = 0);
68 // set/get the current animation name (set is recursive)
69 void set_animation_name(const char *name);
70 const char *get_animation_name() const;
73 void set_position(const Vector3 &pos, long tmsec = 0);
74 Vector3 get_node_position(long tmsec = 0) const;
76 void set_rotation(const Quaternion &quat, long tmsec = 0);
77 Quaternion get_node_rotation(long tmsec = 0) const;
79 void set_scaling(const Vector3 &pos, long tmsec = 0);
80 Vector3 get_node_scaling(long tmsec = 0) const;
82 // these take hierarchy into account
83 Vector3 get_position(long tmsec = 0) const;
84 Quaternion get_rotation(long tmsec = 0) const;
85 Vector3 get_scaling(long tmsec = 0) const;
87 void set_pivot(const Vector3 &pivot);
88 Vector3 get_pivot() const;
90 // the local matrix is concatenated with the regular node/anim matrix
91 void set_local_matrix(const Matrix4x4 &mat);
92 const Matrix4x4 &get_local_matrix() const;
94 // for bone nodes, the transformation of the bone in bind position
95 void set_bone_matrix(const Matrix4x4 &bmat);
96 const Matrix4x4 &get_bone_matrix() const;
98 // node transformation alone
99 void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
101 // node transformation taking hierarchy into account
102 void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
103 };
106 class Track {
107 private:
108 struct anm_track *trk;
109 Interp interp;
110 Extrap extrap;
112 public:
113 Track();
114 ~Track();
116 Track(const Track &trk);
117 Track &operator =(const Track &trk);
119 void set_interpolator(Interp in);
120 Interp get_interpolator() const;
121 void set_extrapolator(Extrap ex);
122 Extrap get_extrapolator() const;
124 void set_default(double def);
126 void set_value(float val, long tmsec = 0);
127 float get_value(long tmsec = 0) const;
129 // the same as get_value
130 float operator ()(long tmsec = 0) const;
131 };
133 class Track3 {
134 private:
135 Track track[3];
137 public:
138 void set_interpolator(Interp in);
139 Interp get_interpolator() const;
140 void set_extrapolator(Extrap ex);
141 Extrap get_extrapolator() const;
143 void set_default(const Vector3 &def);
145 void set_value(const Vector3 &val, long tmsec = 0);
146 Vector3 get_value(long tmsec = 0) const;
148 // the same as get_value
149 Vector3 operator ()(long tmsec = 0) const;
150 };
152 } // namespace goatgfx
154 #endif /* XFORM_NODE_H_ */