conworlds

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/xform_node.h	Sun Aug 24 09:41:24 2014 +0300
     1.3 @@ -0,0 +1,154 @@
     1.4 +#ifndef GOATGFX_XFORM_NODE_H_
     1.5 +#define GOATGFX_XFORM_NODE_H_
     1.6 +
     1.7 +#include <vector>
     1.8 +#include "vmath/vector.h"
     1.9 +#include "vmath/quat.h"
    1.10 +#include "vmath/matrix.h"
    1.11 +
    1.12 +
    1.13 +struct anm_node;
    1.14 +struct anm_track;
    1.15 +
    1.16 +enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
    1.17 +enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
    1.18 +
    1.19 +// NOTE: all time arguments are milliseconds
    1.20 +
    1.21 +class XFormNode {
    1.22 +private:
    1.23 +	struct anm_node *anm;
    1.24 +	std::vector<XFormNode*> children;
    1.25 +	XFormNode *parent;
    1.26 +
    1.27 +	Interp interp;
    1.28 +	Extrap extrap;
    1.29 +
    1.30 +	Matrix4x4 local_matrix;
    1.31 +	Matrix4x4 bone_matrix;
    1.32 +
    1.33 +	XFormNode(const XFormNode &node) {}
    1.34 +	XFormNode &operator =(const XFormNode &node) { return *this; }
    1.35 +
    1.36 +public:
    1.37 +	XFormNode();
    1.38 +	virtual ~XFormNode();
    1.39 +
    1.40 +	virtual void set_name(const char *name);
    1.41 +	virtual const char *get_name() const;
    1.42 +
    1.43 +	virtual void set_interpolator(Interp in);
    1.44 +	virtual Interp get_interpolator() const;
    1.45 +	virtual void set_extrapolator(Extrap ex);
    1.46 +	virtual Extrap get_extrapolator() const;
    1.47 +
    1.48 +	virtual XFormNode *get_parent();
    1.49 +	virtual const XFormNode *get_parent() const;
    1.50 +
    1.51 +	// children management
    1.52 +	virtual void add_child(XFormNode *child);
    1.53 +	virtual void remove_child(XFormNode *child);
    1.54 +
    1.55 +	virtual int get_children_count() const;
    1.56 +	virtual XFormNode *get_child(int idx);
    1.57 +	virtual const XFormNode *get_child(int idx) const;
    1.58 +
    1.59 +
    1.60 +	virtual void use_animation(int idx);
    1.61 +	virtual void use_animation(const char *name);
    1.62 +	virtual void use_animation(int aidx, int bidx, float t);
    1.63 +	virtual void use_animation(const char *aname, const char *bname, float t);
    1.64 +
    1.65 +	virtual int get_active_animation_index(int which = 0) const;
    1.66 +	virtual float get_active_animation_mix() const;
    1.67 +
    1.68 +	virtual int get_animation_count() const;
    1.69 +
    1.70 +	// add a new empty animation slot (recursive)
    1.71 +	virtual void add_animation(const char *name = 0);
    1.72 +
    1.73 +	// set/get the current animation name (set is recursive)
    1.74 +	virtual void set_animation_name(const char *name);
    1.75 +	virtual const char *get_animation_name() const;
    1.76 +
    1.77 +
    1.78 +	virtual void set_position(const Vector3 &pos, long tmsec = 0);
    1.79 +	virtual Vector3 get_node_position(long tmsec = 0) const;
    1.80 +
    1.81 +	virtual void set_rotation(const Quaternion &quat, long tmsec = 0);
    1.82 +	virtual Quaternion get_node_rotation(long tmsec = 0) const;
    1.83 +
    1.84 +	virtual void set_scaling(const Vector3 &pos, long tmsec = 0);
    1.85 +	virtual Vector3 get_node_scaling(long tmsec = 0) const;
    1.86 +
    1.87 +	// these take hierarchy into account
    1.88 +	virtual Vector3 get_position(long tmsec = 0) const;
    1.89 +	virtual Quaternion get_rotation(long tmsec = 0) const;
    1.90 +	virtual Vector3 get_scaling(long tmsec = 0) const;
    1.91 +
    1.92 +	virtual void set_pivot(const Vector3 &pivot);
    1.93 +	virtual Vector3 get_pivot() const;
    1.94 +
    1.95 +	// the local matrix is concatenated with the regular node/anim matrix
    1.96 +	virtual void set_local_matrix(const Matrix4x4 &mat);
    1.97 +	virtual const Matrix4x4 &get_local_matrix() const;
    1.98 +
    1.99 +	// for bone nodes, the transformation of the bone in bind position
   1.100 +	virtual void set_bone_matrix(const Matrix4x4 &bmat);
   1.101 +	virtual const Matrix4x4 &get_bone_matrix() const;
   1.102 +
   1.103 +	// node transformation alone
   1.104 +	virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
   1.105 +
   1.106 +	// node transformation taking hierarchy into account
   1.107 +	virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
   1.108 +};
   1.109 +
   1.110 +
   1.111 +class Track {
   1.112 +private:
   1.113 +	struct anm_track *trk;
   1.114 +	Interp interp;
   1.115 +	Extrap extrap;
   1.116 +
   1.117 +public:
   1.118 +	Track();
   1.119 +	~Track();
   1.120 +
   1.121 +	Track(const Track &trk);
   1.122 +	Track &operator =(const Track &trk);
   1.123 +
   1.124 +	void set_interpolator(Interp in);
   1.125 +	Interp get_interpolator() const;
   1.126 +	void set_extrapolator(Extrap ex);
   1.127 +	Extrap get_extrapolator() const;
   1.128 +
   1.129 +	void set_default(double def);
   1.130 +
   1.131 +	void set_value(float val, long tmsec = 0);
   1.132 +	float get_value(long tmsec = 0) const;
   1.133 +
   1.134 +	// the same as get_value
   1.135 +	float operator ()(long tmsec = 0) const;
   1.136 +};
   1.137 +
   1.138 +class Track3 {
   1.139 +private:
   1.140 +	Track track[3];
   1.141 +
   1.142 +public:
   1.143 +	void set_interpolator(Interp in);
   1.144 +	Interp get_interpolator() const;
   1.145 +	void set_extrapolator(Extrap ex);
   1.146 +	Extrap get_extrapolator() const;
   1.147 +
   1.148 +	void set_default(const Vector3 &def);
   1.149 +
   1.150 +	void set_value(const Vector3 &val, long tmsec = 0);
   1.151 +	Vector3 get_value(long tmsec = 0) const;
   1.152 +
   1.153 +	// the same as get_value
   1.154 +	Vector3 operator ()(long tmsec = 0) const;
   1.155 +};
   1.156 +
   1.157 +#endif	/* GOATGFX_XFORM_NODE_H_ */