goat3d

view src/xform_node.h @ 29:3d669155709d

- switched the unix build to use the internal vmath/anim as well - fixed a memory corruption issue which was caused by including the system-wide installed version of the anim.h header file - started the ass2goat assimp->goat3d converter
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Sep 2013 21:53:03 +0300
parents e46529a5d057
children 0fe02696fb1e
line source
1 /*
2 TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks)
3 */
4 #ifndef XFORM_NODE_H_
5 #define XFORM_NODE_H_
7 #include <vector>
8 #include "vmath/vector.h"
9 #include "vmath/quat.h"
10 #include "vmath/matrix.h"
12 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
13 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
15 struct anm_node;
16 struct anm_track;
18 // XXX all time arguments are milliseconds
20 class XFormNode {
21 private:
22 struct anm_node *anm;
23 std::vector<XFormNode*> children;
25 Interp interp;
26 Extrap extrap;
28 Matrix4x4 local_matrix;
29 Matrix4x4 bone_matrix;
31 XFormNode(const XFormNode &node) {}
32 XFormNode &operator =(const XFormNode &node) { return *this; }
34 public:
35 XFormNode();
36 virtual ~XFormNode();
38 virtual void set_name(const char *name);
39 virtual const char *get_name() const;
41 virtual void set_interpolator(Interp in);
42 virtual Interp get_interpolator() const;
43 virtual void set_extrapolator(Extrap ex);
44 virtual Extrap get_extrapolator() const;
46 // children management
47 virtual void add_child(XFormNode *child);
48 virtual void remove_child(XFormNode *child);
50 virtual int get_children_count() const;
51 virtual XFormNode *get_child(int idx);
52 virtual const XFormNode *get_child(int idx) const;
55 virtual void set_position(const Vector3 &pos, long tmsec = 0);
56 virtual Vector3 get_node_position(long tmsec = 0) const;
58 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
59 virtual Quaternion get_node_rotation(long tmsec = 0) const;
61 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
62 virtual Vector3 get_node_scaling(long tmsec = 0) const;
64 // these take hierarchy into account
65 virtual Vector3 get_position(long tmsec = 0) const;
66 virtual Quaternion get_rotation(long tmsec = 0) const;
67 virtual Vector3 get_scaling(long tmsec = 0) const;
69 virtual void set_pivot(const Vector3 &pivot);
70 virtual Vector3 get_pivot() const;
72 // the local matrix is concatenated with the regular node/anim matrix
73 virtual void set_local_matrix(const Matrix4x4 &mat);
74 virtual const Matrix4x4 &get_local_matrix() const;
76 // for bone nodes, the transformation of the bone in bind position
77 virtual void set_bone_matrix(const Matrix4x4 &bmat);
78 virtual const Matrix4x4 &get_bone_matrix() const;
80 // node transformation alone
81 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
83 // node transformation taking hierarchy into account
84 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
85 };
88 class Track {
89 private:
90 struct anm_track *trk;
91 Interp interp;
92 Extrap extrap;
94 public:
95 Track();
96 ~Track();
98 Track(const Track &trk);
99 Track &operator =(const Track &trk);
101 void set_interpolator(Interp in);
102 Interp get_interpolator() const;
103 void set_extrapolator(Extrap ex);
104 Extrap get_extrapolator() const;
106 void set_default(double def);
108 void set_value(float val, long tmsec = 0);
109 float get_value(long tmsec = 0) const;
111 // the same as get_value
112 float operator ()(long tmsec = 0) const;
113 };
115 class Track3 {
116 private:
117 Track track[3];
119 public:
120 void set_interpolator(Interp in);
121 Interp get_interpolator() const;
122 void set_extrapolator(Extrap ex);
123 Extrap get_extrapolator() const;
125 void set_default(const Vector3 &def);
127 void set_value(const Vector3 &val, long tmsec = 0);
128 Vector3 get_value(long tmsec = 0) const;
130 // the same as get_value
131 Vector3 operator ()(long tmsec = 0) const;
132 };
134 #endif /* XFORM_NODE_H_ */