rev |
line source |
nuclear@13
|
1 #ifndef GOATGFX_XFORM_NODE_H_
|
nuclear@13
|
2 #define GOATGFX_XFORM_NODE_H_
|
nuclear@13
|
3
|
nuclear@13
|
4 #include <vector>
|
nuclear@13
|
5 #include "vmath/vector.h"
|
nuclear@13
|
6 #include "vmath/quat.h"
|
nuclear@13
|
7 #include "vmath/matrix.h"
|
nuclear@13
|
8
|
nuclear@13
|
9
|
nuclear@13
|
10 struct anm_node;
|
nuclear@13
|
11 struct anm_track;
|
nuclear@13
|
12
|
nuclear@13
|
13 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
|
nuclear@13
|
14 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
|
nuclear@13
|
15
|
nuclear@13
|
16 // NOTE: all time arguments are milliseconds
|
nuclear@13
|
17
|
nuclear@13
|
18 class XFormNode {
|
nuclear@13
|
19 private:
|
nuclear@13
|
20 struct anm_node *anm;
|
nuclear@13
|
21 std::vector<XFormNode*> children;
|
nuclear@13
|
22 XFormNode *parent;
|
nuclear@13
|
23
|
nuclear@13
|
24 Interp interp;
|
nuclear@13
|
25 Extrap extrap;
|
nuclear@13
|
26
|
nuclear@13
|
27 Matrix4x4 local_matrix;
|
nuclear@13
|
28 Matrix4x4 bone_matrix;
|
nuclear@13
|
29
|
nuclear@13
|
30 XFormNode(const XFormNode &node) {}
|
nuclear@13
|
31 XFormNode &operator =(const XFormNode &node) { return *this; }
|
nuclear@13
|
32
|
nuclear@13
|
33 public:
|
nuclear@13
|
34 XFormNode();
|
nuclear@13
|
35 virtual ~XFormNode();
|
nuclear@13
|
36
|
nuclear@13
|
37 virtual void set_name(const char *name);
|
nuclear@13
|
38 virtual const char *get_name() const;
|
nuclear@13
|
39
|
nuclear@13
|
40 virtual void set_interpolator(Interp in);
|
nuclear@13
|
41 virtual Interp get_interpolator() const;
|
nuclear@13
|
42 virtual void set_extrapolator(Extrap ex);
|
nuclear@13
|
43 virtual Extrap get_extrapolator() const;
|
nuclear@13
|
44
|
nuclear@13
|
45 virtual XFormNode *get_parent();
|
nuclear@13
|
46 virtual const XFormNode *get_parent() const;
|
nuclear@13
|
47
|
nuclear@13
|
48 // children management
|
nuclear@13
|
49 virtual void add_child(XFormNode *child);
|
nuclear@13
|
50 virtual void remove_child(XFormNode *child);
|
nuclear@13
|
51
|
nuclear@13
|
52 virtual int get_children_count() const;
|
nuclear@13
|
53 virtual XFormNode *get_child(int idx);
|
nuclear@13
|
54 virtual const XFormNode *get_child(int idx) const;
|
nuclear@13
|
55
|
nuclear@13
|
56
|
nuclear@13
|
57 virtual void use_animation(int idx);
|
nuclear@13
|
58 virtual void use_animation(const char *name);
|
nuclear@13
|
59 virtual void use_animation(int aidx, int bidx, float t);
|
nuclear@13
|
60 virtual void use_animation(const char *aname, const char *bname, float t);
|
nuclear@13
|
61
|
nuclear@13
|
62 virtual int get_active_animation_index(int which = 0) const;
|
nuclear@13
|
63 virtual float get_active_animation_mix() const;
|
nuclear@13
|
64
|
nuclear@13
|
65 virtual int get_animation_count() const;
|
nuclear@13
|
66
|
nuclear@13
|
67 // add a new empty animation slot (recursive)
|
nuclear@13
|
68 virtual void add_animation(const char *name = 0);
|
nuclear@13
|
69
|
nuclear@13
|
70 // set/get the current animation name (set is recursive)
|
nuclear@13
|
71 virtual void set_animation_name(const char *name);
|
nuclear@13
|
72 virtual const char *get_animation_name() const;
|
nuclear@13
|
73
|
nuclear@13
|
74
|
nuclear@13
|
75 virtual void set_position(const Vector3 &pos, long tmsec = 0);
|
nuclear@13
|
76 virtual Vector3 get_node_position(long tmsec = 0) const;
|
nuclear@13
|
77
|
nuclear@13
|
78 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
|
nuclear@13
|
79 virtual Quaternion get_node_rotation(long tmsec = 0) const;
|
nuclear@13
|
80
|
nuclear@13
|
81 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
|
nuclear@13
|
82 virtual Vector3 get_node_scaling(long tmsec = 0) const;
|
nuclear@13
|
83
|
nuclear@13
|
84 // these take hierarchy into account
|
nuclear@13
|
85 virtual Vector3 get_position(long tmsec = 0) const;
|
nuclear@13
|
86 virtual Quaternion get_rotation(long tmsec = 0) const;
|
nuclear@13
|
87 virtual Vector3 get_scaling(long tmsec = 0) const;
|
nuclear@13
|
88
|
nuclear@13
|
89 virtual void set_pivot(const Vector3 &pivot);
|
nuclear@13
|
90 virtual Vector3 get_pivot() const;
|
nuclear@13
|
91
|
nuclear@13
|
92 // the local matrix is concatenated with the regular node/anim matrix
|
nuclear@13
|
93 virtual void set_local_matrix(const Matrix4x4 &mat);
|
nuclear@13
|
94 virtual const Matrix4x4 &get_local_matrix() const;
|
nuclear@13
|
95
|
nuclear@13
|
96 // for bone nodes, the transformation of the bone in bind position
|
nuclear@13
|
97 virtual void set_bone_matrix(const Matrix4x4 &bmat);
|
nuclear@13
|
98 virtual const Matrix4x4 &get_bone_matrix() const;
|
nuclear@13
|
99
|
nuclear@13
|
100 // node transformation alone
|
nuclear@13
|
101 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
|
nuclear@13
|
102
|
nuclear@13
|
103 // node transformation taking hierarchy into account
|
nuclear@13
|
104 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
|
nuclear@13
|
105 };
|
nuclear@13
|
106
|
nuclear@13
|
107
|
nuclear@13
|
108 class Track {
|
nuclear@13
|
109 private:
|
nuclear@13
|
110 struct anm_track *trk;
|
nuclear@13
|
111 Interp interp;
|
nuclear@13
|
112 Extrap extrap;
|
nuclear@13
|
113
|
nuclear@13
|
114 public:
|
nuclear@13
|
115 Track();
|
nuclear@13
|
116 ~Track();
|
nuclear@13
|
117
|
nuclear@13
|
118 Track(const Track &trk);
|
nuclear@13
|
119 Track &operator =(const Track &trk);
|
nuclear@13
|
120
|
nuclear@13
|
121 void set_interpolator(Interp in);
|
nuclear@13
|
122 Interp get_interpolator() const;
|
nuclear@13
|
123 void set_extrapolator(Extrap ex);
|
nuclear@13
|
124 Extrap get_extrapolator() const;
|
nuclear@13
|
125
|
nuclear@13
|
126 void set_default(double def);
|
nuclear@13
|
127
|
nuclear@13
|
128 void set_value(float val, long tmsec = 0);
|
nuclear@13
|
129 float get_value(long tmsec = 0) const;
|
nuclear@13
|
130
|
nuclear@13
|
131 // the same as get_value
|
nuclear@13
|
132 float operator ()(long tmsec = 0) const;
|
nuclear@13
|
133 };
|
nuclear@13
|
134
|
nuclear@13
|
135 class Track3 {
|
nuclear@13
|
136 private:
|
nuclear@13
|
137 Track track[3];
|
nuclear@13
|
138
|
nuclear@13
|
139 public:
|
nuclear@13
|
140 void set_interpolator(Interp in);
|
nuclear@13
|
141 Interp get_interpolator() const;
|
nuclear@13
|
142 void set_extrapolator(Extrap ex);
|
nuclear@13
|
143 Extrap get_extrapolator() const;
|
nuclear@13
|
144
|
nuclear@13
|
145 void set_default(const Vector3 &def);
|
nuclear@13
|
146
|
nuclear@13
|
147 void set_value(const Vector3 &val, long tmsec = 0);
|
nuclear@13
|
148 Vector3 get_value(long tmsec = 0) const;
|
nuclear@13
|
149
|
nuclear@13
|
150 // the same as get_value
|
nuclear@13
|
151 Vector3 operator ()(long tmsec = 0) const;
|
nuclear@13
|
152 };
|
nuclear@13
|
153
|
nuclear@13
|
154 #endif /* GOATGFX_XFORM_NODE_H_ */
|