vrshoot

view src/xform_node.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
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 <list>
9 #include "vmath/vector.h"
10 #include "vmath/quat.h"
11 #include "vmath/matrix.h"
14 struct anm_node;
15 struct anm_track;
17 enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
18 enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
20 enum {
21 NODE_NULL = 0,
22 NODE_OBJECT = 1,
23 NODE_CAMERA = 2,
24 NODE_LIGHT = 4,
26 NODE_ANY = 0xffff
27 };
29 // XXX all time arguments are milliseconds
31 class XFormNode {
32 private:
33 struct anm_node *anm;
34 std::vector<XFormNode*> children;
35 XFormNode *parent;
37 Interp interp;
38 Extrap extrap;
40 Matrix4x4 local_matrix;
41 Matrix4x4 bone_matrix;
43 XFormNode(const XFormNode &node) {}
44 XFormNode &operator =(const XFormNode &node) { return *this; }
46 protected:
47 unsigned int type;
49 public:
50 XFormNode();
51 virtual ~XFormNode();
53 virtual void set_name(const char *name);
54 virtual const char *get_name() const;
56 virtual unsigned int get_type() const;
58 virtual void set_interpolator(Interp in);
59 virtual Interp get_interpolator() const;
60 virtual void set_extrapolator(Extrap ex);
61 virtual Extrap get_extrapolator() const;
63 // children management
64 virtual void add_child(XFormNode *child);
65 virtual void remove_child(XFormNode *child);
67 virtual int get_children_count() const;
68 virtual XFormNode *get_child(int idx);
69 virtual const XFormNode *get_child(int idx) const;
71 virtual XFormNode *get_parent();
72 virtual const XFormNode *get_parent() const;
74 virtual void clear_xform();
76 virtual void set_position(const Vector3 &pos, long tmsec = 0);
77 virtual Vector3 get_node_position(long tmsec = 0) const;
79 virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
80 virtual Quaternion get_node_rotation(long tmsec = 0) const;
82 virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
83 virtual Vector3 get_node_scaling(long tmsec = 0) const;
85 // these take hierarchy into account
86 virtual Vector3 get_position(long tmsec = 0) const;
87 virtual Quaternion get_rotation(long tmsec = 0) const;
88 virtual Vector3 get_scaling(long tmsec = 0) const;
90 virtual void set_pivot(const Vector3 &pivot);
91 virtual Vector3 get_pivot() const;
93 // the local matrix is concatenated with the regular node/anim matrix
94 virtual void set_local_matrix(const Matrix4x4 &mat);
95 virtual const Matrix4x4 &get_local_matrix() const;
97 // for bone nodes, the transformation of the bone in bind position
98 virtual void set_bone_matrix(const Matrix4x4 &bmat);
99 virtual const Matrix4x4 &get_bone_matrix() const;
101 // node transformation alone
102 virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
104 // node transformation taking hierarchy into account
105 virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
107 // collect all nodes of a particular type or combination of types specified by the bitmask
108 virtual std::list<XFormNode*> get_all_nodes(unsigned int type_mask);
109 virtual std::list<const XFormNode*> get_all_nodes(unsigned int type_mask) const;
111 virtual void draw(long msec = 0) const;
112 };
115 class Track {
116 private:
117 struct anm_track *trk;
118 Interp interp;
119 Extrap extrap;
121 public:
122 Track();
123 ~Track();
125 Track(const Track &trk);
126 Track &operator =(const Track &trk);
128 void set_interpolator(Interp in);
129 Interp get_interpolator() const;
130 void set_extrapolator(Extrap ex);
131 Extrap get_extrapolator() const;
133 void set_default(double def);
135 void set_value(float val, long tmsec = 0);
136 float get_value(long tmsec = 0) const;
138 // the same as get_value
139 float operator ()(long tmsec = 0) const;
140 };
142 class Track3 {
143 private:
144 Track track[3];
146 public:
147 void set_interpolator(Interp in);
148 Interp get_interpolator() const;
149 void set_extrapolator(Extrap ex);
150 Extrap get_extrapolator() const;
152 void set_default(const Vector3 &def);
154 void set_value(const Vector3 &val, long tmsec = 0);
155 Vector3 get_value(long tmsec = 0) const;
157 // the same as get_value
158 Vector3 operator ()(long tmsec = 0) const;
159 };
161 #endif /* XFORM_NODE_H_ */