goat3dgfx

view src/xform_node.h @ 16:f61cc1df533c

added viewscn example (under dev)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Nov 2013 20:53:26 +0200
parents 1873dfd13f2d
children 7c593721547f
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"
13 struct anm_node;
14 struct anm_track;
16 namespace goatgfx {
18 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
19 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
21 // XXX all time arguments are milliseconds
23 class XFormNode {
24 private:
25 struct anm_node *anm;
26 std::vector<XFormNode*> children;
28 Interp interp;
29 Extrap extrap;
31 Matrix4x4 local_matrix;
32 Matrix4x4 bone_matrix;
34 XFormNode(const XFormNode &node) {}
35 XFormNode &operator =(const XFormNode &node) { return *this; }
37 public:
38 XFormNode();
39 virtual ~XFormNode();
41 void set_name(const char *name);
42 const char *get_name() const;
44 void set_interpolator(Interp in);
45 Interp get_interpolator() const;
46 void set_extrapolator(Extrap ex);
47 Extrap get_extrapolator() const;
49 // children management
50 void add_child(XFormNode *child);
51 void remove_child(XFormNode *child);
53 int get_children_count() const;
54 XFormNode *get_child(int idx);
55 const XFormNode *get_child(int idx) const;
58 void set_position(const Vector3 &pos, long tmsec = 0);
59 Vector3 get_node_position(long tmsec = 0) const;
61 void set_rotation(const Quaternion &quat, long tmsec = 0);
62 Quaternion get_node_rotation(long tmsec = 0) const;
64 void set_scaling(const Vector3 &pos, long tmsec = 0);
65 Vector3 get_node_scaling(long tmsec = 0) const;
67 // these take hierarchy into account
68 Vector3 get_position(long tmsec = 0) const;
69 Quaternion get_rotation(long tmsec = 0) const;
70 Vector3 get_scaling(long tmsec = 0) const;
72 void set_pivot(const Vector3 &pivot);
73 Vector3 get_pivot() const;
75 // the local matrix is concatenated with the regular node/anim matrix
76 void set_local_matrix(const Matrix4x4 &mat);
77 const Matrix4x4 &get_local_matrix() const;
79 // for bone nodes, the transformation of the bone in bind position
80 void set_bone_matrix(const Matrix4x4 &bmat);
81 const Matrix4x4 &get_bone_matrix() const;
83 // node transformation alone
84 void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
86 // node transformation taking hierarchy into account
87 void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
88 };
91 class Track {
92 private:
93 struct anm_track *trk;
94 Interp interp;
95 Extrap extrap;
97 public:
98 Track();
99 ~Track();
101 Track(const Track &trk);
102 Track &operator =(const Track &trk);
104 void set_interpolator(Interp in);
105 Interp get_interpolator() const;
106 void set_extrapolator(Extrap ex);
107 Extrap get_extrapolator() const;
109 void set_default(double def);
111 void set_value(float val, long tmsec = 0);
112 float get_value(long tmsec = 0) const;
114 // the same as get_value
115 float operator ()(long tmsec = 0) const;
116 };
118 class Track3 {
119 private:
120 Track track[3];
122 public:
123 void set_interpolator(Interp in);
124 Interp get_interpolator() const;
125 void set_extrapolator(Extrap ex);
126 Extrap get_extrapolator() const;
128 void set_default(const Vector3 &def);
130 void set_value(const Vector3 &val, long tmsec = 0);
131 Vector3 get_value(long tmsec = 0) const;
133 // the same as get_value
134 Vector3 operator ()(long tmsec = 0) const;
135 };
137 } // namespace goatgfx
139 #endif /* XFORM_NODE_H_ */