diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj
index ddc37cf4..232bc3ed 100644
--- a/Code/GamePhysics/GamePhysics.vcxproj
+++ b/Code/GamePhysics/GamePhysics.vcxproj
@@ -152,12 +152,14 @@
+
+
-
+
diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters
index 256cd6b1..4c0fd5f3 100644
--- a/Code/GamePhysics/GamePhysics.vcxproj.filters
+++ b/Code/GamePhysics/GamePhysics.vcxproj.filters
@@ -30,6 +30,9 @@
Header Files\Implementation
+
+ Header Files\Implementation
+
@@ -38,7 +41,10 @@
Source Files
-
+
+ Source Files
+
+
Source Files
diff --git a/Code/GamePhysics/DLLMain.cpp b/Code/GamePhysics/Implementation/DLLMain.cpp
similarity index 100%
rename from Code/GamePhysics/DLLMain.cpp
rename to Code/GamePhysics/Implementation/DLLMain.cpp
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
index 54af5084..6c3e4a27 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
@@ -57,6 +57,11 @@ API_Impl::API_Impl()
API_Impl::~API_Impl() {}
+void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
+{
+ //! @todo TODO: implement stub
+}
+
void API_Impl::SetDeltaTime( float deltaTime )
{
updateFrameLength = deltaTime;
@@ -155,6 +160,11 @@ void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orient
//! @todo TODO: implement stub
}
+void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
+{
+ //! @todo TODO: implement stub
+}
+
UniquePointer API_Impl::CreateSimpleRigidBody() const
{
return new SimpleRigidBody();
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
index c02ebdb2..5a2e3ef6 100644
--- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
@@ -13,6 +13,8 @@ namespace Oyster
API_Impl();
virtual ~API_Impl();
+ void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
+
void SetDeltaTime( float deltaTime );
void SetGravityConstant( float g );
void SetAction( EventAction_Collision functionPointer );
@@ -38,6 +40,7 @@ namespace Oyster
void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
+ void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
::Utility::DynamicMemory::UniquePointer CreateSimpleRigidBody() const;
private:
diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
index 7fd15e40..cc1f847b 100644
--- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
+++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp
@@ -7,7 +7,11 @@ using namespace ::Oyster::Collision3D;
using namespace ::Utility::DynamicMemory;
using namespace ::Utility::Value;
-SimpleRigidBody::SimpleRigidBody() : previous(), current() {}
+SimpleRigidBody::SimpleRigidBody()
+ : previous(), current(),
+ gravityNormal(0.0f),
+ subscribeCollision(true),
+ ignoreGravity(false) {}
SimpleRigidBody::~SimpleRigidBody() {}
@@ -18,7 +22,12 @@ UniquePointer SimpleRigidBody::Clone() const
bool SimpleRigidBody::IsSubscribingCollisions() const
{ // Assumption
- return true;
+ return this->subscribeCollision;
+}
+
+bool SimpleRigidBody::IsAffectedByGravity() const
+{
+ return !this->ignoreGravity;
}
bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const
@@ -51,6 +60,11 @@ Float3 & SimpleRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem
return targetMem = (worldPos - this->current.box.center).GetNormalized();
}
+Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
+{
+ return targetMem = this->gravityNormal;
+}
+
Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
{
return targetMem = this->current.box.center;
@@ -81,6 +95,22 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
return this->current == this->previous ? resting : altered;
}
+void SimpleRigidBody::SetGravity( bool ignore)
+{
+ this->ignoreGravity = ignore;
+ this->gravityNormal = Float3::null;
+}
+
+void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
+{
+ this->gravityNormal = normalizedVector;
+}
+
+void SimpleRigidBody::SetSubscription( bool subscribeCollision )
+{
+ this->subscribeCollision = subscribeCollision;
+}
+
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
{
this->current.SetMomentOfInertia_KeepVelocity( localI );
@@ -114,4 +144,9 @@ void SimpleRigidBody::SetRotation( const Float4x4 &rotation )
void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
{
this->current.SetOrientation( orientation );
+}
+
+void SimpleRigidBody::SetSize( const Float3 &size )
+{
+ this->current.SetSize( size );
}
\ No newline at end of file
diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h
index 99295e44..41be919b 100644
--- a/Code/GamePhysics/Implementation/SimpleRigidBody.h
+++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h
@@ -15,11 +15,13 @@ namespace Oyster { namespace Physics
::Utility::DynamicMemory::UniquePointer Clone() const;
bool IsSubscribingCollisions() const;
+ bool IsAffectedByGravity() const;
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) 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 & GetGravityNormal( ::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;
@@ -27,6 +29,9 @@ namespace Oyster { namespace Physics
UpdateState Update( ::Oyster::Math::Float timeStepLength );
+ void SetGravity( bool ignore);
+ void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
+ void SetSubscription( bool subscribeCollision );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
@@ -34,9 +39,12 @@ namespace Oyster { namespace Physics
void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
+ void SetSize( const ::Oyster::Math::Float3 &size );
private:
::Oyster::Physics3D::RigidBody previous, current;
+ ::Oyster::Math::Float3 gravityNormal;
+ bool subscribeCollision, ignoreGravity;
};
} }
diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h
index 0f4a80ee..bf80e6fa 100644
--- a/Code/GamePhysics/PhysicsAPI.h
+++ b/Code/GamePhysics/PhysicsAPI.h
@@ -51,6 +51,14 @@ namespace Oyster
/** Gets the Physics instance. */
static API & Instance();
+ /********************************************************
+ * Clears all content and reset Engine assetts such as buffers.
+ * @param numObjects: The predicted max number of active objects.
+ * @param numGravityWells: The predicted max number of active gravity wells.
+ * @param worldSize: The size of acceptable physics space.
+ ********************************************************/
+ virtual void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize ) = 0;
+
/********************************************************
* Sets the time length of each physics update frame.
********************************************************/
@@ -133,7 +141,7 @@ namespace Oyster
* @param worldF: Vector with the direction and magnitude of the force. [N]
********************************************************/
virtual void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0;
-
+
/********************************************************
* Apply force on an object.
* @param objRefA: A pointer to the ICustomBody representing a physical object.
@@ -196,6 +204,13 @@ namespace Oyster
********************************************************/
virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0;
+ /********************************************************
+ * Resizes the boundingBox.
+ * @param objRef: A pointer to the ICustomBody representing a physical object.
+ * @param size: New size of this [m]
+ ********************************************************/
+ virtual void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size ) = 0;
+
/********************************************************
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
* @return A pointer along with the responsibility to delete.
@@ -223,6 +238,11 @@ namespace Oyster
********************************************************/
virtual bool IsSubscribingCollisions() const = 0;
+ /********************************************************
+ * @return true if Engine should apply gravity on this object.
+ ********************************************************/
+ virtual bool IsAffectedByGravity() const = 0;
+
/********************************************************
* Performs a detailed Intersect test and returns if, when and where.
* @param object: What this is intersect testing against.
@@ -254,6 +274,13 @@ namespace Oyster
********************************************************/
virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
+ /********************************************************
+ * The gravity normal will have same direction as the total gravity force pulling on this and have the magnitude of 1.0f.
+ * @param targetMem: Provided memory that written into and then returned.
+ * @return a normalized vector in worldSpace. Exception: Null vector if no gravity been applied.
+ ********************************************************/
+ virtual ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
+
/********************************************************
* The world position of this center of gravity.
* @param targetMem: Provided memory that written into and then returned.
@@ -280,52 +307,74 @@ namespace Oyster
virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Is called during API::Update
********************************************************/
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
+
+ /********************************************************
+ * @param ignore: True if Engine should not apply Gravity.
+ ********************************************************/
+ virtual void SetGravity( bool ignore) = 0;
/********************************************************
- * To be only called by Engine
+ * Used by Engine
+ * @param normalizedVector: Should have same direction as the pullinggravity.
+ ********************************************************/
+ virtual void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ) = 0;
+
+ /********************************************************
+ * @param subscribeCollision: If is true, engine will call EventAction_Collision when this collides.
+ ********************************************************/
+ virtual void SetSubscription( bool subscribeCollision ) = 0;
+
+ /********************************************************
+ * To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepMomentum(...)
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetMass_KeepVelocity(...)
********************************************************/
virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetMass_KeepMomentum(...)
********************************************************/
virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetCenter(...)
********************************************************/
virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetRotation(...)
********************************************************/
virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0;
/********************************************************
- * To be only called by Engine
+ * To not be called if is in Engine
* Use API::SetOrientation(...)
********************************************************/
virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0;
+
+ /********************************************************
+ * To not be called if is in Engine
+ * Use API::SetSize(...)
+ ********************************************************/
+ virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
};
}
}