vrshoot

diff src/xform_node.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/xform_node.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +/*
     1.5 +TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks)
     1.6 +*/
     1.7 +#ifndef XFORM_NODE_H_
     1.8 +#define XFORM_NODE_H_
     1.9 +
    1.10 +#include <vector>
    1.11 +#include <list>
    1.12 +#include "vmath/vector.h"
    1.13 +#include "vmath/quat.h"
    1.14 +#include "vmath/matrix.h"
    1.15 +
    1.16 +
    1.17 +struct anm_node;
    1.18 +struct anm_track;
    1.19 +
    1.20 +enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
    1.21 +enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
    1.22 +
    1.23 +enum {
    1.24 +	NODE_NULL		= 0,
    1.25 +	NODE_OBJECT		= 1,
    1.26 +	NODE_CAMERA		= 2,
    1.27 +	NODE_LIGHT		= 4,
    1.28 +
    1.29 +	NODE_ANY		= 0xffff
    1.30 +};
    1.31 +
    1.32 +// XXX all time arguments are milliseconds
    1.33 +
    1.34 +class XFormNode {
    1.35 +private:
    1.36 +	struct anm_node *anm;
    1.37 +	std::vector<XFormNode*> children;
    1.38 +	XFormNode *parent;
    1.39 +
    1.40 +	Interp interp;
    1.41 +	Extrap extrap;
    1.42 +
    1.43 +	Matrix4x4 local_matrix;
    1.44 +	Matrix4x4 bone_matrix;
    1.45 +
    1.46 +	XFormNode(const XFormNode &node) {}
    1.47 +	XFormNode &operator =(const XFormNode &node) { return *this; }
    1.48 +
    1.49 +protected:
    1.50 +	unsigned int type;
    1.51 +
    1.52 +public:
    1.53 +	XFormNode();
    1.54 +	virtual ~XFormNode();
    1.55 +
    1.56 +	virtual void set_name(const char *name);
    1.57 +	virtual const char *get_name() const;
    1.58 +
    1.59 +	virtual unsigned int get_type() const;
    1.60 +
    1.61 +	virtual void set_interpolator(Interp in);
    1.62 +	virtual Interp get_interpolator() const;
    1.63 +	virtual void set_extrapolator(Extrap ex);
    1.64 +	virtual Extrap get_extrapolator() const;
    1.65 +
    1.66 +	// children management
    1.67 +	virtual void add_child(XFormNode *child);
    1.68 +	virtual void remove_child(XFormNode *child);
    1.69 +
    1.70 +	virtual int get_children_count() const;
    1.71 +	virtual XFormNode *get_child(int idx);
    1.72 +	virtual const XFormNode *get_child(int idx) const;
    1.73 +
    1.74 +	virtual XFormNode *get_parent();
    1.75 +	virtual const XFormNode *get_parent() const;
    1.76 +
    1.77 +	virtual void clear_xform();
    1.78 +
    1.79 +	virtual void set_position(const Vector3 &pos, long tmsec = 0);
    1.80 +	virtual Vector3 get_node_position(long tmsec = 0) const;
    1.81 +
    1.82 +	virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
    1.83 +	virtual Quaternion get_node_rotation(long tmsec = 0) const;
    1.84 +
    1.85 +	virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
    1.86 +	virtual Vector3 get_node_scaling(long tmsec = 0) const;
    1.87 +
    1.88 +	// these take hierarchy into account
    1.89 +	virtual Vector3 get_position(long tmsec = 0) const;
    1.90 +	virtual Quaternion get_rotation(long tmsec = 0) const;
    1.91 +	virtual Vector3 get_scaling(long tmsec = 0) const;
    1.92 +
    1.93 +	virtual void set_pivot(const Vector3 &pivot);
    1.94 +	virtual Vector3 get_pivot() const;
    1.95 +
    1.96 +	// the local matrix is concatenated with the regular node/anim matrix
    1.97 +	virtual void set_local_matrix(const Matrix4x4 &mat);
    1.98 +	virtual const Matrix4x4 &get_local_matrix() const;
    1.99 +
   1.100 +	// for bone nodes, the transformation of the bone in bind position
   1.101 +	virtual void set_bone_matrix(const Matrix4x4 &bmat);
   1.102 +	virtual const Matrix4x4 &get_bone_matrix() const;
   1.103 +
   1.104 +	// node transformation alone
   1.105 +	virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
   1.106 +
   1.107 +	// node transformation taking hierarchy into account
   1.108 +	virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
   1.109 +
   1.110 +	// collect all nodes of a particular type or combination of types specified by the bitmask
   1.111 +	virtual std::list<XFormNode*> get_all_nodes(unsigned int type_mask);
   1.112 +	virtual std::list<const XFormNode*> get_all_nodes(unsigned int type_mask) const;
   1.113 +
   1.114 +	virtual void draw(long msec = 0) const;
   1.115 +};
   1.116 +
   1.117 +
   1.118 +class Track {
   1.119 +private:
   1.120 +	struct anm_track *trk;
   1.121 +	Interp interp;
   1.122 +	Extrap extrap;
   1.123 +
   1.124 +public:
   1.125 +	Track();
   1.126 +	~Track();
   1.127 +
   1.128 +	Track(const Track &trk);
   1.129 +	Track &operator =(const Track &trk);
   1.130 +
   1.131 +	void set_interpolator(Interp in);
   1.132 +	Interp get_interpolator() const;
   1.133 +	void set_extrapolator(Extrap ex);
   1.134 +	Extrap get_extrapolator() const;
   1.135 +
   1.136 +	void set_default(double def);
   1.137 +
   1.138 +	void set_value(float val, long tmsec = 0);
   1.139 +	float get_value(long tmsec = 0) const;
   1.140 +
   1.141 +	// the same as get_value
   1.142 +	float operator ()(long tmsec = 0) const;
   1.143 +};
   1.144 +
   1.145 +class Track3 {
   1.146 +private:
   1.147 +	Track track[3];
   1.148 +
   1.149 +public:
   1.150 +	void set_interpolator(Interp in);
   1.151 +	Interp get_interpolator() const;
   1.152 +	void set_extrapolator(Extrap ex);
   1.153 +	Extrap get_extrapolator() const;
   1.154 +
   1.155 +	void set_default(const Vector3 &def);
   1.156 +
   1.157 +	void set_value(const Vector3 &val, long tmsec = 0);
   1.158 +	Vector3 get_value(long tmsec = 0) const;
   1.159 +
   1.160 +	// the same as get_value
   1.161 +	Vector3 operator ()(long tmsec = 0) const;
   1.162 +};
   1.163 +
   1.164 +#endif	/* XFORM_NODE_H_ */