From 2928e08252a8eb11c282bcbaa57ccfbccaf0cb58 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 12:13:14 +0100 Subject: [PATCH] SphericalRigidBody factory done not tested though --- .../Implementation/PhysicsAPI_Impl.cpp | 2 +- .../Implementation/SimpleRigidBody.cpp | 2 +- .../Implementation/SphericalRigidBody.cpp | 69 ++++++++++++------- .../Implementation/SphericalRigidBody.h | 3 +- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 2c745500..6c9b212a 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -169,7 +169,7 @@ UniquePointer API_Impl::CreateRigidBody( const API::SimpleBodyDescr UniquePointer API_Impl::CreateRigidBody( const API::SphericalBodyDescription &desc ) const { - return new SphericalRigidBody(); + return new SphericalRigidBody( desc ); } namespace Oyster { namespace Physics { namespace Default diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index d83aa399..40a1b7ee 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -10,7 +10,7 @@ using namespace ::Utility::Value; SimpleRigidBody::SimpleRigidBody() { - this->rigid = RigidBody(); + this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 16.0f, Float4x4::identity ); this->gravityNormal = Float3::null; this->collisionAction = Default::EventAction_Collision; this->ignoreGravity = false; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 1c9b7b52..baf8d98b 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -9,11 +9,33 @@ using namespace ::Utility::DynamicMemory; using namespace ::Utility::Value; SphericalRigidBody::SphericalRigidBody() - : previous(), current( Box(Float4x4::identity, Float3::null, Float3(1.0f)) ), - gravityNormal( 0.0f ), - collisionAction(Default::EventAction_Collision), - ignoreGravity( false ), - body( Float3::null, 0.5f ) {} +{ + this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 10.0f, Float4x4::identity ); + this->gravityNormal = Float3::null; + this->collisionAction = Default::EventAction_Collision; + this->ignoreGravity = false; + this->body = Sphere( Float3::null, 0.5f ); +} + +SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc ) +{ + this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, Float3(2.0f * desc.radius) ), + desc.mass, + desc.inertiaTensor ); + this->gravityNormal = Float3::null; + + if( desc.subscription ) + { + this->collisionAction = desc.subscription; + } + else + { + this->collisionAction = Default::EventAction_Collision; + } + + this->ignoreGravity = desc.ignoreGravity; + this->body = Sphere( desc.centerPosition, desc.radius ); +} SphericalRigidBody::~SphericalRigidBody() {} @@ -43,7 +65,7 @@ bool SphericalRigidBody::Intersects( const ICustomBody &object, Float timeStepLe bool SphericalRigidBody::Intersects( const ICollideable &shape ) const { - return this->current.box.Intersects( shape ); + return this->rigid.box.Intersects( shape ); } Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const @@ -54,7 +76,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const { //! @todo TODO: better implementation needed - return targetMem = (worldPos - this->current.box.center).GetNormalized(); + return targetMem = (worldPos - this->rigid.box.center).GetNormalized(); } Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const @@ -64,33 +86,32 @@ Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const { - return targetMem = this->current.box.center; + return targetMem = this->rigid.box.center; } Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const { - return targetMem = this->current.box.rotation; + return targetMem = this->rigid.box.rotation; } Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const { - return targetMem = this->current.GetOrientation(); + return targetMem = this->rigid.GetOrientation(); } Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const { - return targetMem = this->current.GetView(); + return targetMem = this->rigid.GetView(); } UpdateState SphericalRigidBody::Update( Float timeStepLength ) { - this->previous = this->current; // memorizing the old state - - this->current.Update_LeapFrog( timeStepLength ); - this->body.center = this->current.GetCenter(); + this->rigid.Update_LeapFrog( timeStepLength ); + this->body.center = this->rigid.GetCenter(); // compare previous and new state and return result - return this->current == this->previous ? UpdateState_resting : UpdateState_altered; + //return this->current == this->previous ? UpdateState_resting : UpdateState_altered; + return UpdateState_altered; } void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer ) @@ -118,43 +139,43 @@ void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector ) void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI ) { - this->current.SetMomentOfInertia_KeepVelocity( localI ); + this->rigid.SetMomentOfInertia_KeepVelocity( localI ); } void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI ) { - this->current.SetMomentOfInertia_KeepMomentum( localI ); + this->rigid.SetMomentOfInertia_KeepMomentum( localI ); } void SphericalRigidBody::SetMass_KeepVelocity( Float m ) { - this->current.SetMass_KeepVelocity( m ); + this->rigid.SetMass_KeepVelocity( m ); } void SphericalRigidBody::SetMass_KeepMomentum( Float m ) { - this->current.SetMass_KeepMomentum( m ); + this->rigid.SetMass_KeepMomentum( m ); } void SphericalRigidBody::SetCenter( const Float3 &worldPos ) { - this->current.SetCenter( worldPos ); + this->rigid.SetCenter( worldPos ); this->body.center = worldPos; } void SphericalRigidBody::SetRotation( const Float4x4 &rotation ) { - this->current.SetRotation( rotation ); + this->rigid.SetRotation( rotation ); } void SphericalRigidBody::SetOrientation( const Float4x4 &orientation ) { - this->current.SetOrientation( orientation ); + this->rigid.SetOrientation( orientation ); this->body.center = orientation.v[3].xyz; } void SphericalRigidBody::SetSize( const Float3 &size ) { - this->current.SetSize( size ); + this->rigid.SetSize( size ); this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )? } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 1540f7a1..61f5d604 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -11,6 +11,7 @@ namespace Oyster { namespace Physics { public: SphericalRigidBody(); + SphericalRigidBody( const API::SphericalBodyDescription &desc ); virtual ~SphericalRigidBody(); ::Utility::DynamicMemory::UniquePointer Clone() const; @@ -43,7 +44,7 @@ namespace Oyster { namespace Physics void SetSize( const ::Oyster::Math::Float3 &size ); private: - ::Oyster::Physics3D::RigidBody previous, current; + ::Oyster::Physics3D::RigidBody rigid; ::Oyster::Math::Float3 gravityNormal; EventAction_Collision collisionAction; bool ignoreGravity;