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 #include <assert.h>
|
nuclear@1
|
19 #include <algorithm>
|
nuclear@1
|
20 #include "xform_node.h"
|
nuclear@47
|
21 #include "anim/anim.h"
|
nuclear@47
|
22 #include "anim/track.h"
|
nuclear@47
|
23
|
nuclear@47
|
24 using namespace g3dimpl;
|
nuclear@1
|
25
|
nuclear@1
|
26 static inline anm_interpolator track_interpolator(Interp in);
|
nuclear@1
|
27 static inline anm_extrapolator track_extrapolator(Extrap ex);
|
nuclear@1
|
28
|
nuclear@1
|
29 XFormNode::XFormNode()
|
nuclear@1
|
30 {
|
nuclear@1
|
31 anm = new anm_node;
|
nuclear@1
|
32 anm_init_node(anm);
|
nuclear@47
|
33 parent = 0;
|
nuclear@30
|
34
|
nuclear@47
|
35 // TODO read them from anm to get the correct initial values
|
nuclear@47
|
36 interp = INTERP_LINEAR;
|
nuclear@47
|
37 extrap = EXTRAP_EXTEND;
|
nuclear@1
|
38 }
|
nuclear@1
|
39
|
nuclear@1
|
40 XFormNode::~XFormNode()
|
nuclear@1
|
41 {
|
nuclear@1
|
42 anm_destroy_node(anm);
|
nuclear@1
|
43 delete anm;
|
nuclear@1
|
44 }
|
nuclear@1
|
45
|
nuclear@47
|
46 struct anm_node *XFormNode::get_libanim_node() const
|
nuclear@47
|
47 {
|
nuclear@47
|
48 return anm;
|
nuclear@47
|
49 }
|
nuclear@47
|
50
|
nuclear@1
|
51 void XFormNode::set_name(const char *name)
|
nuclear@1
|
52 {
|
nuclear@1
|
53 anm_set_node_name(anm, name);
|
nuclear@1
|
54 }
|
nuclear@1
|
55
|
nuclear@1
|
56 const char *XFormNode::get_name() const
|
nuclear@1
|
57 {
|
nuclear@1
|
58 return anm_get_node_name(anm);
|
nuclear@1
|
59 }
|
nuclear@1
|
60
|
nuclear@1
|
61 void XFormNode::set_interpolator(Interp in)
|
nuclear@1
|
62 {
|
nuclear@1
|
63 anm_set_interpolator(anm, track_interpolator(in));
|
nuclear@1
|
64 interp = in;
|
nuclear@1
|
65 }
|
nuclear@1
|
66
|
nuclear@1
|
67 Interp XFormNode::get_interpolator() const
|
nuclear@1
|
68 {
|
nuclear@1
|
69 return interp;
|
nuclear@1
|
70 }
|
nuclear@1
|
71
|
nuclear@1
|
72 void XFormNode::set_extrapolator(Extrap ex)
|
nuclear@1
|
73 {
|
nuclear@1
|
74 anm_set_extrapolator(anm, track_extrapolator(ex));
|
nuclear@1
|
75 extrap = ex;
|
nuclear@1
|
76 }
|
nuclear@1
|
77
|
nuclear@1
|
78 Extrap XFormNode::get_extrapolator() const
|
nuclear@1
|
79 {
|
nuclear@1
|
80 return extrap;
|
nuclear@1
|
81 }
|
nuclear@1
|
82
|
nuclear@47
|
83 XFormNode *XFormNode::get_parent()
|
nuclear@47
|
84 {
|
nuclear@47
|
85 return parent;
|
nuclear@47
|
86 }
|
nuclear@47
|
87
|
nuclear@47
|
88 const XFormNode *XFormNode::get_parent() const
|
nuclear@47
|
89 {
|
nuclear@47
|
90 return parent;
|
nuclear@47
|
91 }
|
nuclear@47
|
92
|
nuclear@95
|
93 XFormNode *XFormNode::get_root()
|
nuclear@95
|
94 {
|
nuclear@95
|
95 if(!parent) return this;
|
nuclear@95
|
96 return parent->get_root();
|
nuclear@95
|
97 }
|
nuclear@95
|
98
|
nuclear@95
|
99 const XFormNode *XFormNode::get_root() const
|
nuclear@95
|
100 {
|
nuclear@95
|
101 if(!parent) return this;
|
nuclear@95
|
102 return parent->get_root();
|
nuclear@95
|
103 }
|
nuclear@95
|
104
|
nuclear@1
|
105 void XFormNode::add_child(XFormNode *child)
|
nuclear@1
|
106 {
|
nuclear@66
|
107 if(!child || child == this) return;
|
nuclear@66
|
108
|
nuclear@1
|
109 children.push_back(child);
|
nuclear@1
|
110 anm_link_node(anm, child->anm);
|
nuclear@30
|
111 child->parent = this;
|
nuclear@1
|
112 }
|
nuclear@1
|
113
|
nuclear@1
|
114 void XFormNode::remove_child(XFormNode *child)
|
nuclear@1
|
115 {
|
nuclear@1
|
116 std::vector<XFormNode*>::iterator it;
|
nuclear@1
|
117 it = std::find(children.begin(), children.end(), child);
|
nuclear@1
|
118 if(it != children.end()) {
|
nuclear@1
|
119 children.erase(it);
|
nuclear@1
|
120 anm_unlink_node(anm, child->anm);
|
nuclear@47
|
121
|
nuclear@47
|
122 if(child->parent == this) {
|
nuclear@47
|
123 child->parent = 0;
|
nuclear@47
|
124 }
|
nuclear@1
|
125 }
|
nuclear@1
|
126 }
|
nuclear@1
|
127
|
nuclear@1
|
128 int XFormNode::get_children_count() const
|
nuclear@1
|
129 {
|
nuclear@1
|
130 return (int)children.size();
|
nuclear@1
|
131 }
|
nuclear@1
|
132
|
nuclear@1
|
133 XFormNode *XFormNode::get_child(int idx)
|
nuclear@1
|
134 {
|
nuclear@1
|
135 if(idx >= 0 && idx < get_children_count()) {
|
nuclear@1
|
136 return children[idx];
|
nuclear@1
|
137 }
|
nuclear@1
|
138 return 0;
|
nuclear@1
|
139 }
|
nuclear@1
|
140
|
nuclear@1
|
141 const XFormNode *XFormNode::get_child(int idx) const
|
nuclear@1
|
142 {
|
nuclear@1
|
143 if(idx >= 0 && idx < get_children_count()) {
|
nuclear@1
|
144 return children[idx];
|
nuclear@1
|
145 }
|
nuclear@1
|
146 return 0;
|
nuclear@1
|
147 }
|
nuclear@1
|
148
|
nuclear@47
|
149
|
nuclear@47
|
150 void XFormNode::use_animation(int idx)
|
nuclear@30
|
151 {
|
nuclear@47
|
152 if(idx >= 0) {
|
nuclear@47
|
153 anm_use_animation(anm, idx);
|
nuclear@47
|
154 }
|
nuclear@30
|
155 }
|
nuclear@30
|
156
|
nuclear@47
|
157 void XFormNode::use_animation(const char *name)
|
nuclear@47
|
158 {
|
nuclear@47
|
159 anm_use_animation(anm, anm_find_animation(anm, name));
|
nuclear@47
|
160 }
|
nuclear@47
|
161
|
nuclear@47
|
162 void XFormNode::use_animation(int aidx, int bidx, float t)
|
nuclear@47
|
163 {
|
nuclear@47
|
164 anm_use_animations(anm, aidx, bidx, t);
|
nuclear@47
|
165 }
|
nuclear@47
|
166
|
nuclear@47
|
167 void XFormNode::use_animation(const char *aname, const char *bname, float t)
|
nuclear@47
|
168 {
|
nuclear@47
|
169 int aidx = anm_find_animation(anm, aname);
|
nuclear@47
|
170 int bidx = anm_find_animation(anm, bname);
|
nuclear@47
|
171
|
nuclear@47
|
172 if(aidx == -1) {
|
nuclear@47
|
173 use_animation(bidx);
|
nuclear@47
|
174 }
|
nuclear@47
|
175 if(bidx == -1) {
|
nuclear@47
|
176 use_animation(aidx);
|
nuclear@47
|
177 }
|
nuclear@47
|
178 anm_use_animations(anm, aidx, bidx, t);
|
nuclear@47
|
179 }
|
nuclear@47
|
180
|
nuclear@47
|
181 int XFormNode::get_active_animation_index(int which) const
|
nuclear@47
|
182 {
|
nuclear@47
|
183 return anm_get_active_animation_index(anm, which);
|
nuclear@47
|
184 }
|
nuclear@47
|
185
|
nuclear@47
|
186 float XFormNode::get_active_animation_mix() const
|
nuclear@47
|
187 {
|
nuclear@47
|
188 return anm_get_active_animation_mix(anm);
|
nuclear@47
|
189 }
|
nuclear@47
|
190
|
nuclear@47
|
191 int XFormNode::get_animation_count() const
|
nuclear@47
|
192 {
|
nuclear@47
|
193 return anm_get_animation_count(anm);
|
nuclear@47
|
194 }
|
nuclear@47
|
195
|
nuclear@47
|
196 void XFormNode::add_animation(const char *name)
|
nuclear@47
|
197 {
|
nuclear@47
|
198 int idx = get_animation_count();
|
nuclear@47
|
199
|
nuclear@47
|
200 anm_add_animation(anm);
|
nuclear@47
|
201 use_animation(idx);
|
nuclear@47
|
202
|
nuclear@47
|
203 if(name) {
|
nuclear@47
|
204 set_animation_name(name);
|
nuclear@47
|
205 }
|
nuclear@47
|
206 }
|
nuclear@47
|
207
|
nuclear@47
|
208 void XFormNode::set_animation_name(const char *name)
|
nuclear@47
|
209 {
|
nuclear@47
|
210 anm_set_active_animation_name(anm, name);
|
nuclear@47
|
211 }
|
nuclear@47
|
212
|
nuclear@47
|
213 const char *XFormNode::get_animation_name() const
|
nuclear@47
|
214 {
|
nuclear@47
|
215 return anm_get_active_animation_name(anm);
|
nuclear@47
|
216 }
|
nuclear@47
|
217
|
nuclear@95
|
218 bool XFormNode::get_timeline_bounds(long *start, long *end)
|
nuclear@95
|
219 {
|
nuclear@95
|
220 long node_start = LONG_MAX;
|
nuclear@95
|
221 long node_end = LONG_MIN;
|
nuclear@95
|
222
|
nuclear@95
|
223 for(int i=0; i<3; i++) {
|
nuclear@95
|
224 int nkeys = get_key_count(i);
|
nuclear@95
|
225 if(nkeys > 0) {
|
nuclear@95
|
226 long tmp = get_key_time(i, 0);
|
nuclear@95
|
227 if(tmp < node_start) node_start = tmp;
|
nuclear@95
|
228 tmp = get_key_time(i, nkeys - 1);
|
nuclear@95
|
229 if(tmp > node_end) node_end = tmp;
|
nuclear@95
|
230 }
|
nuclear@95
|
231 }
|
nuclear@95
|
232
|
nuclear@95
|
233 for(size_t i=0; i<children.size(); i++) {
|
nuclear@95
|
234 long cstart, cend;
|
nuclear@95
|
235 if(children[i]->get_timeline_bounds(&cstart, &cend)) {
|
nuclear@95
|
236 if(cstart < node_start) node_start = cstart;
|
nuclear@95
|
237 if(cend > node_end) node_end = cend;
|
nuclear@95
|
238 }
|
nuclear@95
|
239 }
|
nuclear@95
|
240
|
nuclear@95
|
241 if(node_start != LONG_MAX) {
|
nuclear@95
|
242 *start = node_start;
|
nuclear@95
|
243 *end = node_end;
|
nuclear@95
|
244 return true;
|
nuclear@95
|
245 }
|
nuclear@95
|
246 return false;
|
nuclear@95
|
247 }
|
nuclear@95
|
248
|
nuclear@48
|
249 static const int track_type_base[] = {ANM_TRACK_POS_X, ANM_TRACK_ROT_X, ANM_TRACK_SCL_X};
|
nuclear@48
|
250 static const int track_type_nelem[] = {3, 4, 3};
|
nuclear@47
|
251
|
nuclear@48
|
252 int XFormNode::get_key_count(int trackid) const
|
nuclear@48
|
253 {
|
nuclear@48
|
254 struct anm_animation *anim = anm_get_active_animation(anm, 0);
|
nuclear@68
|
255 if(anim) {
|
nuclear@68
|
256 return anim->tracks[track_type_base[trackid]].count;
|
nuclear@68
|
257 }
|
nuclear@68
|
258 return 0;
|
nuclear@48
|
259 }
|
nuclear@48
|
260
|
nuclear@48
|
261 int XFormNode::get_position_key_count() const
|
nuclear@48
|
262 {
|
nuclear@48
|
263 return get_key_count(POSITION_TRACK);
|
nuclear@48
|
264 }
|
nuclear@48
|
265
|
nuclear@48
|
266 int XFormNode::get_rotation_key_count() const
|
nuclear@48
|
267 {
|
nuclear@48
|
268 return get_key_count(ROTATION_TRACK);
|
nuclear@48
|
269 }
|
nuclear@48
|
270
|
nuclear@48
|
271 int XFormNode::get_scaling_key_count() const
|
nuclear@48
|
272 {
|
nuclear@48
|
273 return get_key_count(SCALING_TRACK);
|
nuclear@48
|
274 }
|
nuclear@48
|
275
|
nuclear@48
|
276 long XFormNode::get_key_time(int trackid, int idx) const
|
nuclear@48
|
277 {
|
nuclear@48
|
278 struct anm_animation *anim = anm_get_active_animation(anm, 0);
|
nuclear@48
|
279 struct anm_keyframe *key = anm_get_keyframe(anim->tracks + track_type_base[trackid], idx);
|
nuclear@48
|
280 return ANM_TM2MSEC(key->time);
|
nuclear@48
|
281 }
|
nuclear@48
|
282
|
nuclear@48
|
283 long XFormNode::get_position_key_time(int idx) const
|
nuclear@48
|
284 {
|
nuclear@48
|
285 return get_key_time(POSITION_TRACK, idx);
|
nuclear@48
|
286 }
|
nuclear@48
|
287
|
nuclear@48
|
288 long XFormNode::get_rotation_key_time(int idx) const
|
nuclear@48
|
289 {
|
nuclear@48
|
290 return get_key_time(ROTATION_TRACK, idx);
|
nuclear@48
|
291 }
|
nuclear@48
|
292
|
nuclear@48
|
293 long XFormNode::get_scaling_key_time(int idx) const
|
nuclear@48
|
294 {
|
nuclear@48
|
295 return get_key_time(SCALING_TRACK, idx);
|
nuclear@48
|
296 }
|
nuclear@48
|
297
|
nuclear@48
|
298 int XFormNode::get_key_value(int trackid, int idx, float *val) const
|
nuclear@48
|
299 {
|
nuclear@48
|
300 struct anm_animation *anim = anm_get_active_animation(anm, 0);
|
nuclear@48
|
301
|
nuclear@48
|
302 int nelem = track_type_nelem[trackid];
|
nuclear@48
|
303 for(int i=0; i<nelem; i++) {
|
nuclear@48
|
304 struct anm_keyframe *key = anm_get_keyframe(anim->tracks + track_type_base[trackid] + i, idx);
|
nuclear@48
|
305 val[i] = key->val;
|
nuclear@48
|
306 }
|
nuclear@48
|
307 return nelem;
|
nuclear@48
|
308 }
|
nuclear@48
|
309
|
nuclear@48
|
310 Vector3 XFormNode::get_position_key_value(int idx) const
|
nuclear@48
|
311 {
|
nuclear@48
|
312 float val[3];
|
nuclear@48
|
313 get_key_value(POSITION_TRACK, idx, val);
|
nuclear@48
|
314 return Vector3(val[0], val[1], val[2]);
|
nuclear@48
|
315 }
|
nuclear@48
|
316
|
nuclear@48
|
317 Quaternion XFormNode::get_rotation_key_value(int idx) const
|
nuclear@48
|
318 {
|
nuclear@48
|
319 float val[4];
|
nuclear@48
|
320 get_key_value(ROTATION_TRACK, idx, val);
|
nuclear@48
|
321 return Quaternion(val[3], val[0], val[1], val[2]);
|
nuclear@48
|
322 }
|
nuclear@48
|
323
|
nuclear@48
|
324 Vector3 XFormNode::get_scaling_key_value(int idx) const
|
nuclear@48
|
325 {
|
nuclear@48
|
326 float val[3];
|
nuclear@48
|
327 get_key_value(SCALING_TRACK, idx, val);
|
nuclear@48
|
328 return Vector3(val[0], val[1], val[2]);
|
nuclear@48
|
329 }
|
nuclear@47
|
330
|
nuclear@1
|
331 void XFormNode::set_position(const Vector3 &pos, long tmsec)
|
nuclear@1
|
332 {
|
nuclear@1
|
333 anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec));
|
nuclear@1
|
334 }
|
nuclear@1
|
335
|
nuclear@1
|
336 Vector3 XFormNode::get_node_position(long tmsec) const
|
nuclear@1
|
337 {
|
nuclear@1
|
338 vec3_t p = anm_get_node_position(anm, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
339 return Vector3(p.x, p.y, p.z);
|
nuclear@1
|
340 }
|
nuclear@1
|
341
|
nuclear@1
|
342 void XFormNode::set_rotation(const Quaternion &quat, long tmsec)
|
nuclear@1
|
343 {
|
nuclear@1
|
344 anm_set_rotation(anm, quat_cons(quat.s, quat.v.x, quat.v.y, quat.v.z), ANM_MSEC2TM(tmsec));
|
nuclear@1
|
345 }
|
nuclear@1
|
346
|
nuclear@1
|
347 Quaternion XFormNode::get_node_rotation(long tmsec) const
|
nuclear@1
|
348 {
|
nuclear@1
|
349 quat_t q = anm_get_node_rotation(anm, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
350 return Quaternion(q.w, q.x, q.y, q.z);
|
nuclear@1
|
351 }
|
nuclear@1
|
352
|
nuclear@1
|
353 void XFormNode::set_scaling(const Vector3 &pos, long tmsec)
|
nuclear@1
|
354 {
|
nuclear@1
|
355 anm_set_scaling(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec));
|
nuclear@1
|
356 }
|
nuclear@1
|
357
|
nuclear@1
|
358 Vector3 XFormNode::get_node_scaling(long tmsec) const
|
nuclear@1
|
359 {
|
nuclear@1
|
360 vec3_t s = anm_get_node_scaling(anm, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
361 return Vector3(s.x, s.y, s.z);
|
nuclear@1
|
362 }
|
nuclear@1
|
363
|
nuclear@1
|
364 // these take hierarchy into account
|
nuclear@1
|
365 Vector3 XFormNode::get_position(long tmsec) const
|
nuclear@1
|
366 {
|
nuclear@1
|
367 vec3_t v = anm_get_position(anm, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
368 return Vector3(v.x, v.y, v.z);
|
nuclear@1
|
369 }
|
nuclear@1
|
370
|
nuclear@1
|
371 Quaternion XFormNode::get_rotation(long tmsec) const
|
nuclear@1
|
372 {
|
nuclear@1
|
373 quat_t q = anm_get_rotation(anm, tmsec);
|
nuclear@1
|
374 return Quaternion(q.w, q.x, q.y, q.z);
|
nuclear@1
|
375 }
|
nuclear@1
|
376
|
nuclear@1
|
377 Vector3 XFormNode::get_scaling(long tmsec) const
|
nuclear@1
|
378 {
|
nuclear@1
|
379 vec3_t v = anm_get_scaling(anm, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
380 return Vector3(v.x, v.y, v.z);
|
nuclear@1
|
381 }
|
nuclear@1
|
382
|
nuclear@1
|
383 void XFormNode::set_pivot(const Vector3 &pivot)
|
nuclear@1
|
384 {
|
nuclear@1
|
385 anm_set_pivot(anm, v3_cons(pivot.x, pivot.y, pivot.z));
|
nuclear@1
|
386 }
|
nuclear@1
|
387
|
nuclear@1
|
388 Vector3 XFormNode::get_pivot() const
|
nuclear@1
|
389 {
|
nuclear@1
|
390 vec3_t p = anm_get_pivot(anm);
|
nuclear@1
|
391 return Vector3(p.x, p.y, p.z);
|
nuclear@1
|
392 }
|
nuclear@1
|
393
|
nuclear@1
|
394 void XFormNode::set_local_matrix(const Matrix4x4 &mat)
|
nuclear@1
|
395 {
|
nuclear@1
|
396 local_matrix = mat;
|
nuclear@1
|
397 }
|
nuclear@1
|
398
|
nuclear@1
|
399 const Matrix4x4 &XFormNode::get_local_matrix() const
|
nuclear@1
|
400 {
|
nuclear@1
|
401 return local_matrix;
|
nuclear@1
|
402 }
|
nuclear@1
|
403
|
nuclear@1
|
404 void XFormNode::set_bone_matrix(const Matrix4x4 &bmat)
|
nuclear@1
|
405 {
|
nuclear@1
|
406 bone_matrix = bmat;
|
nuclear@1
|
407 }
|
nuclear@1
|
408
|
nuclear@1
|
409 const Matrix4x4 &XFormNode::get_bone_matrix() const
|
nuclear@1
|
410 {
|
nuclear@1
|
411 return bone_matrix;
|
nuclear@1
|
412 }
|
nuclear@1
|
413
|
nuclear@1
|
414 #define FOO
|
nuclear@1
|
415
|
nuclear@1
|
416 void XFormNode::get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat) const
|
nuclear@1
|
417 {
|
nuclear@1
|
418 anm_time_t tm = ANM_MSEC2TM(tmsec);
|
nuclear@1
|
419
|
nuclear@1
|
420 if(mat) {
|
nuclear@1
|
421 anm_get_node_matrix(anm, (scalar_t(*)[4])mat, tm);
|
nuclear@1
|
422 #ifdef FOO
|
nuclear@1
|
423 *mat = local_matrix * *mat;
|
nuclear@1
|
424 #else
|
nuclear@1
|
425 *mat = *mat * local_matrix;
|
nuclear@1
|
426 #endif
|
nuclear@1
|
427 }
|
nuclear@1
|
428 if(inv_mat) {
|
nuclear@1
|
429 anm_get_inv_matrix(anm, (scalar_t(*)[4])inv_mat, tm);
|
nuclear@1
|
430 }
|
nuclear@1
|
431 }
|
nuclear@1
|
432
|
nuclear@1
|
433 void XFormNode::get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat) const
|
nuclear@1
|
434 {
|
nuclear@1
|
435 anm_time_t tm = ANM_MSEC2TM(tmsec);
|
nuclear@1
|
436
|
nuclear@1
|
437 if(mat) {
|
nuclear@1
|
438 anm_get_matrix(anm, (scalar_t(*)[4])mat, tm);
|
nuclear@1
|
439 #ifdef FOO
|
nuclear@1
|
440 *mat = local_matrix * *mat;
|
nuclear@1
|
441 #else
|
nuclear@1
|
442 *mat = *mat * local_matrix;
|
nuclear@1
|
443 #endif
|
nuclear@1
|
444 }
|
nuclear@1
|
445 if(inv_mat) {
|
nuclear@1
|
446 anm_get_inv_matrix(anm, (scalar_t(*)[4])inv_mat, tm);
|
nuclear@1
|
447 }
|
nuclear@1
|
448 }
|
nuclear@1
|
449
|
nuclear@1
|
450
|
nuclear@1
|
451 // ---- Track ----
|
nuclear@1
|
452
|
nuclear@1
|
453 Track::Track()
|
nuclear@1
|
454 {
|
nuclear@1
|
455 trk = new anm_track;
|
nuclear@1
|
456 anm_init_track(trk);
|
nuclear@1
|
457 }
|
nuclear@1
|
458
|
nuclear@1
|
459 Track::~Track()
|
nuclear@1
|
460 {
|
nuclear@1
|
461 anm_destroy_track(trk);
|
nuclear@1
|
462 delete trk;
|
nuclear@1
|
463 }
|
nuclear@1
|
464
|
nuclear@1
|
465 Track::Track(const Track &rhs)
|
nuclear@1
|
466 {
|
nuclear@1
|
467 trk = new anm_track;
|
nuclear@1
|
468 anm_init_track(trk);
|
nuclear@1
|
469 anm_copy_track(trk, rhs.trk);
|
nuclear@1
|
470 interp = rhs.interp;
|
nuclear@1
|
471 extrap = rhs.extrap;
|
nuclear@1
|
472 }
|
nuclear@1
|
473
|
nuclear@1
|
474 Track &Track::operator =(const Track &rhs)
|
nuclear@1
|
475 {
|
nuclear@1
|
476 if(&rhs == this) {
|
nuclear@1
|
477 return *this;
|
nuclear@1
|
478 }
|
nuclear@1
|
479
|
nuclear@1
|
480 anm_copy_track(trk, rhs.trk);
|
nuclear@1
|
481 interp = rhs.interp;
|
nuclear@1
|
482 extrap = rhs.extrap;
|
nuclear@1
|
483 return *this;
|
nuclear@1
|
484 }
|
nuclear@1
|
485
|
nuclear@1
|
486
|
nuclear@1
|
487 void Track::set_interpolator(Interp in)
|
nuclear@1
|
488 {
|
nuclear@1
|
489 anm_set_track_interpolator(trk, track_interpolator(in));
|
nuclear@1
|
490 interp = in;
|
nuclear@1
|
491 }
|
nuclear@1
|
492
|
nuclear@1
|
493 Interp Track::get_interpolator() const
|
nuclear@1
|
494 {
|
nuclear@1
|
495 return interp;
|
nuclear@1
|
496 }
|
nuclear@1
|
497
|
nuclear@1
|
498 void Track::set_extrapolator(Extrap ex)
|
nuclear@1
|
499 {
|
nuclear@1
|
500 anm_set_track_extrapolator(trk, track_extrapolator(ex));
|
nuclear@1
|
501 extrap = ex;
|
nuclear@1
|
502 }
|
nuclear@1
|
503
|
nuclear@1
|
504 Extrap Track::get_extrapolator() const
|
nuclear@1
|
505 {
|
nuclear@1
|
506 return extrap;
|
nuclear@1
|
507 }
|
nuclear@1
|
508
|
nuclear@1
|
509 void Track::set_default(double def)
|
nuclear@1
|
510 {
|
nuclear@1
|
511 anm_set_track_default(trk, def);
|
nuclear@1
|
512 }
|
nuclear@1
|
513
|
nuclear@1
|
514 void Track::set_value(float val, long tmsec)
|
nuclear@1
|
515 {
|
nuclear@1
|
516 anm_set_value(trk, ANM_MSEC2TM(tmsec), val);
|
nuclear@1
|
517 }
|
nuclear@1
|
518
|
nuclear@1
|
519 float Track::get_value(long tmsec) const
|
nuclear@1
|
520 {
|
nuclear@1
|
521 return anm_get_value(trk, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
522 }
|
nuclear@1
|
523
|
nuclear@1
|
524 float Track::operator ()(long tmsec) const
|
nuclear@1
|
525 {
|
nuclear@1
|
526 return anm_get_value(trk, ANM_MSEC2TM(tmsec));
|
nuclear@1
|
527 }
|
nuclear@1
|
528
|
nuclear@1
|
529
|
nuclear@1
|
530 // ---- Track3 ----
|
nuclear@1
|
531
|
nuclear@1
|
532 void Track3::set_interpolator(Interp in)
|
nuclear@1
|
533 {
|
nuclear@1
|
534 for(int i=0; i<3; i++) {
|
nuclear@1
|
535 track[i].set_interpolator(in);
|
nuclear@1
|
536 }
|
nuclear@1
|
537 }
|
nuclear@1
|
538
|
nuclear@1
|
539 Interp Track3::get_interpolator() const
|
nuclear@1
|
540 {
|
nuclear@1
|
541 return track[0].get_interpolator();
|
nuclear@1
|
542 }
|
nuclear@1
|
543
|
nuclear@1
|
544 void Track3::set_extrapolator(Extrap ex)
|
nuclear@1
|
545 {
|
nuclear@1
|
546 for(int i=0; i<3; i++) {
|
nuclear@1
|
547 track[i].set_extrapolator(ex);
|
nuclear@1
|
548 }
|
nuclear@1
|
549 }
|
nuclear@1
|
550
|
nuclear@1
|
551 Extrap Track3::get_extrapolator() const
|
nuclear@1
|
552 {
|
nuclear@1
|
553 return track[0].get_extrapolator();
|
nuclear@1
|
554 }
|
nuclear@1
|
555
|
nuclear@1
|
556 void Track3::set_default(const Vector3 &def)
|
nuclear@1
|
557 {
|
nuclear@1
|
558 for(int i=0; i<3; i++) {
|
nuclear@1
|
559 track[i].set_default(def[i]);
|
nuclear@1
|
560 }
|
nuclear@1
|
561 }
|
nuclear@1
|
562
|
nuclear@1
|
563 void Track3::set_value(const Vector3 &val, long tmsec)
|
nuclear@1
|
564 {
|
nuclear@1
|
565 for(int i=0; i<3; i++) {
|
nuclear@1
|
566 track[i].set_value(val[i], tmsec);
|
nuclear@1
|
567 }
|
nuclear@1
|
568 }
|
nuclear@1
|
569
|
nuclear@1
|
570 Vector3 Track3::get_value(long tmsec) const
|
nuclear@1
|
571 {
|
nuclear@1
|
572 return Vector3(track[0](tmsec), track[1](tmsec), track[2](tmsec));
|
nuclear@1
|
573 }
|
nuclear@1
|
574
|
nuclear@1
|
575 Vector3 Track3::operator ()(long tmsec) const
|
nuclear@1
|
576 {
|
nuclear@1
|
577 return Vector3(track[0](tmsec), track[1](tmsec), track[2](tmsec));
|
nuclear@1
|
578 }
|
nuclear@1
|
579
|
nuclear@1
|
580
|
nuclear@1
|
581 static inline anm_interpolator track_interpolator(Interp in)
|
nuclear@1
|
582 {
|
nuclear@1
|
583 switch(in) {
|
nuclear@1
|
584 case INTERP_STEP:
|
nuclear@1
|
585 return ANM_INTERP_STEP;
|
nuclear@1
|
586 case INTERP_LINEAR:
|
nuclear@1
|
587 return ANM_INTERP_LINEAR;
|
nuclear@1
|
588 case INTERP_CUBIC:
|
nuclear@1
|
589 return ANM_INTERP_CUBIC;
|
nuclear@1
|
590 }
|
nuclear@1
|
591
|
nuclear@1
|
592 assert(0);
|
nuclear@1
|
593 return ANM_INTERP_STEP;
|
nuclear@1
|
594 }
|
nuclear@1
|
595
|
nuclear@1
|
596 static inline anm_extrapolator track_extrapolator(Extrap ex)
|
nuclear@1
|
597 {
|
nuclear@1
|
598 switch(ex) {
|
nuclear@1
|
599 case EXTRAP_EXTEND:
|
nuclear@1
|
600 return ANM_EXTRAP_EXTEND;
|
nuclear@1
|
601 case EXTRAP_CLAMP:
|
nuclear@1
|
602 return ANM_EXTRAP_CLAMP;
|
nuclear@1
|
603 case EXTRAP_REPEAT:
|
nuclear@1
|
604 return ANM_EXTRAP_REPEAT;
|
nuclear@1
|
605 }
|
nuclear@1
|
606
|
nuclear@1
|
607 assert(0);
|
nuclear@1
|
608 return ANM_EXTRAP_EXTEND;
|
nuclear@1
|
609 }
|
nuclear@1
|
610
|