# HG changeset patch # User John Tsiombikas # Date 1388206103 -7200 # Node ID 92bfb0206969c40456dc90abd88f51943ef2a0ba # Parent 7c593721547ff385a1ddc3fe2a15a62383d372d6 - made all XFormNode functions virtual - added XFormNode::get_parent() diff -r 7c593721547f -r 92bfb0206969 src/xform_node.cc --- a/src/xform_node.cc Fri Dec 27 11:59:32 2013 +0200 +++ b/src/xform_node.cc Sat Dec 28 06:48:23 2013 +0200 @@ -13,6 +13,11 @@ { anm = new anm_node; anm_init_node(anm); + parent = 0; + + // TODO read them from anm to get the correct initial values + interp = INTERP_LINEAR; + extrap = EXTRAP_EXTEND; } XFormNode::~XFormNode() @@ -53,10 +58,21 @@ return extrap; } +XFormNode *XFormNode::get_parent() +{ + return parent; +} + +const XFormNode *XFormNode::get_parent() const +{ + return parent; +} + void XFormNode::add_child(XFormNode *child) { children.push_back(child); anm_link_node(anm, child->anm); + child->parent = this; } void XFormNode::remove_child(XFormNode *child) @@ -66,6 +82,10 @@ if(it != children.end()) { children.erase(it); anm_unlink_node(anm, child->anm); + + if(child->parent == this) { + child->parent = 0; + } } } diff -r 7c593721547f -r 92bfb0206969 src/xform_node.h --- a/src/xform_node.h Fri Dec 27 11:59:32 2013 +0200 +++ b/src/xform_node.h Sat Dec 28 06:48:23 2013 +0200 @@ -21,6 +21,7 @@ private: struct anm_node *anm; std::vector children; + XFormNode *parent; Interp interp; Extrap extrap; @@ -35,71 +36,74 @@ XFormNode(); virtual ~XFormNode(); - void set_name(const char *name); - const char *get_name() const; + virtual void set_name(const char *name); + virtual const char *get_name() const; - void set_interpolator(Interp in); - Interp get_interpolator() const; - void set_extrapolator(Extrap ex); - Extrap get_extrapolator() const; + virtual void set_interpolator(Interp in); + virtual Interp get_interpolator() const; + virtual void set_extrapolator(Extrap ex); + virtual Extrap get_extrapolator() const; + + virtual XFormNode *get_parent(); + virtual const XFormNode *get_parent() const; // children management - void add_child(XFormNode *child); - void remove_child(XFormNode *child); + virtual void add_child(XFormNode *child); + virtual void remove_child(XFormNode *child); - int get_children_count() const; - XFormNode *get_child(int idx); - const XFormNode *get_child(int idx) const; + virtual int get_children_count() const; + virtual XFormNode *get_child(int idx); + virtual const XFormNode *get_child(int idx) const; - void use_animation(int idx); - void use_animation(const char *name); - void use_animation(int aidx, int bidx, float t); - void use_animation(const char *aname, const char *bname, float t); + virtual void use_animation(int idx); + virtual void use_animation(const char *name); + virtual void use_animation(int aidx, int bidx, float t); + virtual void use_animation(const char *aname, const char *bname, float t); - int get_active_animation_index(int which = 0) const; - float get_active_animation_mix() const; + virtual int get_active_animation_index(int which = 0) const; + virtual float get_active_animation_mix() const; - int get_animation_count() const; + virtual int get_animation_count() const; // add a new empty animation slot (recursive) - void add_animation(const char *name = 0); + virtual void add_animation(const char *name = 0); // set/get the current animation name (set is recursive) - void set_animation_name(const char *name); - const char *get_animation_name() const; + virtual void set_animation_name(const char *name); + virtual const char *get_animation_name() const; - void set_position(const Vector3 &pos, long tmsec = 0); - Vector3 get_node_position(long tmsec = 0) const; + virtual void set_position(const Vector3 &pos, long tmsec = 0); + virtual Vector3 get_node_position(long tmsec = 0) const; - void set_rotation(const Quaternion &quat, long tmsec = 0); - Quaternion get_node_rotation(long tmsec = 0) const; + virtual void set_rotation(const Quaternion &quat, long tmsec = 0); + virtual Quaternion get_node_rotation(long tmsec = 0) const; - void set_scaling(const Vector3 &pos, long tmsec = 0); - Vector3 get_node_scaling(long tmsec = 0) const; + virtual void set_scaling(const Vector3 &pos, long tmsec = 0); + virtual Vector3 get_node_scaling(long tmsec = 0) const; // these take hierarchy into account - Vector3 get_position(long tmsec = 0) const; - Quaternion get_rotation(long tmsec = 0) const; - Vector3 get_scaling(long tmsec = 0) const; + virtual Vector3 get_position(long tmsec = 0) const; + virtual Quaternion get_rotation(long tmsec = 0) const; + virtual Vector3 get_scaling(long tmsec = 0) const; - void set_pivot(const Vector3 &pivot); - Vector3 get_pivot() const; + virtual void set_pivot(const Vector3 &pivot); + virtual Vector3 get_pivot() const; // the local matrix is concatenated with the regular node/anim matrix - void set_local_matrix(const Matrix4x4 &mat); - const Matrix4x4 &get_local_matrix() const; + virtual void set_local_matrix(const Matrix4x4 &mat); + virtual const Matrix4x4 &get_local_matrix() const; // for bone nodes, the transformation of the bone in bind position - void set_bone_matrix(const Matrix4x4 &bmat); - const Matrix4x4 &get_bone_matrix() const; + virtual void set_bone_matrix(const Matrix4x4 &bmat); + virtual const Matrix4x4 &get_bone_matrix() const; // node transformation alone - void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; + virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; // node transformation taking hierarchy into account - void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; + virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; };