gpuray_glsl

view src/xform_node.h @ 2:6e3a4daf3159

adding cones
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 09 Nov 2014 14:39:01 +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 "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, EXTRAP_PINGPONG };
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;
25 Interp interp;
26 Extrap extrap;
28 Matrix4x4 local_matrix;
29 Matrix4x4 bone_matrix;
31 XFormNode(const XFormNode &node) {}
32 XFormNode &operator =(const XFormNode &node) { return *this; }
34 public:
35 XFormNode();
36 virtual ~XFormNode();
38 void set_name(const char *name);
39 const char *get_name() const;
41 void set_interpolator(Interp in);
42 Interp get_interpolator() const;
43 void set_extrapolator(Extrap ex);
44 Extrap get_extrapolator() const;
46 // children management
47 void add_child(XFormNode *child);
48 void remove_child(XFormNode *child);
50 int get_children_count() const;
51 XFormNode *get_child(int idx);
52 const XFormNode *get_child(int idx) const;
55 void set_position(const Vector3 &pos, long tmsec = 0);
56 Vector3 get_node_position(long tmsec = 0) const;
58 void set_rotation(const Quaternion &quat, long tmsec = 0);
59 Quaternion get_node_rotation(long tmsec = 0) const;
61 void set_scaling(const Vector3 &pos, long tmsec = 0);
62 Vector3 get_node_scaling(long tmsec = 0) const;
64 // these take hierarchy into account
65 Vector3 get_position(long tmsec = 0) const;
66 Quaternion get_rotation(long tmsec = 0) const;
67 Vector3 get_scaling(long tmsec = 0) const;
69 void set_pivot(const Vector3 &pivot);
70 Vector3 get_pivot() const;
72 // the local matrix is concatenated with the regular node/anim matrix
73 void set_local_matrix(const Matrix4x4 &mat);
74 const Matrix4x4 &get_local_matrix() const;
76 // for bone nodes, the transformation of the bone in bind position
77 void set_bone_matrix(const Matrix4x4 &bmat);
78 const Matrix4x4 &get_bone_matrix() const;
80 // node transformation alone
81 void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
83 // node transformation taking hierarchy into account
84 void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
85 };
88 class Track {
89 private:
90 struct anm_track *trk;
91 Interp interp;
92 Extrap extrap;
94 public:
95 Track();
96 ~Track();
98 Track(const Track &trk);
99 Track &operator =(const Track &trk);
101 void set_interpolator(Interp in);
102 Interp get_interpolator() const;
103 void set_extrapolator(Extrap ex);
104 Extrap get_extrapolator() const;
106 void set_default(double def);
108 void set_value(float val, long tmsec = 0);
109 float get_value(long tmsec = 0) const;
111 // the same as get_value
112 float operator ()(long tmsec = 0) const;
113 };
115 class Track3 {
116 private:
117 Track track[3];
119 public:
120 void set_interpolator(Interp in);
121 Interp get_interpolator() const;
122 void set_extrapolator(Extrap ex);
123 Extrap get_extrapolator() const;
125 void set_default(const Vector3 &def);
127 void set_value(const Vector3 &val, long tmsec = 0);
128 Vector3 get_value(long tmsec = 0) const;
130 // the same as get_value
131 Vector3 operator ()(long tmsec = 0) const;
132 };
134 #endif /* XFORM_NODE_H_ */