From c1c3b5e6af5ad5008a51bedfb6655a870f8e5bec Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 09:02:46 +0100 Subject: [PATCH] angular collision response fix Incorrect formula found and corrected --- Code/GamePhysics/PhysicsStructs-Impl.h | 4 +++- Code/OysterPhysics3D/OysterPhysics3D.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 1bdf07b6..9b13cacf 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -147,7 +147,9 @@ namespace Oyster inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const { //return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); // C3083 error? - return this->linearMomentum + ::Oyster::Math::Float4( this->angularMomentum.xyz.Cross((at - this->centerPos).xyz), 0.0f ); + + ::Oyster::Math::Float4 offset = at - this->centerPos; + return this->linearMomentum + ( ::Oyster::Math::Float4(this->angularMomentum.xyz.Cross(offset.xyz), 0.0f) /= offset.Dot(offset) ); } inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index f70d228f..84058387 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -63,7 +63,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float4 TangentialLinearMomentum( const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &worldOffset ) { - return ::Oyster::Math::Float4( angularMomentum.xyz.Cross(worldOffset.xyz), 0.0f ); + return ::Oyster::Math::Float4( angularMomentum.xyz.Cross(worldOffset.xyz), 0.0f ) /= worldOffset.Dot( worldOffset ); } /******************************************************************