goat3d

view src/xform_node.h @ 55:af1310ed212b

not done yet
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 19 Jan 2014 14:56:44 +0200
parents 498ca7ac7047
children dad392c710df
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 g3dimpl {
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;
24 XFormNode *parent;
26 Interp interp;
27 Extrap extrap;
29 Matrix4x4 local_matrix;
30 Matrix4x4 bone_matrix;
32 XFormNode(const XFormNode &node) {}
33 XFormNode &operator =(const XFormNode &node) { return *this; }
35 public:
36 enum { POSITION_TRACK, ROTATION_TRACK, SCALING_TRACK };
38 XFormNode();
39 virtual ~XFormNode();
41 // retrieve the pointer to the underlying libanim data structure
42 virtual struct anm_node *get_libanim_node() const;
44 virtual void set_name(const char *name);
45 virtual const char *get_name() const;
47 virtual void set_interpolator(Interp in);
48 virtual Interp get_interpolator() const;
49 virtual void set_extrapolator(Extrap ex);
50 virtual Extrap get_extrapolator() const;
52 virtual XFormNode *get_parent();
53 virtual const XFormNode *get_parent() const;
55 // children management
56 virtual void add_child(XFormNode *child);
57 virtual void remove_child(XFormNode *child);
59 virtual int get_children_count() const;
60 virtual XFormNode *get_child(int idx);
61 virtual const XFormNode *get_child(int idx) const;
64 virtual void use_animation(int idx);
65 virtual void use_animation(const char *name);
66 virtual void use_animation(int aidx, int bidx, float t);
67 virtual void use_animation(const char *aname, const char *bname, float t);
69 virtual int get_active_animation_index(int which = 0) const;
70 virtual float get_active_animation_mix() const;
72 virtual int get_animation_count() const;
74 // add a new empty animation slot (recursive)
75 virtual void add_animation(const char *name = 0);
77 // set/get the current animation name (set is recursive)
78 virtual void set_animation_name(const char *name);
79 virtual const char *get_animation_name() const;
81 // raw keyframe retrieval without interpolation
82 // NOTE: trackid parameters correspond to the values of the unnamed enumeration at the top
84 virtual int get_key_count(int trackid) const;
85 virtual int get_position_key_count() const;
86 virtual int get_rotation_key_count() const;
87 virtual int get_scaling_key_count() const;
89 virtual long get_key_time(int trackid, int idx) const;
90 virtual long get_position_key_time(int idx) const;
91 virtual long get_rotation_key_time(int idx) const;
92 virtual long get_scaling_key_time(int idx) const;
94 /* writes the key value through the val pointer, and returns the number
95 * of elements in that value (3 for pos/scale, 4 for rotation).
96 */
97 virtual int get_key_value(int trackid, int idx, float *val) const;
98 virtual Vector3 get_position_key_value(int idx) const;
99 virtual Quaternion get_rotation_key_value(int idx) const;
100 virtual Vector3 get_scaling_key_value(int idx) const;
103 virtual void set_position(const Vector3 &pos, long tmsec = 0);
104 virtual Vector3 get_node_position(long tmsec = 0) const;
106 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
107 virtual Quaternion get_node_rotation(long tmsec = 0) const;
109 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
110 virtual Vector3 get_node_scaling(long tmsec = 0) const;
112 // these take hierarchy into account
113 virtual Vector3 get_position(long tmsec = 0) const;
114 virtual Quaternion get_rotation(long tmsec = 0) const;
115 virtual Vector3 get_scaling(long tmsec = 0) const;
117 virtual void set_pivot(const Vector3 &pivot);
118 virtual Vector3 get_pivot() const;
120 // the local matrix is concatenated with the regular node/anim matrix
121 virtual void set_local_matrix(const Matrix4x4 &mat);
122 virtual const Matrix4x4 &get_local_matrix() const;
124 // for bone nodes, the transformation of the bone in bind position
125 virtual void set_bone_matrix(const Matrix4x4 &bmat);
126 virtual const Matrix4x4 &get_bone_matrix() const;
128 // node transformation alone
129 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
131 // node transformation taking hierarchy into account
132 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
133 };
136 class Track {
137 private:
138 struct anm_track *trk;
139 Interp interp;
140 Extrap extrap;
142 public:
143 Track();
144 ~Track();
146 Track(const Track &trk);
147 Track &operator =(const Track &trk);
149 void set_interpolator(Interp in);
150 Interp get_interpolator() const;
151 void set_extrapolator(Extrap ex);
152 Extrap get_extrapolator() const;
154 void set_default(double def);
156 void set_value(float val, long tmsec = 0);
157 float get_value(long tmsec = 0) const;
159 // the same as get_value
160 float operator ()(long tmsec = 0) const;
161 };
163 class Track3 {
164 private:
165 Track track[3];
167 public:
168 void set_interpolator(Interp in);
169 Interp get_interpolator() const;
170 void set_extrapolator(Extrap ex);
171 Extrap get_extrapolator() const;
173 void set_default(const Vector3 &def);
175 void set_value(const Vector3 &val, long tmsec = 0);
176 Vector3 get_value(long tmsec = 0) const;
178 // the same as get_value
179 Vector3 operator ()(long tmsec = 0) const;
180 };
182 } // namespace g3dimpl
184 #endif /* XFORM_NODE_H_ */