goat3d

annotate src/xform_node.h @ 38:60f2037680ee

split the exporter into two files to make it more readable (and maybe make an importer too at some point?)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Oct 2013 20:02:57 +0300
parents cd71f0b92f44
children 498ca7ac7047
rev   line source
nuclear@1 1 /*
nuclear@1 2 TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks)
nuclear@1 3 */
nuclear@1 4 #ifndef XFORM_NODE_H_
nuclear@1 5 #define XFORM_NODE_H_
nuclear@1 6
nuclear@1 7 #include <vector>
nuclear@1 8 #include "vmath/vector.h"
nuclear@1 9 #include "vmath/quat.h"
nuclear@1 10 #include "vmath/matrix.h"
nuclear@1 11
nuclear@1 12 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
nuclear@1 13 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
nuclear@1 14
nuclear@1 15 struct anm_node;
nuclear@1 16 struct anm_track;
nuclear@1 17
nuclear@1 18 // XXX 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@1 36 XFormNode();
nuclear@1 37 virtual ~XFormNode();
nuclear@1 38
nuclear@8 39 virtual void set_name(const char *name);
nuclear@8 40 virtual const char *get_name() const;
nuclear@1 41
nuclear@8 42 virtual void set_interpolator(Interp in);
nuclear@8 43 virtual Interp get_interpolator() const;
nuclear@8 44 virtual void set_extrapolator(Extrap ex);
nuclear@8 45 virtual Extrap get_extrapolator() const;
nuclear@1 46
nuclear@1 47 // children management
nuclear@8 48 virtual void add_child(XFormNode *child);
nuclear@8 49 virtual void remove_child(XFormNode *child);
nuclear@1 50
nuclear@8 51 virtual int get_children_count() const;
nuclear@8 52 virtual XFormNode *get_child(int idx);
nuclear@8 53 virtual const XFormNode *get_child(int idx) const;
nuclear@1 54
nuclear@30 55 virtual XFormNode *get_parent() const;
nuclear@1 56
nuclear@8 57 virtual void set_position(const Vector3 &pos, long tmsec = 0);
nuclear@8 58 virtual Vector3 get_node_position(long tmsec = 0) const;
nuclear@1 59
nuclear@8 60 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
nuclear@8 61 virtual Quaternion get_node_rotation(long tmsec = 0) const;
nuclear@1 62
nuclear@8 63 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
nuclear@8 64 virtual Vector3 get_node_scaling(long tmsec = 0) const;
nuclear@1 65
nuclear@1 66 // these take hierarchy into account
nuclear@8 67 virtual Vector3 get_position(long tmsec = 0) const;
nuclear@8 68 virtual Quaternion get_rotation(long tmsec = 0) const;
nuclear@8 69 virtual Vector3 get_scaling(long tmsec = 0) const;
nuclear@1 70
nuclear@8 71 virtual void set_pivot(const Vector3 &pivot);
nuclear@8 72 virtual Vector3 get_pivot() const;
nuclear@1 73
nuclear@1 74 // the local matrix is concatenated with the regular node/anim matrix
nuclear@8 75 virtual void set_local_matrix(const Matrix4x4 &mat);
nuclear@8 76 virtual const Matrix4x4 &get_local_matrix() const;
nuclear@1 77
nuclear@1 78 // for bone nodes, the transformation of the bone in bind position
nuclear@8 79 virtual void set_bone_matrix(const Matrix4x4 &bmat);
nuclear@8 80 virtual const Matrix4x4 &get_bone_matrix() const;
nuclear@1 81
nuclear@1 82 // node transformation alone
nuclear@8 83 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
nuclear@1 84
nuclear@1 85 // node transformation taking hierarchy into account
nuclear@8 86 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
nuclear@1 87 };
nuclear@1 88
nuclear@1 89
nuclear@1 90 class Track {
nuclear@1 91 private:
nuclear@1 92 struct anm_track *trk;
nuclear@1 93 Interp interp;
nuclear@1 94 Extrap extrap;
nuclear@1 95
nuclear@1 96 public:
nuclear@1 97 Track();
nuclear@1 98 ~Track();
nuclear@1 99
nuclear@1 100 Track(const Track &trk);
nuclear@1 101 Track &operator =(const Track &trk);
nuclear@1 102
nuclear@1 103 void set_interpolator(Interp in);
nuclear@1 104 Interp get_interpolator() const;
nuclear@1 105 void set_extrapolator(Extrap ex);
nuclear@1 106 Extrap get_extrapolator() const;
nuclear@1 107
nuclear@1 108 void set_default(double def);
nuclear@1 109
nuclear@1 110 void set_value(float val, long tmsec = 0);
nuclear@1 111 float get_value(long tmsec = 0) const;
nuclear@1 112
nuclear@1 113 // the same as get_value
nuclear@1 114 float operator ()(long tmsec = 0) const;
nuclear@1 115 };
nuclear@1 116
nuclear@1 117 class Track3 {
nuclear@1 118 private:
nuclear@1 119 Track track[3];
nuclear@1 120
nuclear@1 121 public:
nuclear@1 122 void set_interpolator(Interp in);
nuclear@1 123 Interp get_interpolator() const;
nuclear@1 124 void set_extrapolator(Extrap ex);
nuclear@1 125 Extrap get_extrapolator() const;
nuclear@1 126
nuclear@1 127 void set_default(const Vector3 &def);
nuclear@1 128
nuclear@1 129 void set_value(const Vector3 &val, long tmsec = 0);
nuclear@1 130 Vector3 get_value(long tmsec = 0) const;
nuclear@1 131
nuclear@1 132 // the same as get_value
nuclear@1 133 Vector3 operator ()(long tmsec = 0) const;
nuclear@1 134 };
nuclear@1 135
nuclear@1 136 #endif /* XFORM_NODE_H_ */