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