conworlds

view src/xform_node.h @ 13:283cdfa7dda2

added a crapload of code from goat3dgfx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Aug 2014 09:41:24 +0300
parents
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 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
14 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
16 // NOTE: all time arguments are milliseconds
18 class XFormNode {
19 private:
20 struct anm_node *anm;
21 std::vector<XFormNode*> children;
22 XFormNode *parent;
24 Interp interp;
25 Extrap extrap;
27 Matrix4x4 local_matrix;
28 Matrix4x4 bone_matrix;
30 XFormNode(const XFormNode &node) {}
31 XFormNode &operator =(const XFormNode &node) { return *this; }
33 public:
34 XFormNode();
35 virtual ~XFormNode();
37 virtual void set_name(const char *name);
38 virtual const char *get_name() const;
40 virtual void set_interpolator(Interp in);
41 virtual Interp get_interpolator() const;
42 virtual void set_extrapolator(Extrap ex);
43 virtual Extrap get_extrapolator() const;
45 virtual XFormNode *get_parent();
46 virtual const XFormNode *get_parent() const;
48 // children management
49 virtual void add_child(XFormNode *child);
50 virtual void remove_child(XFormNode *child);
52 virtual int get_children_count() const;
53 virtual XFormNode *get_child(int idx);
54 virtual const XFormNode *get_child(int idx) const;
57 virtual void use_animation(int idx);
58 virtual void use_animation(const char *name);
59 virtual void use_animation(int aidx, int bidx, float t);
60 virtual void use_animation(const char *aname, const char *bname, float t);
62 virtual int get_active_animation_index(int which = 0) const;
63 virtual float get_active_animation_mix() const;
65 virtual int get_animation_count() const;
67 // add a new empty animation slot (recursive)
68 virtual void add_animation(const char *name = 0);
70 // set/get the current animation name (set is recursive)
71 virtual void set_animation_name(const char *name);
72 virtual const char *get_animation_name() const;
75 virtual void set_position(const Vector3 &pos, long tmsec = 0);
76 virtual Vector3 get_node_position(long tmsec = 0) const;
78 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
79 virtual Quaternion get_node_rotation(long tmsec = 0) const;
81 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
82 virtual Vector3 get_node_scaling(long tmsec = 0) const;
84 // these take hierarchy into account
85 virtual Vector3 get_position(long tmsec = 0) const;
86 virtual Quaternion get_rotation(long tmsec = 0) const;
87 virtual Vector3 get_scaling(long tmsec = 0) const;
89 virtual void set_pivot(const Vector3 &pivot);
90 virtual Vector3 get_pivot() const;
92 // the local matrix is concatenated with the regular node/anim matrix
93 virtual void set_local_matrix(const Matrix4x4 &mat);
94 virtual const Matrix4x4 &get_local_matrix() const;
96 // for bone nodes, the transformation of the bone in bind position
97 virtual void set_bone_matrix(const Matrix4x4 &bmat);
98 virtual const Matrix4x4 &get_bone_matrix() const;
100 // node transformation alone
101 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
103 // node transformation taking hierarchy into account
104 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
105 };
108 class Track {
109 private:
110 struct anm_track *trk;
111 Interp interp;
112 Extrap extrap;
114 public:
115 Track();
116 ~Track();
118 Track(const Track &trk);
119 Track &operator =(const Track &trk);
121 void set_interpolator(Interp in);
122 Interp get_interpolator() const;
123 void set_extrapolator(Extrap ex);
124 Extrap get_extrapolator() const;
126 void set_default(double def);
128 void set_value(float val, long tmsec = 0);
129 float get_value(long tmsec = 0) const;
131 // the same as get_value
132 float operator ()(long tmsec = 0) const;
133 };
135 class Track3 {
136 private:
137 Track track[3];
139 public:
140 void set_interpolator(Interp in);
141 Interp get_interpolator() const;
142 void set_extrapolator(Extrap ex);
143 Extrap get_extrapolator() const;
145 void set_default(const Vector3 &def);
147 void set_value(const Vector3 &val, long tmsec = 0);
148 Vector3 get_value(long tmsec = 0) const;
150 // the same as get_value
151 Vector3 operator ()(long tmsec = 0) const;
152 };
154 #endif /* GOATGFX_XFORM_NODE_H_ */