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