goat3d
view src/xform_node.h @ 103:45a9d493e98c
fixed the input latency issue by calling QWidget::update() instead of QGLWidget::updateGL()
update schedules an update instead of redrawing immediately.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 12 Sep 2015 17:40:02 +0300 |
parents | dad392c710df |
children |
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 virtual XFormNode *get_root();
73 virtual const XFormNode *get_root() const;
75 // children management
76 virtual void add_child(XFormNode *child);
77 virtual void remove_child(XFormNode *child);
79 virtual int get_children_count() const;
80 virtual XFormNode *get_child(int idx);
81 virtual const XFormNode *get_child(int idx) const;
84 virtual void use_animation(int idx);
85 virtual void use_animation(const char *name);
86 virtual void use_animation(int aidx, int bidx, float t);
87 virtual void use_animation(const char *aname, const char *bname, float t);
89 virtual int get_active_animation_index(int which = 0) const;
90 virtual float get_active_animation_mix() const;
92 virtual int get_animation_count() const;
94 // add a new empty animation slot (recursive)
95 virtual void add_animation(const char *name = 0);
97 // set/get the current animation name (set is recursive)
98 virtual void set_animation_name(const char *name);
99 virtual const char *get_animation_name() const;
101 virtual bool get_timeline_bounds(long *start, long *end);
103 // raw keyframe retrieval without interpolation
104 // NOTE: trackid parameters correspond to the values of the unnamed enumeration at the top
106 virtual int get_key_count(int trackid) const;
107 virtual int get_position_key_count() const;
108 virtual int get_rotation_key_count() const;
109 virtual int get_scaling_key_count() const;
111 virtual long get_key_time(int trackid, int idx) const;
112 virtual long get_position_key_time(int idx) const;
113 virtual long get_rotation_key_time(int idx) const;
114 virtual long get_scaling_key_time(int idx) const;
116 /* writes the key value through the val pointer, and returns the number
117 * of elements in that value (3 for pos/scale, 4 for rotation).
118 */
119 virtual int get_key_value(int trackid, int idx, float *val) const;
120 virtual Vector3 get_position_key_value(int idx) const;
121 virtual Quaternion get_rotation_key_value(int idx) const;
122 virtual Vector3 get_scaling_key_value(int idx) const;
125 virtual void set_position(const Vector3 &pos, long tmsec = 0);
126 virtual Vector3 get_node_position(long tmsec = 0) const;
128 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
129 virtual Quaternion get_node_rotation(long tmsec = 0) const;
131 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
132 virtual Vector3 get_node_scaling(long tmsec = 0) const;
134 // these take hierarchy into account
135 virtual Vector3 get_position(long tmsec = 0) const;
136 virtual Quaternion get_rotation(long tmsec = 0) const;
137 virtual Vector3 get_scaling(long tmsec = 0) const;
139 virtual void set_pivot(const Vector3 &pivot);
140 virtual Vector3 get_pivot() const;
142 // the local matrix is concatenated with the regular node/anim matrix
143 virtual void set_local_matrix(const Matrix4x4 &mat);
144 virtual const Matrix4x4 &get_local_matrix() const;
146 // for bone nodes, the transformation of the bone in bind position
147 virtual void set_bone_matrix(const Matrix4x4 &bmat);
148 virtual const Matrix4x4 &get_bone_matrix() const;
150 // node transformation alone
151 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
153 // node transformation taking hierarchy into account
154 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
155 };
158 class Track {
159 private:
160 struct anm_track *trk;
161 Interp interp;
162 Extrap extrap;
164 public:
165 Track();
166 ~Track();
168 Track(const Track &trk);
169 Track &operator =(const Track &trk);
171 void set_interpolator(Interp in);
172 Interp get_interpolator() const;
173 void set_extrapolator(Extrap ex);
174 Extrap get_extrapolator() const;
176 void set_default(double def);
178 void set_value(float val, long tmsec = 0);
179 float get_value(long tmsec = 0) const;
181 // the same as get_value
182 float operator ()(long tmsec = 0) const;
183 };
185 class Track3 {
186 private:
187 Track track[3];
189 public:
190 void set_interpolator(Interp in);
191 Interp get_interpolator() const;
192 void set_extrapolator(Extrap ex);
193 Extrap get_extrapolator() const;
195 void set_default(const Vector3 &def);
197 void set_value(const Vector3 &val, long tmsec = 0);
198 Vector3 get_value(long tmsec = 0) const;
200 // the same as get_value
201 Vector3 operator ()(long tmsec = 0) const;
202 };
204 } // namespace g3dimpl
206 #endif /* XFORM_NODE_H_ */