goat3dgfx

view src/xform_node.h @ 33:253542d715f4

default texture
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Mar 2014 06:32:37 +0200
parents 92bfb0206969
children
line source
1 #ifndef GOATGFX_XFORM_NODE_H_
2 #define GOATGFX_XFORM_NODE_H_
4 #include <vector>
5 #include "vmath/vector.h"
6 #include "vmath/quat.h"
7 #include "vmath/matrix.h"
10 struct anm_node;
11 struct anm_track;
13 namespace goatgfx {
15 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
16 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
18 // NOTE: 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 virtual XFormNode *get_parent();
48 virtual const XFormNode *get_parent() const;
50 // children management
51 virtual void add_child(XFormNode *child);
52 virtual void remove_child(XFormNode *child);
54 virtual int get_children_count() const;
55 virtual XFormNode *get_child(int idx);
56 virtual const XFormNode *get_child(int idx) const;
59 virtual void use_animation(int idx);
60 virtual void use_animation(const char *name);
61 virtual void use_animation(int aidx, int bidx, float t);
62 virtual void use_animation(const char *aname, const char *bname, float t);
64 virtual int get_active_animation_index(int which = 0) const;
65 virtual float get_active_animation_mix() const;
67 virtual int get_animation_count() const;
69 // add a new empty animation slot (recursive)
70 virtual void add_animation(const char *name = 0);
72 // set/get the current animation name (set is recursive)
73 virtual void set_animation_name(const char *name);
74 virtual const char *get_animation_name() const;
77 virtual void set_position(const Vector3 &pos, long tmsec = 0);
78 virtual Vector3 get_node_position(long tmsec = 0) const;
80 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
81 virtual Quaternion get_node_rotation(long tmsec = 0) const;
83 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
84 virtual Vector3 get_node_scaling(long tmsec = 0) const;
86 // these take hierarchy into account
87 virtual Vector3 get_position(long tmsec = 0) const;
88 virtual Quaternion get_rotation(long tmsec = 0) const;
89 virtual Vector3 get_scaling(long tmsec = 0) const;
91 virtual void set_pivot(const Vector3 &pivot);
92 virtual Vector3 get_pivot() const;
94 // the local matrix is concatenated with the regular node/anim matrix
95 virtual void set_local_matrix(const Matrix4x4 &mat);
96 virtual const Matrix4x4 &get_local_matrix() const;
98 // for bone nodes, the transformation of the bone in bind position
99 virtual void set_bone_matrix(const Matrix4x4 &bmat);
100 virtual const Matrix4x4 &get_bone_matrix() const;
102 // node transformation alone
103 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
105 // node transformation taking hierarchy into account
106 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
107 };
110 class Track {
111 private:
112 struct anm_track *trk;
113 Interp interp;
114 Extrap extrap;
116 public:
117 Track();
118 ~Track();
120 Track(const Track &trk);
121 Track &operator =(const Track &trk);
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(double def);
130 void set_value(float val, long tmsec = 0);
131 float get_value(long tmsec = 0) const;
133 // the same as get_value
134 float operator ()(long tmsec = 0) const;
135 };
137 class Track3 {
138 private:
139 Track track[3];
141 public:
142 void set_interpolator(Interp in);
143 Interp get_interpolator() const;
144 void set_extrapolator(Extrap ex);
145 Extrap get_extrapolator() const;
147 void set_default(const Vector3 &def);
149 void set_value(const Vector3 &val, long tmsec = 0);
150 Vector3 get_value(long tmsec = 0) const;
152 // the same as get_value
153 Vector3 operator ()(long tmsec = 0) const;
154 };
156 } // namespace goatgfx
158 #endif /* GOATGFX_XFORM_NODE_H_ */