diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj index f3a87a2a..c9f6513c 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj +++ b/Code/GamePhysics/GamePhysics.vcxproj @@ -146,10 +146,13 @@ + + + diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters index 07661556..7118c2b5 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj.filters +++ b/Code/GamePhysics/GamePhysics.vcxproj.filters @@ -27,10 +27,19 @@ Header Files\Implementation + + Header Files\Implementation + Source Files + + Source Files + + + Source Files + \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/NullBody.cpp b/Code/GamePhysics/Implementation/NullBody.cpp new file mode 100644 index 00000000..76d2471d --- /dev/null +++ b/Code/GamePhysics/Implementation/NullBody.cpp @@ -0,0 +1,83 @@ +#include "..\PhysicsAPI.h" + +using namespace ::Oyster::Physics; +using namespace ::Oyster::Physics::Error; +using namespace ::Oyster::Math; +using namespace ::Oyster::Collision3D; +using namespace ::Utility::DynamicMemory; + +NullBody::~NullBody() {} + +UniquePointer NullBody::Clone() const +{ + return new NullBody( *this ); +} + +bool NullBody::IsSubscribingCollisions() const +{ + return false; +} + +bool NullBody::Intersects( const ICustomBody &object, Float &deltaWhen, Float3 &worldPointOfContact ) const +{ + return false; +} + +bool NullBody::Intersects( const ICollideable &shape ) const +{ + return false; +} + +unsigned int NullBody::GetReference() const +{ + return not_a_reference; +} + +Sphere & NullBody::GetBoundingSphere( Sphere &targetMem ) const +{ + return targetMem = Sphere( Float3::null, 0.0f ); +} + +Float3 & NullBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const +{ + return targetMem = Float3::standard_unit_z; +} + +Float3 & NullBody::GetCenter( Float3 &targetMem ) const +{ + return targetMem = Float3::null; +} + +Float4x4 & NullBody::GetRotation( Float4x4 &targetMem ) const +{ + return targetMem = Float4x4::identity; +} + +Float4x4 & NullBody::GetOrientation( Float4x4 &targetMem ) const +{ + return targetMem = Float4x4::identity; +} + +Float4x4 & NullBody::GetView( Float4x4 &targetMem ) const +{ + return targetMem = Float4x4::identity; +} + +UpdateState NullBody::Update( Float timeStepLength ) +{ + return resting; +} + +void NullBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI ) {} + +void NullBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI ) {} + +void NullBody::SetMass_KeepVelocity( Float m ) {} + +void NullBody::SetMass_KeepMomentum( Float m ) {} + +void NullBody::SetCenter( const Float3 &worldPos ) {} + +void NullBody::SetRotation( const Float4x4 &rotation ) {} + +void NullBody::SetOrientation( const Float4x4 &orientation ) {} \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 09d0b1b5..c1816a0b 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -1,7 +1,10 @@ #include "PhysicsAPI_Impl.h" +#include "SimpleRigidBody.h" -using namespace Oyster; -using namespace Physics; +using namespace ::Oyster::Physics; +using namespace ::Oyster::Math; +using namespace ::Oyster::Collision3D; +using namespace ::Utility::DynamicMemory; API_Impl instance; @@ -42,6 +45,12 @@ void API_Impl::Update() /** @todo TODO: Fix this function.*/ } +bool API_Impl::IsInLimbo( unsigned int objRef ) +{ + //! @todo TODO: implement stub + return true; +} + void API_Impl::MoveToLimbo( unsigned int objRef ) { /** @todo TODO: Fix this function.*/ @@ -51,13 +60,70 @@ void API_Impl::ReleaseFromLimbo( unsigned int objRef ) /** @todo TODO: Fix this function.*/ } -unsigned int API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer handle ) +unsigned int API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer handle ) { /** @todo TODO: Fix this function.*/ return 0; } + +::Utility::DynamicMemory::UniquePointer ExtractObject( unsigned int objRef ) +{ + //! @todo TODO: implement stub + return NULL; +} + void API_Impl::DestroyObject( unsigned int objRef ) { /** @todo TODO: Fix this function.*/ +} + +void API_Impl::ApplyForceAt( unsigned int objRef, const Float3 &worldPos, const Float3 &worldF ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::ApplyCollisionResponse( unsigned int objRefA, unsigned int objRefB, Float &deltaWhen, Float3 &worldPointOfContact ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( unsigned int objRef, const Float4x4 &localI ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( unsigned int objRef, const Float4x4 &localI ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetMass_KeepVelocity( unsigned int objRef, Float m ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetMass_KeepMomentum( unsigned int objRef, Float m ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetCenter( unsigned int objRef, const Float3 &worldPos ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetRotation( unsigned int objRef, const Float4x4 &rotation ) +{ + //! @todo TODO: implement stub +} + +void API_Impl::SetOrientation( unsigned int objRef, const Float4x4 &orientation ) +{ + //! @todo TODO: implement stub +} + +UniquePointer API_Impl::CreateSimpleRigidBody() const +{ + return new SimpleRigidBody(); } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 445080b5..3b1f217c 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -20,11 +20,28 @@ namespace Oyster void Update(); + bool IsInLimbo( unsigned int objRef ); void MoveToLimbo( unsigned int objRef ); void ReleaseFromLimbo( unsigned int objRef ); - unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle ); + unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle ); + ::Utility::DynamicMemory::UniquePointer ExtractObject( unsigned int objRef ); void DestroyObject( unsigned int objRef ); + + const ICustomBody & Peek( unsigned int objRef ) const; + + void ApplyForceAt( unsigned int objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); + void ApplyCollisionResponse( unsigned int objRefA, unsigned int objRefB, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ); + + void SetMomentOfInertiaTensor_KeepVelocity( unsigned int objRef, const ::Oyster::Math::Float4x4 &localI ); + void SetMomentOfInertiaTensor_KeepMomentum( unsigned int objRef, const ::Oyster::Math::Float4x4 &localI ); + void SetMass_KeepVelocity( unsigned int objRef, ::Oyster::Math::Float m ); + void SetMass_KeepMomentum( unsigned int objRef, ::Oyster::Math::Float m ); + void SetCenter( unsigned int objRef, const ::Oyster::Math::Float3 &worldPos ); + void SetRotation( unsigned int objRef, const ::Oyster::Math::Float4x4 &rotation ); + void SetOrientation( unsigned int objRef, const ::Oyster::Math::Float4x4 &orientation ); + + ::Utility::DynamicMemory::UniquePointer CreateSimpleRigidBody() const; }; } diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp new file mode 100644 index 00000000..59d501b4 --- /dev/null +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -0,0 +1,122 @@ +#include "SimpleRigidBody.h" + +using namespace ::Oyster::Physics; +using namespace ::Oyster::Math; +using namespace ::Oyster::Collision3D; +using namespace ::Utility::DynamicMemory; + +SimpleRigidBody::SimpleRigidBody() +{ + //! @todo TODO: implement stub +} + +SimpleRigidBody::~SimpleRigidBody() +{ + //! @todo TODO: implement stub +} + +UniquePointer SimpleRigidBody::Clone() const +{ + return new SimpleRigidBody( *this ); +} + +bool SimpleRigidBody::IsSubscribingCollisions() const +{ + //! @todo TODO: implement stub + return false; +} + +bool SimpleRigidBody::Intersects( const ICustomBody &object, Float &deltaWhen, Float3 &worldPointOfContact ) const +{ + //! @todo TODO: implement stub + return false; +} + +bool SimpleRigidBody::Intersects( const ICollideable &shape ) const +{ + //! @todo TODO: implement stub + return false; +} + +unsigned int SimpleRigidBody::GetReference() const +{ + //! @todo TODO: implement stub + return Error::not_a_reference; +} + +Sphere & SimpleRigidBody::GetBoundingSphere( Sphere &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Sphere( Float3::null, 0.0f ); +} + +Float3 & SimpleRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Float3::standard_unit_z; +} + +Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Float3::null; +} + +Float4x4 & SimpleRigidBody::GetRotation( Float4x4 &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Float4x4::identity; +} + +Float4x4 & SimpleRigidBody::GetOrientation( Float4x4 &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Float4x4::identity; +} + +Float4x4 & SimpleRigidBody::GetView( Float4x4 &targetMem ) const +{ + //! @todo TODO: implement stub + return targetMem = Float4x4::identity; +} + +UpdateState SimpleRigidBody::Update( Float timeStepLength ) +{ + //! @todo TODO: implement stub + return resting; +} + +void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetMass_KeepVelocity( Float m ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetMass_KeepMomentum( Float m ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetCenter( const Float3 &worldPos ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetRotation( const Float4x4 &rotation ) +{ + //! @todo TODO: implement stub +} + +void SimpleRigidBody::SetOrientation( const Float4x4 &orientation ) +{ + //! @todo TODO: implement stub +} \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h new file mode 100644 index 00000000..dd6531e6 --- /dev/null +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -0,0 +1,42 @@ +#ifndef OYSTER_PHYSICS_SIMPLE_RIGIDBODY_H +#define OYSTER_PHYSICS_SIMPLE_RIGIDBODY_H + +#include "..\PhysicsAPI.h" + +namespace Oyster { namespace Physics +{ + class SimpleRigidBody : public ICustomBody + { + public: + SimpleRigidBody(); + virtual ~SimpleRigidBody(); + + ::Utility::DynamicMemory::UniquePointer Clone() const; + + bool IsSubscribingCollisions() const; + bool Intersects( const ICustomBody &object, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; + bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const; + + unsigned int GetReference() const; + ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; + ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; + ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; + ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + + UpdateState Update( ::Oyster::Math::Float timeStepLength ); + + void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ); + void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ); + void SetMass_KeepVelocity( ::Oyster::Math::Float m ); + void SetMass_KeepMomentum( ::Oyster::Math::Float m ); + void SetCenter( const ::Oyster::Math::Float3 &worldPos ); + void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); + void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); + + private: + }; +} } + +#endif \ No newline at end of file diff --git a/Code/GamePhysics/Include/PhysicsAPI.h b/Code/GamePhysics/Include/PhysicsAPI.h deleted file mode 100644 index 3b40e705..00000000 --- a/Code/GamePhysics/Include/PhysicsAPI.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef PHYSICS_API_H -#define PHYSICS_API_H - -#include "OysterMath.h" - -namespace Oyster -{ - namespace Physics - { - class API; - class IRigidBody; - class IParticle; - - class API - { - public: - static API & Instance(); - }; - - class IRigidBody - { - public: - - }; - - class IParticle - { - public: - - }; - } - - namespace Collision - {} -} -#endif \ No newline at end of file diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index d9ae0a59..c1f6ef43 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -10,8 +10,7 @@ namespace Oyster namespace Physics { class API; - class IRigidBody; - class IParticle; + class ICustomBody; enum UpdateState { @@ -28,7 +27,7 @@ namespace Oyster { public: typedef void (*EventAction_Collision)( unsigned int, unsigned int ); - typedef void (*EventAction_Destruction)( unsigned int, ::Utility::DynamicMemory::UniquePointer ); + typedef void (*EventAction_Destruction)( unsigned int, ::Utility::DynamicMemory::UniquePointer ); static API & Instance(); @@ -43,34 +42,94 @@ namespace Oyster virtual void MoveToLimbo( unsigned int objRef ) = 0; virtual void ReleaseFromLimbo( unsigned int objRef ) = 0; - virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle ) = 0; - virtual ::Utility::DynamicMemory::UniquePointer ExtractObject( unsigned int objRef ) = 0; + virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle ) = 0; + virtual ::Utility::DynamicMemory::UniquePointer ExtractObject( unsigned int objRef ) = 0; virtual void DestroyObject( unsigned int objRef ) = 0; + + virtual const ICustomBody & Peek( unsigned int objRef ) const = 0; + + virtual void ApplyForceAt( unsigned int objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0; + virtual void ApplyCollisionResponse( unsigned int objRefA, unsigned int objRefB, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) = 0; + + virtual void SetMomentOfInertiaTensor_KeepVelocity( unsigned int objRef, const ::Oyster::Math::Float4x4 &localI ) = 0; + virtual void SetMomentOfInertiaTensor_KeepMomentum( unsigned int objRef, const ::Oyster::Math::Float4x4 &localI ) = 0; + virtual void SetMass_KeepVelocity( unsigned int objRef, ::Oyster::Math::Float m ) = 0; + virtual void SetMass_KeepMomentum( unsigned int objRef, ::Oyster::Math::Float m ) = 0; + virtual void SetCenter( unsigned int objRef, const ::Oyster::Math::Float3 &worldPos ) = 0; + virtual void SetRotation( unsigned int objRef, const ::Oyster::Math::Float4x4 &rotation ) = 0; + virtual void SetOrientation( unsigned int objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0; + + virtual ::Utility::DynamicMemory::UniquePointer CreateSimpleRigidBody() const = 0; + + protected: + virtual ~API() {} }; - class IRigidBody + class ICustomBody { public: - virtual ~IRigidBody() {}; + virtual ~ICustomBody() {}; + + virtual ::Utility::DynamicMemory::UniquePointer Clone() const = 0; + + virtual bool IsSubscribingCollisions() const = 0; + virtual bool Intersects( const ICustomBody &object, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const = 0; + virtual bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const = 0; + + virtual unsigned int GetReference() const = 0; + virtual ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const = 0; + virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0; + virtual ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0; + virtual ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0; + virtual ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0; + virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0; virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0; - - virtual bool IsSubscribingCollisions() const = 0; - virtual bool IsIntersecting( const IRigidBody &object, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) = 0; - virtual unsigned int GetReference() const = 0; - virtual ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const = 0; - virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0; + virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0; + virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0; + virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0; + virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0; + virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0; + virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0; + virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0; }; - class IParticle + namespace Error { - public: + const unsigned int not_a_reference = ::Utility::Value::numeric_limits::max(); - }; + class NullBody : public ICustomBody + { + public: + virtual ~NullBody(); + + ::Utility::DynamicMemory::UniquePointer Clone() const; + + bool IsSubscribingCollisions() const; + bool Intersects( const ICustomBody &object, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; + bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const; + + unsigned int GetReference() const; + ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; + ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; + ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; + ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + + UpdateState Update( ::Oyster::Math::Float timeStepLength ); + + void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ); + void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ); + void SetMass_KeepVelocity( ::Oyster::Math::Float m ); + void SetMass_KeepMomentum( ::Oyster::Math::Float m ); + void SetCenter( const ::Oyster::Math::Float3 &worldPos ); + void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); + void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); + + } const nobody; + } } - - namespace Collision - {} } #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index c4bd27ff..980fbcb5 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -229,7 +229,7 @@ Float3 RigidBody::GetLinearVelocity() const } void RigidBody::GetMomentumAt( const Float3 &worldPos, const Float3 &surfaceNormal, Float3 &normalMomentum, Float3 &tangentialMomentum ) const -{ +{ // by Dan Andersson Float3 worldOffset = worldPos - this->box.center; Float3 momentum = Formula::TangentialLinearMomentum( this->angularMomentum, worldOffset ); momentum += this->linearMomentum; @@ -238,7 +238,18 @@ void RigidBody::GetMomentumAt( const Float3 &worldPos, const Float3 &surfaceNorm tangentialMomentum = momentum - normalMomentum; } -void RigidBody::SetMomentOfInertia( const Float4x4 &localI ) +void RigidBody::SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) +{ // by Dan Andersson + if( localI.GetDeterminant() != 0.0f ) // insanitycheck! momentOfInertiaTensor must be invertable + { + Float3 w = Formula::AngularVelocity( (this->box.rotation * this->momentOfInertiaTensor).GetInverse(), + this->angularMomentum ); + this->momentOfInertiaTensor = localI; + this->angularMomentum = Formula::AngularMomentum( this->box.rotation*localI, w ); + } +} + +void RigidBody::SetMomentOfInertia_KeepMomentum( const Float4x4 &localI ) { // by Dan Andersson if( localI.GetDeterminant() != 0.0f ) // insanitycheck! momentOfInertiaTensor must be invertable { @@ -250,9 +261,9 @@ void RigidBody::SetMass_KeepVelocity( const Float &m ) { // by Dan Andersson if( m != 0.0f ) // insanitycheck! mass must be invertable { - Float3 velocity = Formula::LinearVelocity( this->mass, this->linearMomentum ); + Float3 v = Formula::LinearVelocity( this->mass, this->linearMomentum ); this->mass = m; - this->linearMomentum = Formula::LinearMomentum( this->mass, velocity ); + this->linearMomentum = Formula::LinearMomentum( this->mass, v ); } } diff --git a/Code/OysterPhysics3D/RigidBody.h b/Code/OysterPhysics3D/RigidBody.h index 19ce6bb2..b343ff07 100644 --- a/Code/OysterPhysics3D/RigidBody.h +++ b/Code/OysterPhysics3D/RigidBody.h @@ -68,7 +68,8 @@ namespace Oyster { namespace Physics3D // SET METHODS //////////////////////////////// - void SetMomentOfInertia( const ::Oyster::Math::Float4x4 &localI ); + void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ); + void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ); void SetMass_KeepVelocity( const ::Oyster::Math::Float &m ); void SetMass_KeepMomentum( const ::Oyster::Math::Float &m );