nuclear@0: /* nuclear@0: TODO: add multiple animations per node in libanim (i.e. multiple sets of tracks) nuclear@0: */ nuclear@0: #ifndef XFORM_NODE_H_ nuclear@0: #define XFORM_NODE_H_ nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include "vmath/vector.h" nuclear@0: #include "vmath/quat.h" nuclear@0: #include "vmath/matrix.h" nuclear@0: nuclear@0: nuclear@0: struct anm_node; nuclear@0: struct anm_track; nuclear@0: nuclear@0: enum Interp { INTERP_STEP, INTERP_LINEAR, INTERP_CUBIC }; nuclear@0: enum Extrap { EXTRAP_EXTEND, EXTRAP_CLAMP, EXTRAP_REPEAT }; nuclear@0: nuclear@0: enum { nuclear@0: NODE_NULL = 0, nuclear@0: NODE_OBJECT = 1, nuclear@0: NODE_CAMERA = 2, nuclear@0: NODE_LIGHT = 4, nuclear@0: nuclear@0: NODE_ANY = 0xffff nuclear@0: }; nuclear@0: nuclear@0: // XXX all time arguments are milliseconds nuclear@0: nuclear@0: class XFormNode { nuclear@0: private: nuclear@0: struct anm_node *anm; nuclear@0: std::vector children; nuclear@0: XFormNode *parent; nuclear@0: nuclear@0: Interp interp; nuclear@0: Extrap extrap; nuclear@0: nuclear@0: Matrix4x4 local_matrix; nuclear@0: Matrix4x4 bone_matrix; nuclear@0: nuclear@0: XFormNode(const XFormNode &node) {} nuclear@0: XFormNode &operator =(const XFormNode &node) { return *this; } nuclear@0: nuclear@0: protected: nuclear@0: unsigned int type; nuclear@0: nuclear@0: public: nuclear@0: XFormNode(); nuclear@0: virtual ~XFormNode(); nuclear@0: nuclear@0: virtual void set_name(const char *name); nuclear@0: virtual const char *get_name() const; nuclear@0: nuclear@0: virtual unsigned int get_type() const; nuclear@0: nuclear@0: virtual void set_interpolator(Interp in); nuclear@0: virtual Interp get_interpolator() const; nuclear@0: virtual void set_extrapolator(Extrap ex); nuclear@0: virtual Extrap get_extrapolator() const; nuclear@0: nuclear@0: // children management nuclear@0: virtual void add_child(XFormNode *child); nuclear@0: virtual void remove_child(XFormNode *child); nuclear@0: nuclear@0: virtual int get_children_count() const; nuclear@0: virtual XFormNode *get_child(int idx); nuclear@0: virtual const XFormNode *get_child(int idx) const; nuclear@0: nuclear@0: virtual XFormNode *get_parent(); nuclear@0: virtual const XFormNode *get_parent() const; nuclear@0: nuclear@0: virtual void clear_xform(); nuclear@0: nuclear@0: virtual void set_position(const Vector3 &pos, long tmsec = 0); nuclear@0: virtual Vector3 get_node_position(long tmsec = 0) const; nuclear@0: nuclear@0: virtual void set_rotation(const Quaternion &quat, long tmsec = 0); nuclear@0: virtual Quaternion get_node_rotation(long tmsec = 0) const; nuclear@0: nuclear@0: virtual void set_scaling(const Vector3 &pos, long tmsec = 0); nuclear@0: virtual Vector3 get_node_scaling(long tmsec = 0) const; nuclear@0: nuclear@0: // these take hierarchy into account nuclear@0: virtual Vector3 get_position(long tmsec = 0) const; nuclear@0: virtual Quaternion get_rotation(long tmsec = 0) const; nuclear@0: virtual Vector3 get_scaling(long tmsec = 0) const; nuclear@0: nuclear@0: virtual void set_pivot(const Vector3 &pivot); nuclear@0: virtual Vector3 get_pivot() const; nuclear@0: nuclear@0: // the local matrix is concatenated with the regular node/anim matrix nuclear@0: virtual void set_local_matrix(const Matrix4x4 &mat); nuclear@0: virtual const Matrix4x4 &get_local_matrix() const; nuclear@0: nuclear@0: // for bone nodes, the transformation of the bone in bind position nuclear@0: virtual void set_bone_matrix(const Matrix4x4 &bmat); nuclear@0: virtual const Matrix4x4 &get_bone_matrix() const; nuclear@0: nuclear@0: // node transformation alone nuclear@0: virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; nuclear@0: nuclear@0: // node transformation taking hierarchy into account nuclear@0: virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; nuclear@0: nuclear@0: // collect all nodes of a particular type or combination of types specified by the bitmask nuclear@0: virtual std::list get_all_nodes(unsigned int type_mask); nuclear@0: virtual std::list get_all_nodes(unsigned int type_mask) const; nuclear@0: nuclear@0: virtual void draw(long msec = 0) const; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: class Track { nuclear@0: private: nuclear@0: struct anm_track *trk; nuclear@0: Interp interp; nuclear@0: Extrap extrap; nuclear@0: nuclear@0: public: nuclear@0: Track(); nuclear@0: ~Track(); nuclear@0: nuclear@0: Track(const Track &trk); nuclear@0: Track &operator =(const Track &trk); nuclear@0: nuclear@0: void set_interpolator(Interp in); nuclear@0: Interp get_interpolator() const; nuclear@0: void set_extrapolator(Extrap ex); nuclear@0: Extrap get_extrapolator() const; nuclear@0: nuclear@0: void set_default(double def); nuclear@0: nuclear@0: void set_value(float val, long tmsec = 0); nuclear@0: float get_value(long tmsec = 0) const; nuclear@0: nuclear@0: // the same as get_value nuclear@0: float operator ()(long tmsec = 0) const; nuclear@0: }; nuclear@0: nuclear@0: class Track3 { nuclear@0: private: nuclear@0: Track track[3]; nuclear@0: nuclear@0: public: nuclear@0: void set_interpolator(Interp in); nuclear@0: Interp get_interpolator() const; nuclear@0: void set_extrapolator(Extrap ex); nuclear@0: Extrap get_extrapolator() const; nuclear@0: nuclear@0: void set_default(const Vector3 &def); nuclear@0: nuclear@0: void set_value(const Vector3 &val, long tmsec = 0); nuclear@0: Vector3 get_value(long tmsec = 0) const; nuclear@0: nuclear@0: // the same as get_value nuclear@0: Vector3 operator ()(long tmsec = 0) const; nuclear@0: }; nuclear@0: nuclear@0: #endif /* XFORM_NODE_H_ */