diff --git a/nif_math.cpp b/nif_math.cpp index 91b94d57afeb7d9f68353dd405779e2fb118b245..79cc7fcb900178d7c6a646c85dea2b9453cc3f4d 100644 --- a/nif_math.cpp +++ b/nif_math.cpp @@ -362,11 +362,11 @@ bool Matrix44::operator==( const Matrix44 & rh ) const { bool Matrix44::operator!=( const Matrix44 & rh ) const { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - if ( (*this)[i][j] == rh[i][j] ) - return false; + if ( (*this)[i][j] != rh[i][j] ) + return true; } } - return true; + return false; } Matrix44 Matrix44::Transpose() const { diff --git a/obj/NiAVObject.cpp b/obj/NiAVObject.cpp index e14640687516a7ac5bf656e4ebdc52497b807fec..409e7002670e05d3f2aacdcc0474fe0f7960815c 100644 --- a/obj/NiAVObject.cpp +++ b/obj/NiAVObject.cpp @@ -189,34 +189,23 @@ void NiAVObject::SetVisibility( bool n ) { } } -bool NiAVObject::GetHasBoundingBox() const { +bool NiAVObject::HasBoundingBox() const { return hasBoundingBox; } -void NiAVObject::SetHasBoundingBox( bool value ) { - hasBoundingBox = value; +void NiAVObject::ClearBoundingBox() { + hasBoundingBox = false; } BoundingBox NiAVObject::GetBoundingBox() const { - return boundingBox; -} - -void NiAVObject::SetBoundingBox( const BoundingBox & value ) { - boundingBox = value; -} - -Ref<NiCollisionData > NiAVObject::GetCollisionData() const { - return collisionData; -} - -void NiAVObject::SetCollisionData( Ref<NiCollisionData > value ) { - collisionData = value; -} - -Ref<NiCollisionObject > NiAVObject::GetCollisionObject() const { - return collisionObject; + if ( hasBoundingBox == true ) { + return boundingBox; + } else { + throw runtime_error("This NIAVObject has no Bounding Box."); + } } -void NiAVObject::SetCollisionObject( Ref<NiCollisionObject > value ) { - collisionObject = value; +void NiAVObject::SetBoundingBox( const BoundingBox & n ) { + boundingBox = n; + hasBoundingBox = true; } diff --git a/obj/NiAVObject.h b/obj/NiAVObject.h index ec2b3a2939d8f8268730c197fe6ebdd2631b881c..55e37a30e9dad44fd25e8c0e2476e778193405c7 100644 --- a/obj/NiAVObject.h +++ b/obj/NiAVObject.h @@ -40,7 +40,11 @@ public: virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version ); virtual list<NiObjectRef> GetRefs() const; - //TODO: Bounding Box. What to do with newer files that have a link? Wrap this in a function and translate? + //TODO: What to do with newer files that have a link for a bounding box? Wrap this in a function and translate? + void ClearBoundingBox(); + BoundingBox GetBoundingBox() const; + void SetBoundingBox( const BoundingBox & n ); + bool HasBoundingBox() const; /*! * This is a conveniance function that allows you to retrieve the full 4x4 matrix transform of a node. It accesses the "Rotation," "Translation," and "Scale" attributes and builds a complete 4x4 transformation matrix from them. @@ -92,31 +96,6 @@ public: bool GetVisibility() const; void SetVisibility( bool n ); - /*! - * Gets whether there is a bounding box associated with this object. - * \return True if there is a bounding box. - * \sa NiAVObject::SetHasBoundingBox - */ - bool GetHasBoundingBox() const; - - /*! - * Assigns whether there is a bounding box associated with this object. - * \sa NiAVObject::GetHasBoundingBox - */ - void SetHasBoundingBox( bool value ); - - /*! - * The bounding box. - */ - BoundingBox GetBoundingBox() const; - void SetBoundingBox( const BoundingBox & value ); - - /*! - * Bounding box: refers to NiCollisionData - */ - Ref<NiCollisionData > GetCollisionData() const; - void SetCollisionData( Ref<NiCollisionData> value ); - /*! * In Oblivion this links the havok objects. */ diff --git a/obj/NiSkinData.cpp b/obj/NiSkinData.cpp index a5cf7408fa1a6919be93c19e492fafe8af1fbfbd..0bf29e75b5f9c06f00b06c89861a3f1c4f46a6e3 100644 --- a/obj/NiSkinData.cpp +++ b/obj/NiSkinData.cpp @@ -94,10 +94,11 @@ NiSkinData::NiSkinData( const Ref<NiTriBasedGeom> & owner ) { Matrix44 owner_mat = owner->GetWorldTransform(); //Get Skeleton root world transform - Matrix44 skel_root_mat = skinInst->GetSkeletonRoot()->GetWorldTransform(); + Matrix44 sr_world = skinInst->GetSkeletonRoot()->GetWorldTransform(); //Inverse owner NiTriBasedGeom matrix & multiply with skeleton root matrix - Matrix44 res_mat = owner_mat.Inverse() * skel_root_mat; + Matrix44 res_mat = owner_mat.Inverse() * sr_world; + //Matrix44 res_mat = (sr_world.Inverse() * owner_mat).Inverse() * sr_world; //Store result res_mat.Decompose( translation, rotation, scale ); @@ -111,12 +112,13 @@ NiSkinData::NiSkinData( const Ref<NiTriBasedGeom> & owner ) { //Get bone world position bone_mat = bone_nodes[i]->GetWorldTransform(); + bone_mat = bone_mat * sr_world; + //Multiply NiTriBasedGeom matrix with inversed bone matrix res_mat = owner_mat * bone_mat.Inverse(); + //Store result res_mat.Decompose( boneList[i].translation, boneList[i].rotation, boneList[i].scale ); - - //TODO: Calculate center and radius of each bone } } \ No newline at end of file