goat3dgfx
changeset 22:92bfb0206969
- made all XFormNode functions virtual
- added XFormNode::get_parent()
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Dec 2013 06:48:23 +0200 |
parents | 7c593721547f |
children | 0ac499409edd |
files | src/xform_node.cc src/xform_node.h |
diffstat | 2 files changed, 62 insertions(+), 38 deletions(-) [+] |
line diff
1.1 --- a/src/xform_node.cc Fri Dec 27 11:59:32 2013 +0200 1.2 +++ b/src/xform_node.cc Sat Dec 28 06:48:23 2013 +0200 1.3 @@ -13,6 +13,11 @@ 1.4 { 1.5 anm = new anm_node; 1.6 anm_init_node(anm); 1.7 + parent = 0; 1.8 + 1.9 + // TODO read them from anm to get the correct initial values 1.10 + interp = INTERP_LINEAR; 1.11 + extrap = EXTRAP_EXTEND; 1.12 } 1.13 1.14 XFormNode::~XFormNode() 1.15 @@ -53,10 +58,21 @@ 1.16 return extrap; 1.17 } 1.18 1.19 +XFormNode *XFormNode::get_parent() 1.20 +{ 1.21 + return parent; 1.22 +} 1.23 + 1.24 +const XFormNode *XFormNode::get_parent() const 1.25 +{ 1.26 + return parent; 1.27 +} 1.28 + 1.29 void XFormNode::add_child(XFormNode *child) 1.30 { 1.31 children.push_back(child); 1.32 anm_link_node(anm, child->anm); 1.33 + child->parent = this; 1.34 } 1.35 1.36 void XFormNode::remove_child(XFormNode *child) 1.37 @@ -66,6 +82,10 @@ 1.38 if(it != children.end()) { 1.39 children.erase(it); 1.40 anm_unlink_node(anm, child->anm); 1.41 + 1.42 + if(child->parent == this) { 1.43 + child->parent = 0; 1.44 + } 1.45 } 1.46 } 1.47
2.1 --- a/src/xform_node.h Fri Dec 27 11:59:32 2013 +0200 2.2 +++ b/src/xform_node.h Sat Dec 28 06:48:23 2013 +0200 2.3 @@ -21,6 +21,7 @@ 2.4 private: 2.5 struct anm_node *anm; 2.6 std::vector<XFormNode*> children; 2.7 + XFormNode *parent; 2.8 2.9 Interp interp; 2.10 Extrap extrap; 2.11 @@ -35,71 +36,74 @@ 2.12 XFormNode(); 2.13 virtual ~XFormNode(); 2.14 2.15 - void set_name(const char *name); 2.16 - const char *get_name() const; 2.17 + virtual void set_name(const char *name); 2.18 + virtual const char *get_name() const; 2.19 2.20 - void set_interpolator(Interp in); 2.21 - Interp get_interpolator() const; 2.22 - void set_extrapolator(Extrap ex); 2.23 - Extrap get_extrapolator() const; 2.24 + virtual void set_interpolator(Interp in); 2.25 + virtual Interp get_interpolator() const; 2.26 + virtual void set_extrapolator(Extrap ex); 2.27 + virtual Extrap get_extrapolator() const; 2.28 + 2.29 + virtual XFormNode *get_parent(); 2.30 + virtual const XFormNode *get_parent() const; 2.31 2.32 // children management 2.33 - void add_child(XFormNode *child); 2.34 - void remove_child(XFormNode *child); 2.35 + virtual void add_child(XFormNode *child); 2.36 + virtual void remove_child(XFormNode *child); 2.37 2.38 - int get_children_count() const; 2.39 - XFormNode *get_child(int idx); 2.40 - const XFormNode *get_child(int idx) const; 2.41 + virtual int get_children_count() const; 2.42 + virtual XFormNode *get_child(int idx); 2.43 + virtual const XFormNode *get_child(int idx) const; 2.44 2.45 2.46 - void use_animation(int idx); 2.47 - void use_animation(const char *name); 2.48 - void use_animation(int aidx, int bidx, float t); 2.49 - void use_animation(const char *aname, const char *bname, float t); 2.50 + virtual void use_animation(int idx); 2.51 + virtual void use_animation(const char *name); 2.52 + virtual void use_animation(int aidx, int bidx, float t); 2.53 + virtual void use_animation(const char *aname, const char *bname, float t); 2.54 2.55 - int get_active_animation_index(int which = 0) const; 2.56 - float get_active_animation_mix() const; 2.57 + virtual int get_active_animation_index(int which = 0) const; 2.58 + virtual float get_active_animation_mix() const; 2.59 2.60 - int get_animation_count() const; 2.61 + virtual int get_animation_count() const; 2.62 2.63 // add a new empty animation slot (recursive) 2.64 - void add_animation(const char *name = 0); 2.65 + virtual void add_animation(const char *name = 0); 2.66 2.67 // set/get the current animation name (set is recursive) 2.68 - void set_animation_name(const char *name); 2.69 - const char *get_animation_name() const; 2.70 + virtual void set_animation_name(const char *name); 2.71 + virtual const char *get_animation_name() const; 2.72 2.73 2.74 - void set_position(const Vector3 &pos, long tmsec = 0); 2.75 - Vector3 get_node_position(long tmsec = 0) const; 2.76 + virtual void set_position(const Vector3 &pos, long tmsec = 0); 2.77 + virtual Vector3 get_node_position(long tmsec = 0) const; 2.78 2.79 - void set_rotation(const Quaternion &quat, long tmsec = 0); 2.80 - Quaternion get_node_rotation(long tmsec = 0) const; 2.81 + virtual void set_rotation(const Quaternion &quat, long tmsec = 0); 2.82 + virtual Quaternion get_node_rotation(long tmsec = 0) const; 2.83 2.84 - void set_scaling(const Vector3 &pos, long tmsec = 0); 2.85 - Vector3 get_node_scaling(long tmsec = 0) const; 2.86 + virtual void set_scaling(const Vector3 &pos, long tmsec = 0); 2.87 + virtual Vector3 get_node_scaling(long tmsec = 0) const; 2.88 2.89 // these take hierarchy into account 2.90 - Vector3 get_position(long tmsec = 0) const; 2.91 - Quaternion get_rotation(long tmsec = 0) const; 2.92 - Vector3 get_scaling(long tmsec = 0) const; 2.93 + virtual Vector3 get_position(long tmsec = 0) const; 2.94 + virtual Quaternion get_rotation(long tmsec = 0) const; 2.95 + virtual Vector3 get_scaling(long tmsec = 0) const; 2.96 2.97 - void set_pivot(const Vector3 &pivot); 2.98 - Vector3 get_pivot() const; 2.99 + virtual void set_pivot(const Vector3 &pivot); 2.100 + virtual Vector3 get_pivot() const; 2.101 2.102 // the local matrix is concatenated with the regular node/anim matrix 2.103 - void set_local_matrix(const Matrix4x4 &mat); 2.104 - const Matrix4x4 &get_local_matrix() const; 2.105 + virtual void set_local_matrix(const Matrix4x4 &mat); 2.106 + virtual const Matrix4x4 &get_local_matrix() const; 2.107 2.108 // for bone nodes, the transformation of the bone in bind position 2.109 - void set_bone_matrix(const Matrix4x4 &bmat); 2.110 - const Matrix4x4 &get_bone_matrix() const; 2.111 + virtual void set_bone_matrix(const Matrix4x4 &bmat); 2.112 + virtual const Matrix4x4 &get_bone_matrix() const; 2.113 2.114 // node transformation alone 2.115 - void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; 2.116 + virtual void get_node_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; 2.117 2.118 // node transformation taking hierarchy into account 2.119 - void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; 2.120 + virtual void get_xform(long tmsec, Matrix4x4 *mat, Matrix4x4 *inv_mat = 0) const; 2.121 }; 2.122 2.123