rev |
line source |
nuclear@54
|
1 /*
|
nuclear@54
|
2 goat3d - 3D scene, character, and animation file format library.
|
nuclear@54
|
3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
|
nuclear@54
|
4
|
nuclear@54
|
5 This program is free software: you can redistribute it and/or modify
|
nuclear@54
|
6 it under the terms of the GNU Lesser General Public License as published by
|
nuclear@54
|
7 the Free Software Foundation, either version 3 of the License, or
|
nuclear@54
|
8 (at your option) any later version.
|
nuclear@54
|
9
|
nuclear@54
|
10 This program is distributed in the hope that it will be useful,
|
nuclear@54
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
nuclear@54
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
nuclear@54
|
13 GNU Lesser General Public License for more details.
|
nuclear@54
|
14
|
nuclear@54
|
15 You should have received a copy of the GNU Lesser General Public License
|
nuclear@54
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
nuclear@54
|
17 */
|
nuclear@1
|
18 #ifndef XFORM_NODE_H_
|
nuclear@1
|
19 #define XFORM_NODE_H_
|
nuclear@1
|
20
|
nuclear@1
|
21 #include <vector>
|
nuclear@1
|
22 #include "vmath/vector.h"
|
nuclear@1
|
23 #include "vmath/quat.h"
|
nuclear@1
|
24 #include "vmath/matrix.h"
|
nuclear@1
|
25
|
nuclear@1
|
26
|
nuclear@1
|
27 struct anm_node;
|
nuclear@1
|
28 struct anm_track;
|
nuclear@1
|
29
|
nuclear@47
|
30 namespace g3dimpl {
|
nuclear@47
|
31
|
nuclear@47
|
32 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
|
nuclear@47
|
33 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
|
nuclear@47
|
34
|
nuclear@47
|
35 // NOTE: all time arguments are milliseconds
|
nuclear@1
|
36
|
nuclear@1
|
37 class XFormNode {
|
nuclear@1
|
38 private:
|
nuclear@1
|
39 struct anm_node *anm;
|
nuclear@1
|
40 std::vector<XFormNode*> children;
|
nuclear@30
|
41 XFormNode *parent;
|
nuclear@1
|
42
|
nuclear@1
|
43 Interp interp;
|
nuclear@1
|
44 Extrap extrap;
|
nuclear@1
|
45
|
nuclear@1
|
46 Matrix4x4 local_matrix;
|
nuclear@1
|
47 Matrix4x4 bone_matrix;
|
nuclear@1
|
48
|
nuclear@1
|
49 XFormNode(const XFormNode &node) {}
|
nuclear@1
|
50 XFormNode &operator =(const XFormNode &node) { return *this; }
|
nuclear@1
|
51
|
nuclear@1
|
52 public:
|
nuclear@48
|
53 enum { POSITION_TRACK, ROTATION_TRACK, SCALING_TRACK };
|
nuclear@48
|
54
|
nuclear@1
|
55 XFormNode();
|
nuclear@1
|
56 virtual ~XFormNode();
|
nuclear@1
|
57
|
nuclear@47
|
58 // retrieve the pointer to the underlying libanim data structure
|
nuclear@47
|
59 virtual struct anm_node *get_libanim_node() const;
|
nuclear@47
|
60
|
nuclear@8
|
61 virtual void set_name(const char *name);
|
nuclear@8
|
62 virtual const char *get_name() const;
|
nuclear@1
|
63
|
nuclear@8
|
64 virtual void set_interpolator(Interp in);
|
nuclear@8
|
65 virtual Interp get_interpolator() const;
|
nuclear@8
|
66 virtual void set_extrapolator(Extrap ex);
|
nuclear@8
|
67 virtual Extrap get_extrapolator() const;
|
nuclear@1
|
68
|
nuclear@47
|
69 virtual XFormNode *get_parent();
|
nuclear@47
|
70 virtual const XFormNode *get_parent() const;
|
nuclear@47
|
71
|
nuclear@1
|
72 // children management
|
nuclear@8
|
73 virtual void add_child(XFormNode *child);
|
nuclear@8
|
74 virtual void remove_child(XFormNode *child);
|
nuclear@1
|
75
|
nuclear@8
|
76 virtual int get_children_count() const;
|
nuclear@8
|
77 virtual XFormNode *get_child(int idx);
|
nuclear@8
|
78 virtual const XFormNode *get_child(int idx) const;
|
nuclear@1
|
79
|
nuclear@47
|
80
|
nuclear@47
|
81 virtual void use_animation(int idx);
|
nuclear@47
|
82 virtual void use_animation(const char *name);
|
nuclear@47
|
83 virtual void use_animation(int aidx, int bidx, float t);
|
nuclear@47
|
84 virtual void use_animation(const char *aname, const char *bname, float t);
|
nuclear@47
|
85
|
nuclear@47
|
86 virtual int get_active_animation_index(int which = 0) const;
|
nuclear@47
|
87 virtual float get_active_animation_mix() const;
|
nuclear@47
|
88
|
nuclear@47
|
89 virtual int get_animation_count() const;
|
nuclear@47
|
90
|
nuclear@47
|
91 // add a new empty animation slot (recursive)
|
nuclear@47
|
92 virtual void add_animation(const char *name = 0);
|
nuclear@47
|
93
|
nuclear@47
|
94 // set/get the current animation name (set is recursive)
|
nuclear@47
|
95 virtual void set_animation_name(const char *name);
|
nuclear@47
|
96 virtual const char *get_animation_name() const;
|
nuclear@47
|
97
|
nuclear@48
|
98 // raw keyframe retrieval without interpolation
|
nuclear@48
|
99 // NOTE: trackid parameters correspond to the values of the unnamed enumeration at the top
|
nuclear@48
|
100
|
nuclear@48
|
101 virtual int get_key_count(int trackid) const;
|
nuclear@48
|
102 virtual int get_position_key_count() const;
|
nuclear@48
|
103 virtual int get_rotation_key_count() const;
|
nuclear@48
|
104 virtual int get_scaling_key_count() const;
|
nuclear@48
|
105
|
nuclear@48
|
106 virtual long get_key_time(int trackid, int idx) const;
|
nuclear@48
|
107 virtual long get_position_key_time(int idx) const;
|
nuclear@48
|
108 virtual long get_rotation_key_time(int idx) const;
|
nuclear@48
|
109 virtual long get_scaling_key_time(int idx) const;
|
nuclear@48
|
110
|
nuclear@48
|
111 /* writes the key value through the val pointer, and returns the number
|
nuclear@48
|
112 * of elements in that value (3 for pos/scale, 4 for rotation).
|
nuclear@48
|
113 */
|
nuclear@48
|
114 virtual int get_key_value(int trackid, int idx, float *val) const;
|
nuclear@48
|
115 virtual Vector3 get_position_key_value(int idx) const;
|
nuclear@48
|
116 virtual Quaternion get_rotation_key_value(int idx) const;
|
nuclear@48
|
117 virtual Vector3 get_scaling_key_value(int idx) const;
|
nuclear@48
|
118
|
nuclear@1
|
119
|
nuclear@8
|
120 virtual void set_position(const Vector3 &pos, long tmsec = 0);
|
nuclear@8
|
121 virtual Vector3 get_node_position(long tmsec = 0) const;
|
nuclear@1
|
122
|
nuclear@8
|
123 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
|
nuclear@8
|
124 virtual Quaternion get_node_rotation(long tmsec = 0) const;
|
nuclear@1
|
125
|
nuclear@8
|
126 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
|
nuclear@8
|
127 virtual Vector3 get_node_scaling(long tmsec = 0) const;
|
nuclear@1
|
128
|
nuclear@1
|
129 // these take hierarchy into account
|
nuclear@8
|
130 virtual Vector3 get_position(long tmsec = 0) const;
|
nuclear@8
|
131 virtual Quaternion get_rotation(long tmsec = 0) const;
|
nuclear@8
|
132 virtual Vector3 get_scaling(long tmsec = 0) const;
|
nuclear@1
|
133
|
nuclear@8
|
134 virtual void set_pivot(const Vector3 &pivot);
|
nuclear@8
|
135 virtual Vector3 get_pivot() const;
|
nuclear@1
|
136
|
nuclear@1
|
137 // the local matrix is concatenated with the regular node/anim matrix
|
nuclear@8
|
138 virtual void set_local_matrix(const Matrix4x4 &mat);
|
nuclear@8
|
139 virtual const Matrix4x4 &get_local_matrix() const;
|
nuclear@1
|
140
|
nuclear@1
|
141 // for bone nodes, the transformation of the bone in bind position
|
nuclear@8
|
142 virtual void set_bone_matrix(const Matrix4x4 &bmat);
|
nuclear@8
|
143 virtual const Matrix4x4 &get_bone_matrix() const;
|
nuclear@1
|
144
|
nuclear@1
|
145 // node transformation alone
|
nuclear@8
|
146 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
|
nuclear@1
|
147
|
nuclear@1
|
148 // node transformation taking hierarchy into account
|
nuclear@8
|
149 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
|
nuclear@1
|
150 };
|
nuclear@1
|
151
|
nuclear@1
|
152
|
nuclear@1
|
153 class Track {
|
nuclear@1
|
154 private:
|
nuclear@1
|
155 struct anm_track *trk;
|
nuclear@1
|
156 Interp interp;
|
nuclear@1
|
157 Extrap extrap;
|
nuclear@1
|
158
|
nuclear@1
|
159 public:
|
nuclear@1
|
160 Track();
|
nuclear@1
|
161 ~Track();
|
nuclear@1
|
162
|
nuclear@1
|
163 Track(const Track &trk);
|
nuclear@1
|
164 Track &operator =(const Track &trk);
|
nuclear@1
|
165
|
nuclear@1
|
166 void set_interpolator(Interp in);
|
nuclear@1
|
167 Interp get_interpolator() const;
|
nuclear@1
|
168 void set_extrapolator(Extrap ex);
|
nuclear@1
|
169 Extrap get_extrapolator() const;
|
nuclear@1
|
170
|
nuclear@1
|
171 void set_default(double def);
|
nuclear@1
|
172
|
nuclear@1
|
173 void set_value(float val, long tmsec = 0);
|
nuclear@1
|
174 float get_value(long tmsec = 0) const;
|
nuclear@1
|
175
|
nuclear@1
|
176 // the same as get_value
|
nuclear@1
|
177 float operator ()(long tmsec = 0) const;
|
nuclear@1
|
178 };
|
nuclear@1
|
179
|
nuclear@1
|
180 class Track3 {
|
nuclear@1
|
181 private:
|
nuclear@1
|
182 Track track[3];
|
nuclear@1
|
183
|
nuclear@1
|
184 public:
|
nuclear@1
|
185 void set_interpolator(Interp in);
|
nuclear@1
|
186 Interp get_interpolator() const;
|
nuclear@1
|
187 void set_extrapolator(Extrap ex);
|
nuclear@1
|
188 Extrap get_extrapolator() const;
|
nuclear@1
|
189
|
nuclear@1
|
190 void set_default(const Vector3 &def);
|
nuclear@1
|
191
|
nuclear@1
|
192 void set_value(const Vector3 &val, long tmsec = 0);
|
nuclear@1
|
193 Vector3 get_value(long tmsec = 0) const;
|
nuclear@1
|
194
|
nuclear@1
|
195 // the same as get_value
|
nuclear@1
|
196 Vector3 operator ()(long tmsec = 0) const;
|
nuclear@1
|
197 };
|
nuclear@1
|
198
|
nuclear@47
|
199 } // namespace g3dimpl
|
nuclear@47
|
200
|
nuclear@1
|
201 #endif /* XFORM_NODE_H_ */
|