goat3d

annotate src/xform_node.h @ 55:af1310ed212b

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