goat3d

view 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
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;
24 XFormNode *parent;
26 Interp interp;
27 Extrap extrap;
29 Matrix4x4 local_matrix;
30 Matrix4x4 bone_matrix;
32 XFormNode(const XFormNode &node) {}
33 XFormNode &operator =(const XFormNode &node) { return *this; }
35 public:
36 XFormNode();
37 virtual ~XFormNode();
39 virtual void set_name(const char *name);
40 virtual const char *get_name() const;
42 virtual void set_interpolator(Interp in);
43 virtual Interp get_interpolator() const;
44 virtual void set_extrapolator(Extrap ex);
45 virtual Extrap get_extrapolator() const;
47 // children management
48 virtual void add_child(XFormNode *child);
49 virtual void remove_child(XFormNode *child);
51 virtual int get_children_count() const;
52 virtual XFormNode *get_child(int idx);
53 virtual const XFormNode *get_child(int idx) const;
55 virtual XFormNode *get_parent() const;
57 virtual void set_position(const Vector3 &pos, long tmsec = 0);
58 virtual Vector3 get_node_position(long tmsec = 0) const;
60 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
61 virtual Quaternion get_node_rotation(long tmsec = 0) const;
63 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
64 virtual Vector3 get_node_scaling(long tmsec = 0) const;
66 // these take hierarchy into account
67 virtual Vector3 get_position(long tmsec = 0) const;
68 virtual Quaternion get_rotation(long tmsec = 0) const;
69 virtual Vector3 get_scaling(long tmsec = 0) const;
71 virtual void set_pivot(const Vector3 &pivot);
72 virtual Vector3 get_pivot() const;
74 // the local matrix is concatenated with the regular node/anim matrix
75 virtual void set_local_matrix(const Matrix4x4 &mat);
76 virtual const Matrix4x4 &get_local_matrix() const;
78 // for bone nodes, the transformation of the bone in bind position
79 virtual void set_bone_matrix(const Matrix4x4 &bmat);
80 virtual const Matrix4x4 &get_bone_matrix() const;
82 // node transformation alone
83 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
85 // node transformation taking hierarchy into account
86 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
87 };
90 class Track {
91 private:
92 struct anm_track *trk;
93 Interp interp;
94 Extrap extrap;
96 public:
97 Track();
98 ~Track();
100 Track(const Track &trk);
101 Track &operator =(const Track &trk);
103 void set_interpolator(Interp in);
104 Interp get_interpolator() const;
105 void set_extrapolator(Extrap ex);
106 Extrap get_extrapolator() const;
108 void set_default(double def);
110 void set_value(float val, long tmsec = 0);
111 float get_value(long tmsec = 0) const;
113 // the same as get_value
114 float operator ()(long tmsec = 0) const;
115 };
117 class Track3 {
118 private:
119 Track track[3];
121 public:
122 void set_interpolator(Interp in);
123 Interp get_interpolator() const;
124 void set_extrapolator(Extrap ex);
125 Extrap get_extrapolator() const;
127 void set_default(const Vector3 &def);
129 void set_value(const Vector3 &val, long tmsec = 0);
130 Vector3 get_value(long tmsec = 0) const;
132 // the same as get_value
133 Vector3 operator ()(long tmsec = 0) const;
134 };
136 #endif /* XFORM_NODE_H_ */