goat3d

annotate 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
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@95 72 virtual XFormNode *get_root();
nuclear@95 73 virtual const XFormNode *get_root() const;
nuclear@95 74
nuclear@1 75 // children management
nuclear@8 76 virtual void add_child(XFormNode *child);
nuclear@8 77 virtual void remove_child(XFormNode *child);
nuclear@1 78
nuclear@8 79 virtual int get_children_count() const;
nuclear@8 80 virtual XFormNode *get_child(int idx);
nuclear@8 81 virtual const XFormNode *get_child(int idx) const;
nuclear@1 82
nuclear@47 83
nuclear@47 84 virtual void use_animation(int idx);
nuclear@47 85 virtual void use_animation(const char *name);
nuclear@47 86 virtual void use_animation(int aidx, int bidx, float t);
nuclear@47 87 virtual void use_animation(const char *aname, const char *bname, float t);
nuclear@47 88
nuclear@47 89 virtual int get_active_animation_index(int which = 0) const;
nuclear@47 90 virtual float get_active_animation_mix() const;
nuclear@47 91
nuclear@47 92 virtual int get_animation_count() const;
nuclear@47 93
nuclear@47 94 // add a new empty animation slot (recursive)
nuclear@47 95 virtual void add_animation(const char *name = 0);
nuclear@47 96
nuclear@47 97 // set/get the current animation name (set is recursive)
nuclear@47 98 virtual void set_animation_name(const char *name);
nuclear@47 99 virtual const char *get_animation_name() const;
nuclear@47 100
nuclear@95 101 virtual bool get_timeline_bounds(long *start, long *end);
nuclear@95 102
nuclear@48 103 // raw keyframe retrieval without interpolation
nuclear@48 104 // NOTE: trackid parameters correspond to the values of the unnamed enumeration at the top
nuclear@48 105
nuclear@48 106 virtual int get_key_count(int trackid) const;
nuclear@48 107 virtual int get_position_key_count() const;
nuclear@48 108 virtual int get_rotation_key_count() const;
nuclear@48 109 virtual int get_scaling_key_count() const;
nuclear@48 110
nuclear@48 111 virtual long get_key_time(int trackid, int idx) const;
nuclear@48 112 virtual long get_position_key_time(int idx) const;
nuclear@48 113 virtual long get_rotation_key_time(int idx) const;
nuclear@48 114 virtual long get_scaling_key_time(int idx) const;
nuclear@48 115
nuclear@48 116 /* writes the key value through the val pointer, and returns the number
nuclear@48 117 * of elements in that value (3 for pos/scale, 4 for rotation).
nuclear@48 118 */
nuclear@48 119 virtual int get_key_value(int trackid, int idx, float *val) const;
nuclear@48 120 virtual Vector3 get_position_key_value(int idx) const;
nuclear@48 121 virtual Quaternion get_rotation_key_value(int idx) const;
nuclear@48 122 virtual Vector3 get_scaling_key_value(int idx) const;
nuclear@48 123
nuclear@1 124
nuclear@8 125 virtual void set_position(const Vector3 &pos, long tmsec = 0);
nuclear@8 126 virtual Vector3 get_node_position(long tmsec = 0) const;
nuclear@1 127
nuclear@8 128 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
nuclear@8 129 virtual Quaternion get_node_rotation(long tmsec = 0) const;
nuclear@1 130
nuclear@8 131 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
nuclear@8 132 virtual Vector3 get_node_scaling(long tmsec = 0) const;
nuclear@1 133
nuclear@1 134 // these take hierarchy into account
nuclear@8 135 virtual Vector3 get_position(long tmsec = 0) const;
nuclear@8 136 virtual Quaternion get_rotation(long tmsec = 0) const;
nuclear@8 137 virtual Vector3 get_scaling(long tmsec = 0) const;
nuclear@1 138
nuclear@8 139 virtual void set_pivot(const Vector3 &pivot);
nuclear@8 140 virtual Vector3 get_pivot() const;
nuclear@1 141
nuclear@1 142 // the local matrix is concatenated with the regular node/anim matrix
nuclear@8 143 virtual void set_local_matrix(const Matrix4x4 &mat);
nuclear@8 144 virtual const Matrix4x4 &get_local_matrix() const;
nuclear@1 145
nuclear@1 146 // for bone nodes, the transformation of the bone in bind position
nuclear@8 147 virtual void set_bone_matrix(const Matrix4x4 &bmat);
nuclear@8 148 virtual const Matrix4x4 &get_bone_matrix() const;
nuclear@1 149
nuclear@1 150 // node transformation alone
nuclear@8 151 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
nuclear@1 152
nuclear@1 153 // node transformation taking hierarchy into account
nuclear@8 154 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
nuclear@1 155 };
nuclear@1 156
nuclear@1 157
nuclear@1 158 class Track {
nuclear@1 159 private:
nuclear@1 160 struct anm_track *trk;
nuclear@1 161 Interp interp;
nuclear@1 162 Extrap extrap;
nuclear@1 163
nuclear@1 164 public:
nuclear@1 165 Track();
nuclear@1 166 ~Track();
nuclear@1 167
nuclear@1 168 Track(const Track &trk);
nuclear@1 169 Track &operator =(const Track &trk);
nuclear@1 170
nuclear@1 171 void set_interpolator(Interp in);
nuclear@1 172 Interp get_interpolator() const;
nuclear@1 173 void set_extrapolator(Extrap ex);
nuclear@1 174 Extrap get_extrapolator() const;
nuclear@1 175
nuclear@1 176 void set_default(double def);
nuclear@1 177
nuclear@1 178 void set_value(float val, long tmsec = 0);
nuclear@1 179 float get_value(long tmsec = 0) const;
nuclear@1 180
nuclear@1 181 // the same as get_value
nuclear@1 182 float operator ()(long tmsec = 0) const;
nuclear@1 183 };
nuclear@1 184
nuclear@1 185 class Track3 {
nuclear@1 186 private:
nuclear@1 187 Track track[3];
nuclear@1 188
nuclear@1 189 public:
nuclear@1 190 void set_interpolator(Interp in);
nuclear@1 191 Interp get_interpolator() const;
nuclear@1 192 void set_extrapolator(Extrap ex);
nuclear@1 193 Extrap get_extrapolator() const;
nuclear@1 194
nuclear@1 195 void set_default(const Vector3 &def);
nuclear@1 196
nuclear@1 197 void set_value(const Vector3 &val, long tmsec = 0);
nuclear@1 198 Vector3 get_value(long tmsec = 0) const;
nuclear@1 199
nuclear@1 200 // the same as get_value
nuclear@1 201 Vector3 operator ()(long tmsec = 0) const;
nuclear@1 202 };
nuclear@1 203
nuclear@47 204 } // namespace g3dimpl
nuclear@47 205
nuclear@1 206 #endif /* XFORM_NODE_H_ */