diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj
index 797fdb2c..f3a87a2a 100644
--- a/Code/GamePhysics/GamePhysics.vcxproj
+++ b/Code/GamePhysics/GamePhysics.vcxproj
@@ -145,7 +145,11 @@
-
+
+
+
+
+
diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters
index b8f7f1a0..8c1b9f8b 100644
--- a/Code/GamePhysics/GamePhysics.vcxproj.filters
+++ b/Code/GamePhysics/GamePhysics.vcxproj.filters
@@ -16,16 +16,21 @@
{f2cb55b8-47a0-45c7-8dce-5b93f945a57b}
-
- {cac9a78f-f09b-4850-b1aa-ea87e8368678}
-
{792daa4b-b2f7-4664-9529-71a929365274}
-
+
Header Files\Include
+
+ Header Files\Implementation
+
+
+
+
+ Header Files\Implementation
+
\ No newline at end of file
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
new file mode 100644
index 00000000..09d0b1b5
--- /dev/null
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp
@@ -0,0 +1,63 @@
+#include "PhysicsAPI_Impl.h"
+
+using namespace Oyster;
+using namespace Physics;
+
+API_Impl instance;
+
+API & Instance()
+{
+ return instance;
+}
+
+API_Impl::API_Impl()
+{
+ /** @todo TODO: Fix this constructor.*/
+}
+
+API_Impl::~API_Impl()
+{
+ /** @todo TODO: Fix this destructor.*/
+}
+
+void API_Impl::SetDeltaTime( float deltaTime )
+{
+ /** @todo TODO: Fix this function.*/
+}
+void API_Impl::SetGravityConstant( float g )
+{
+ /** @todo TODO: Fix this function.*/
+}
+void API_Impl::SetAction( EventAction_Collision functionPointer )
+{
+ /** @todo TODO: Fix this function.*/
+}
+void API_Impl::SetAction( EventAction_Destruction functionPointer )
+{
+ /** @todo TODO: Fix this function.*/
+}
+
+void API_Impl::Update()
+{
+ /** @todo TODO: Fix this function.*/
+}
+
+void API_Impl::MoveToLimbo( unsigned int objRef )
+{
+ /** @todo TODO: Fix this function.*/
+}
+void API_Impl::ReleaseFromLimbo( unsigned int objRef )
+{
+ /** @todo TODO: Fix this function.*/
+}
+
+unsigned int API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer handle )
+{
+ /** @todo TODO: Fix this function.*/
+
+ return 0;
+}
+void API_Impl::DestroyObject( unsigned int objRef )
+{
+ /** @todo TODO: Fix this function.*/
+}
\ No newline at end of file
diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
new file mode 100644
index 00000000..445080b5
--- /dev/null
+++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h
@@ -0,0 +1,34 @@
+#ifndef PHYSICS_API_IMPL_H
+#define PHYSICS_API_IMPL_H
+
+#include "../PhysicsAPI.h"
+
+namespace Oyster
+{
+ namespace Physics
+ {
+ class API_Impl : public API
+ {
+ public:
+ API_Impl();
+ virtual ~API_Impl();
+
+ void SetDeltaTime( float deltaTime );
+ void SetGravityConstant( float g );
+ void SetAction( EventAction_Collision functionPointer );
+ void SetAction( EventAction_Destruction functionPointer );
+
+ void Update();
+
+ void MoveToLimbo( unsigned int objRef );
+ void ReleaseFromLimbo( unsigned int objRef );
+
+ unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle );
+ void DestroyObject( unsigned int objRef );
+ };
+
+ }
+
+}
+
+#endif
\ No newline at end of file
diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h
new file mode 100644
index 00000000..5711b277
--- /dev/null
+++ b/Code/GamePhysics/PhysicsAPI.h
@@ -0,0 +1,58 @@
+#ifndef PHYSICS_API_H
+#define PHYSICS_API_H
+
+#include "OysterMath.h"
+#include "Utilities.h"
+
+namespace Oyster
+{
+ namespace Physics
+ {
+ class API;
+ class IRigidBody;
+ class IParticle;
+
+ namespace Constant
+ {
+ const float gravity_constant = (const float)6.67284e-11; // The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields.
+ }
+
+ class API
+ {
+ public:
+ typedef void (*EventAction_Collision)( unsigned int, unsigned int );
+ typedef void (*EventAction_Destruction)( unsigned int, ::Utility::DynamicMemory::UniquePointer );
+
+ static API & Instance();
+
+ virtual void SetDeltaTime( float deltaTime ) = 0;
+ virtual void SetGravityConstant( float g ) = 0;
+ virtual void SetAction( EventAction_Collision functionPointer ) = 0;
+ virtual void SetAction( EventAction_Destruction functionPointer ) = 0;
+
+ virtual void Update() = 0;
+
+ virtual void MoveToLimbo( unsigned int objRef );
+ virtual void ReleaseFromLimbo( unsigned int objRef );
+
+ virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer handle );
+ virtual void DestroyObject( unsigned int objRef );
+ };
+
+ class IRigidBody
+ {
+ public:
+
+ };
+
+ class IParticle
+ {
+ public:
+
+ };
+ }
+
+ namespace Collision
+ {}
+}
+#endif
\ No newline at end of file
diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h
index 07ae50d3..25381140 100644
--- a/Code/OysterMath/OysterMath.h
+++ b/Code/OysterMath/OysterMath.h
@@ -218,10 +218,14 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
inline Float4x4 & ViewProjectionMatrix( const Float4x4 &view, const Float4x4 &projection, Float4x4 &targetMem = Float4x4() )
{ return targetMem = projection * view; }
- /// Helper inline function that sets and then returns targetMem = transformer * transformee
- inline Float4x4 & TransformMatrix( const Float4x4 &transformer, const Float4x4 &transformee, Float4x4 &targetMem = Float4x4() )
+ /** Helper inline function that sets and then returns targetMem = transformer * transformee */
+ inline Float4x4 & TransformMatrix( const Float4x4 &transformer, const Float4x4 &transformee, Float4x4 &targetMem )
{ return targetMem = transformer * transformee; }
+ /** Helper inline function that sets and then returns transformer * transformee */
+ inline Float4x4 TransformMatrix( const Float4x4 &transformer, const Float4x4 &transformee )
+ { return transformer * transformee; }
+
/// Helper inline function that sets and then returns targetMem = transformer * transformee
inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() )
{ return targetMem = transformer * transformee; }
diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp
index fff6b994..319d4da4 100644
--- a/Code/OysterPhysics3D/RigidBody.cpp
+++ b/Code/OysterPhysics3D/RigidBody.cpp
@@ -39,6 +39,9 @@ RigidBody & RigidBody::operator = ( const RigidBody &body )
void RigidBody::Update_LeapFrog( Float deltaTime )
{ // by Dan Andersson: Euler leap frog update when Runga Kutta is not needed
+ // Important! The member data is all world data except the Inertia tensor. Thus a new InertiaTensor needs to be created to be compatible with the rest of the world data.
+ Float4x4 wMomentOfInertiaTensor = TransformMatrix( this->box.orientation, this->momentOfInertiaTensor );
+
// updating the linear
// dv = dt * a = dt * F / m
// ds = dt * avg_v
@@ -49,7 +52,7 @@ void RigidBody::Update_LeapFrog( Float deltaTime )
// updating the angular
// dw = dt * a = dt * ( I^-1 * T )
// rotation = dt * avg_w
- Float4x4 inversedMomentOfInertiaTensor = this->momentOfInertiaTensor.GetInverse();
+ Float4x4 inversedMomentOfInertiaTensor = wMomentOfInertiaTensor.GetInverse();
Float3 deltaAngularVelocity = Formula::AngularImpulseAcceleration( inversedMomentOfInertiaTensor, this->impulseTorqueSum ); // I^-1 * T
deltaAngularVelocity *= deltaTime;
Float3 rotationAxis = ::Utility::Value::AverageWithDelta( Formula::AngularVelocity(inversedMomentOfInertiaTensor,this->angularMomentum), deltaAngularVelocity );
@@ -73,7 +76,7 @@ void RigidBody::Update_LeapFrog( Float deltaTime )
// update movements and clear impulses
this->linearMomentum += Formula::LinearMomentum( this->mass, deltaLinearVelocity );
this->impulseForceSum = Float3::null;
- this->angularMomentum += Formula::AngularMomentum( this->momentOfInertiaTensor, deltaAngularVelocity );
+ this->angularMomentum += Formula::AngularMomentum( wMomentOfInertiaTensor, deltaAngularVelocity );
this->impulseTorqueSum = Float3::null;
}
diff --git a/Code/OysterPhysics3D/RigidBody.h b/Code/OysterPhysics3D/RigidBody.h
index a2d32f95..4184ca2e 100644
--- a/Code/OysterPhysics3D/RigidBody.h
+++ b/Code/OysterPhysics3D/RigidBody.h
@@ -14,25 +14,23 @@ namespace Oyster { namespace Physics3D
struct RigidBody
{ /// A struct of a simple rigid body.
public:
- ::Oyster::Collision3D::Box box; /// Contains data representing physical presence.
- ::Oyster::Math::Float3 angularMomentum, /// The angular momentum H (Nm*s) around an parallell axis.
- linearMomentum, /// The linear momentum G (kg*m/s).
- impulseTorqueSum, /// The impulse torque T (Nm) that will be consumed each update.
- impulseForceSum; /// The impulse force F (N) that will be consumed each update.
+ ::Oyster::Collision3D::Box box; /** Contains data representing physical presence. (worldValue) */
+ ::Oyster::Math::Float3 angularMomentum, /** The angular momentum H (Nm*s) around an parallell axis. (worldValue) */
+ linearMomentum, /** The linear momentum G (kg*m/s). (worldValue) */
+ impulseTorqueSum, /** The impulse torque T (Nm) that will be consumed each update. (worldValue) */
+ impulseForceSum; /** The impulse force F (N) that will be consumed each update. (worldValue) */
RigidBody( const ::Oyster::Collision3D::Box &box = ::Oyster::Collision3D::Box(), ::Oyster::Math::Float mass = 1.0f );
RigidBody & operator = ( const RigidBody &body );
void Update_LeapFrog( ::Oyster::Math::Float deltaTime );
- void ApplyImpulseForce( const ::Oyster::Math::Float3 &f );
- void ApplyImpulseForceAt_Local( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
- void ApplyImpulseForceAt_World( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos ); /// ApplyImpulseForce_LocalPos is preferred
- void ApplyLinearImpulseAcceleration( const ::Oyster::Math::Float3 &a );
- void ApplyLinearImpulseAccelerationAt_Local( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos );
- void ApplyLinearImpulseAccelerationAt_World( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos ); /// ApplyLinearImpulseAcceleration_LocalPos is preferred
- void ApplyImpulseTorque( const ::Oyster::Math::Float3 &t );
- void ApplyAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a );
+ void ApplyImpulseForce( const ::Oyster::Math::Float3 &worldF );
+ void ApplyImpulseForceAt( const ::Oyster::Math::Float3 &worldF, const ::Oyster::Math::Float3 &worldPos );
+ void ApplyLinearImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
+ void ApplyLinearImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldA, const ::Oyster::Math::Float3 &worldPos );
+ void ApplyImpulseTorque( const ::Oyster::Math::Float3 &worldT );
+ void ApplyAngularImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
// ACCESS METHODS /////////////////////////////
@@ -68,56 +66,44 @@ namespace Oyster { namespace Physics3D
::Oyster::Math::Float3 GetLinearImpulseAcceleration() const;
::Oyster::Math::Float3 GetLinearVelocity() const;
- ::Oyster::Math::Float3 GetTangentialImpulseForceAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialImpulseForceAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialLinearMomentumAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialLinearMomentumAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialImpulseAccelerationAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialImpulseAccelerationAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialLinearVelocityAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetTangentialLinearVelocityAt_World( const ::Oyster::Math::Float3 &pos ) const;
+ ::Oyster::Math::Float3 GetTangentialImpulseForceAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetTangentialLinearMomentumAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetTangentialImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetTangentialLinearVelocityAt( const ::Oyster::Math::Float3 &worldPos ) const;
- ::Oyster::Math::Float3 GetImpulseForceAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetImpulseForceAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetLinearMomentumAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetLinearMomentumAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetImpulseAccelerationAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetImpulseAccelerationAt_World( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetLinearVelocityAt_Local( const ::Oyster::Math::Float3 &pos ) const;
- ::Oyster::Math::Float3 GetLinearVelocityAt_World( const ::Oyster::Math::Float3 &pos ) const;
+ ::Oyster::Math::Float3 GetImpulseForceAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetLinearMomentumAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldPos ) const;
+ ::Oyster::Math::Float3 GetLinearVelocityAt( const ::Oyster::Math::Float3 &worldPos ) const;
// SET METHODS ////////////////////////////////
- void SetMomentOfInertia( const ::Oyster::Math::Float4x4 &i );
+ void SetMomentOfInertia( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( const ::Oyster::Math::Float &m );
void SetMass_KeepMomentum( const ::Oyster::Math::Float &m );
void SetOrientation( const ::Oyster::Math::Float4x4 &o );
void SetSize( const ::Oyster::Math::Float3 &widthHeight );
- void SetCenter( const ::Oyster::Math::Float3 &p );
+ void SetCenter( const ::Oyster::Math::Float3 &worldPos );
- void SetImpulseTorque( const ::Oyster::Math::Float3 &t );
- void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
- void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a );
- void SetAngularVelocity( const ::Oyster::Math::Float3 &w );
+ void SetImpulseTorque( const ::Oyster::Math::Float3 &worldT );
+ void SetAngularMomentum( const ::Oyster::Math::Float3 &worldH );
+ void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
+ void SetAngularVelocity( const ::Oyster::Math::Float3 &worldW );
- void SetImpulseForce( const ::Oyster::Math::Float3 &f );
- void SetLinearMomentum( const ::Oyster::Math::Float3 &g );
- void SetLinearImpulseAcceleration( const ::Oyster::Math::Float3 &a );
- void SetLinearVelocity( const ::Oyster::Math::Float3 &v );
+ void SetImpulseForce( const ::Oyster::Math::Float3 &worldF );
+ void SetLinearMomentum( const ::Oyster::Math::Float3 &worldG );
+ void SetLinearImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
+ void SetLinearVelocity( const ::Oyster::Math::Float3 &worldV );
- void SetImpulseForceAt_Local( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
- void SetImpulseForceAt_World( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
- void SetLinearMomentumAt_Local( const ::Oyster::Math::Float3 &g, const ::Oyster::Math::Float3 &pos );
- void SetLinearMomentumAt_World( const ::Oyster::Math::Float3 &g, const ::Oyster::Math::Float3 &pos );
- void SetImpulseAccelerationAt_Local( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos );
- void SetImpulseAccelerationAt_World( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos );
- void SetLinearVelocityAt_Local( const ::Oyster::Math::Float3 &v, const ::Oyster::Math::Float3 &pos );
- void SetLinearVelocityAt_World( const ::Oyster::Math::Float3 &v, const ::Oyster::Math::Float3 &pos );
+ void SetImpulseForceAt( const ::Oyster::Math::Float3 &worldF, const ::Oyster::Math::Float3 &worldPos );
+ void SetLinearMomentumAt( const ::Oyster::Math::Float3 &worldG, const ::Oyster::Math::Float3 &worldPos );
+ void SetImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldA, const ::Oyster::Math::Float3 &worldPos );
+ void SetLinearVelocityAt( const ::Oyster::Math::Float3 &worldV, const ::Oyster::Math::Float3 &worldPos );
private:
- ::Oyster::Math::Float mass; /// m (kg)
- ::Oyster::Math::Float4x4 momentOfInertiaTensor; /// I (Nm*s) Tensor matrix ( only need to be 3x3 matrix, but is 4x4 for future hardware acceleration )
+ ::Oyster::Math::Float mass; /** m (kg) */
+ ::Oyster::Math::Float4x4 momentOfInertiaTensor; /** I (Nm*s) Tensor matrix ( only need to be 3x3 matrix, but is 4x4 for future hardware acceleration ) (localValue) */
};
// INLINE IMPLEMENTATIONS ///////////////////////////////////////