goat3d

view src/xform_node.h @ 54:dad392c710df

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