goat3d

diff src/xform_node.h @ 1:e46529a5d057

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 17 Aug 2013 23:51:24 +0300
parents
children cd71f0b92f44
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/xform_node.h	Sat Aug 17 23:51:24 2013 +0300
     1.3 @@ -0,0 +1,134 @@
     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 "vmath/vector.h"
    1.12 +#include "vmath/quat.h"
    1.13 +#include "vmath/matrix.h"
    1.14 +
    1.15 +enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC };
    1.16 +enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT };
    1.17 +
    1.18 +struct anm_node;
    1.19 +struct anm_track;
    1.20 +
    1.21 +// XXX all time arguments are milliseconds
    1.22 +
    1.23 +class XFormNode {
    1.24 +private:
    1.25 +	struct anm_node *anm;
    1.26 +	std::vector<XFormNode*> children;
    1.27 +
    1.28 +	Interp interp;
    1.29 +	Extrap extrap;
    1.30 +
    1.31 +	Matrix4x4 local_matrix;
    1.32 +	Matrix4x4 bone_matrix;
    1.33 +
    1.34 +	XFormNode(const XFormNode &node) {}
    1.35 +	XFormNode &operator =(const XFormNode &node) { return *this; }
    1.36 +
    1.37 +public:
    1.38 +	XFormNode();
    1.39 +	virtual ~XFormNode();
    1.40 +
    1.41 +	void set_name(const char *name);
    1.42 +	const char *get_name() const;
    1.43 +
    1.44 +	void set_interpolator(Interp in);
    1.45 +	Interp get_interpolator() const;
    1.46 +	void set_extrapolator(Extrap ex);
    1.47 +	Extrap get_extrapolator() const;
    1.48 +
    1.49 +	// children management
    1.50 +	void add_child(XFormNode *child);
    1.51 +	void remove_child(XFormNode *child);
    1.52 +
    1.53 +	int get_children_count() const;
    1.54 +	XFormNode *get_child(int idx);
    1.55 +	const XFormNode *get_child(int idx) const;
    1.56 +
    1.57 +
    1.58 +	void set_position(const Vector3 &pos, long tmsec = 0);
    1.59 +	Vector3 get_node_position(long tmsec = 0) const;
    1.60 +
    1.61 +	void set_rotation(const Quaternion &quat, long tmsec = 0);
    1.62 +	Quaternion get_node_rotation(long tmsec = 0) const;
    1.63 +
    1.64 +	void set_scaling(const Vector3 &pos, long tmsec = 0);
    1.65 +	Vector3 get_node_scaling(long tmsec = 0) const;
    1.66 +
    1.67 +	// these take hierarchy into account
    1.68 +	Vector3 get_position(long tmsec = 0) const;
    1.69 +	Quaternion get_rotation(long tmsec = 0) const;
    1.70 +	Vector3 get_scaling(long tmsec = 0) const;
    1.71 +
    1.72 +	void set_pivot(const Vector3 &pivot);
    1.73 +	Vector3 get_pivot() const;
    1.74 +
    1.75 +	// the local matrix is concatenated with the regular node/anim matrix
    1.76 +	void set_local_matrix(const Matrix4x4 &mat);
    1.77 +	const Matrix4x4 &get_local_matrix() const;
    1.78 +
    1.79 +	// for bone nodes, the transformation of the bone in bind position
    1.80 +	void set_bone_matrix(const Matrix4x4 &bmat);
    1.81 +	const Matrix4x4 &get_bone_matrix() const;
    1.82 +
    1.83 +	// node transformation alone
    1.84 +	void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
    1.85 +
    1.86 +	// node transformation taking hierarchy into account
    1.87 +	void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const;
    1.88 +};
    1.89 +
    1.90 +
    1.91 +class Track {
    1.92 +private:
    1.93 +	struct anm_track *trk;
    1.94 +	Interp interp;
    1.95 +	Extrap extrap;
    1.96 +
    1.97 +public:
    1.98 +	Track();
    1.99 +	~Track();
   1.100 +
   1.101 +	Track(const Track &trk);
   1.102 +	Track &operator =(const Track &trk);
   1.103 +
   1.104 +	void set_interpolator(Interp in);
   1.105 +	Interp get_interpolator() const;
   1.106 +	void set_extrapolator(Extrap ex);
   1.107 +	Extrap get_extrapolator() const;
   1.108 +
   1.109 +	void set_default(double def);
   1.110 +
   1.111 +	void set_value(float val, long tmsec = 0);
   1.112 +	float get_value(long tmsec = 0) const;
   1.113 +
   1.114 +	// the same as get_value
   1.115 +	float operator ()(long tmsec = 0) const;
   1.116 +};
   1.117 +
   1.118 +class Track3 {
   1.119 +private:
   1.120 +	Track track[3];
   1.121 +
   1.122 +public:
   1.123 +	void set_interpolator(Interp in);
   1.124 +	Interp get_interpolator() const;
   1.125 +	void set_extrapolator(Extrap ex);
   1.126 +	Extrap get_extrapolator() const;
   1.127 +
   1.128 +	void set_default(const Vector3 &def);
   1.129 +
   1.130 +	void set_value(const Vector3 &val, long tmsec = 0);
   1.131 +	Vector3 get_value(long tmsec = 0) const;
   1.132 +
   1.133 +	// the same as get_value
   1.134 +	Vector3 operator ()(long tmsec = 0) const;
   1.135 +};
   1.136 +
   1.137 +#endif	/* XFORM_NODE_H_ */