goat3d

view src/xform_node.h @ 47:498ca7ac7047

- placed all the implementation stuff in the g3dimpl namespace - added animation stuff to the public API - started writing animation saving/loading
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Dec 2013 06:47:39 +0200
parents 0fe02696fb1e
children 9ef9de80649c
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 XFormNode();
37 virtual ~XFormNode();
39 // retrieve the pointer to the underlying libanim data structure
40 virtual struct anm_node *get_libanim_node() const;
42 virtual void set_name(const char *name);
43 virtual const char *get_name() const;
45 virtual void set_interpolator(Interp in);
46 virtual Interp get_interpolator() const;
47 virtual void set_extrapolator(Extrap ex);
48 virtual Extrap get_extrapolator() const;
50 virtual XFormNode *get_parent();
51 virtual const XFormNode *get_parent() const;
53 // children management
54 virtual void add_child(XFormNode *child);
55 virtual void remove_child(XFormNode *child);
57 virtual int get_children_count() const;
58 virtual XFormNode *get_child(int idx);
59 virtual const XFormNode *get_child(int idx) const;
62 virtual void use_animation(int idx);
63 virtual void use_animation(const char *name);
64 virtual void use_animation(int aidx, int bidx, float t);
65 virtual void use_animation(const char *aname, const char *bname, float t);
67 virtual int get_active_animation_index(int which = 0) const;
68 virtual float get_active_animation_mix() const;
70 virtual int get_animation_count() const;
72 // add a new empty animation slot (recursive)
73 virtual void add_animation(const char *name = 0);
75 // set/get the current animation name (set is recursive)
76 virtual void set_animation_name(const char *name);
77 virtual const char *get_animation_name() const;
80 virtual void set_position(const Vector3 &pos, long tmsec = 0);
81 virtual Vector3 get_node_position(long tmsec = 0) const;
83 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
84 virtual Quaternion get_node_rotation(long tmsec = 0) const;
86 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
87 virtual Vector3 get_node_scaling(long tmsec = 0) const;
89 // these take hierarchy into account
90 virtual Vector3 get_position(long tmsec = 0) const;
91 virtual Quaternion get_rotation(long tmsec = 0) const;
92 virtual Vector3 get_scaling(long tmsec = 0) const;
94 virtual void set_pivot(const Vector3 &pivot);
95 virtual Vector3 get_pivot() const;
97 // the local matrix is concatenated with the regular node/anim matrix
98 virtual void set_local_matrix(const Matrix4x4 &mat);
99 virtual const Matrix4x4 &get_local_matrix() const;
101 // for bone nodes, the transformation of the bone in bind position
102 virtual void set_bone_matrix(const Matrix4x4 &bmat);
103 virtual const Matrix4x4 &get_bone_matrix() const;
105 // node transformation alone
106 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
108 // node transformation taking hierarchy into account
109 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
110 };
113 class Track {
114 private:
115 struct anm_track *trk;
116 Interp interp;
117 Extrap extrap;
119 public:
120 Track();
121 ~Track();
123 Track(const Track &trk);
124 Track &operator =(const Track &trk);
126 void set_interpolator(Interp in);
127 Interp get_interpolator() const;
128 void set_extrapolator(Extrap ex);
129 Extrap get_extrapolator() const;
131 void set_default(double def);
133 void set_value(float val, long tmsec = 0);
134 float get_value(long tmsec = 0) const;
136 // the same as get_value
137 float operator ()(long tmsec = 0) const;
138 };
140 class Track3 {
141 private:
142 Track track[3];
144 public:
145 void set_interpolator(Interp in);
146 Interp get_interpolator() const;
147 void set_extrapolator(Extrap ex);
148 Extrap get_extrapolator() const;
150 void set_default(const Vector3 &def);
152 void set_value(const Vector3 &val, long tmsec = 0);
153 Vector3 get_value(long tmsec = 0) const;
155 // the same as get_value
156 Vector3 operator ()(long tmsec = 0) const;
157 };
159 } // namespace g3dimpl
161 #endif /* XFORM_NODE_H_ */