diff --git a/Code/Debug/Tester.ilk b/Code/Debug/Tester.ilk
index 79772ebf..873f8fcc 100644
Binary files a/Code/Debug/Tester.ilk and b/Code/Debug/Tester.ilk differ
diff --git a/Code/Debug/Tester.pdb b/Code/Debug/Tester.pdb
index 49977712..307ffef8 100644
Binary files a/Code/Debug/Tester.pdb and b/Code/Debug/Tester.pdb differ
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/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h
index 184ea1a7..0495939d 100644
--- a/Code/OysterMath/LinearMath.h
+++ b/Code/OysterMath/LinearMath.h
@@ -444,8 +444,8 @@ namespace LinearAlgebra3D
ScalarType c = 1 / (nearClip - farClip);
return targetMem = ::LinearAlgebra::Matrix4x4( 2/width, 0, 0, 0,
0, 2/height, 0, 0,
- 0, 0, -c, 0, 0,
- 0, nearClip*c, 1 );
+ 0, 0, -c, nearClip*c,
+ 0, 0, 0, 1 );
}
/*******************************************************************
@@ -460,15 +460,27 @@ namespace LinearAlgebra3D
*******************************************************************/
template
::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &vertFoV, const ScalarType &aspect, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() )
- { /** @todo TODO: not tested */
+ {
ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ),
dDepth = farClip / (farClip - nearClip);
- return targetMem = ::LinearAlgebra::Matrix4x4( fov / aspect, 0, 0, 0,
+ return targetMem = ::LinearAlgebra::Matrix4x4( fov / aspect, 0, 0, 0,
0, fov, 0, 0,
0, 0, dDepth, -(dDepth * nearClip),
0, 0, 1, 0 );
}
+ template
+ ::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &left, const ScalarType &right, const ScalarType &top, const ScalarType &bottom, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() )
+ { /** @todo TODO: not tested */
+ ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ),
+ dDepth = farClip / (farClip - nearClip);
+ return targetMem = ::LinearAlgebra::Matrix4x4( 2*nearClip/(right - left), 0, -(right + left)/(right - left), 0,
+ 0, 2*nearClip/(top - bottom), -(top + bottom)/(top - bottom), 0,
+ 0, 0, dDepth, -(dDepth * nearClip),
+ 0, 0, 1, 0 );
+ }
+
+
template
inline ::LinearAlgebra::Vector3 VectorProjection( const ::LinearAlgebra::Vector3 &vector, const ::LinearAlgebra::Vector3 &axis )
{ return axis * ( vector.Dot(axis) / axis.Dot(axis) ); }
diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp
index 35df5975..a82658ee 100644
--- a/Code/OysterMath/OysterMath.cpp
+++ b/Code/OysterMath/OysterMath.cpp
@@ -141,6 +141,16 @@ namespace Oyster { namespace Math3D
return targetMem = ::LinearAlgebra3D::OrientationMatrix_LookAtPos( worldLookAt, normalizedUpVector, worldPos );
}
+ Float4x4 & ViewMatrix_LookAtDirection( const Float3 &normalizedDirection, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem )
+ {
+ return ::LinearAlgebra3D::InverseOrientationMatrix( ::LinearAlgebra3D::OrientationMatrix_LookAtDirection( normalizedDirection, normalizedUpVector, worldPos ), targetMem );
+ }
+
+ Float4x4 & ViewMatrix_LookAtPos( const Float3 &worldLookAt, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem )
+ {
+ return ::LinearAlgebra3D::InverseOrientationMatrix( ::LinearAlgebra3D::OrientationMatrix_LookAtPos( worldLookAt, normalizedUpVector, worldPos ), targetMem );
+ }
+
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem )
{
return ::LinearAlgebra3D::InverseOrientationMatrix( orientationMatrix, targetMem );
diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h
index 125fd29d..ab3b307f 100644
--- a/Code/OysterMath/OysterMath.h
+++ b/Code/OysterMath/OysterMath.h
@@ -213,6 +213,12 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
//! @todo TODO: Add documentation and not tested
Float4x4 & OrientationMatrix_LookAtPos( const Float3 &worldLookAt, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem = Float4x4() );
+ //! @todo TODO: Add documentation and not tested
+ Float4x4 & ViewMatrix_LookAtDirection( const Float3 &normalizedDirection, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem = Float4x4() );
+
+ //! @todo TODO: Add documentation and not tested
+ Float4x4 & ViewMatrix_LookAtPos( const Float3 &worldLookAt, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem = Float4x4() );
+
/// If orientationMatrix is assumed to be by all definitions a rigid orientation matrix aka rigid body matrix. Then this is a much faster inverse method.
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem = Float4x4() );
diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h
index ca9948a8..614a4a29 100644
--- a/Code/OysterPhysics3D/OysterPhysics3D.h
+++ b/Code/OysterPhysics3D/OysterPhysics3D.h
@@ -201,6 +201,96 @@ namespace Oyster { namespace Physics3D
namespace MomentOfInertia
{ /// Library of Formulas to calculate moment of inerta for simple shapes
/** @todo TODO: add MomentOfInertia tensor formulas */
+ inline ::Oyster::Math::Float CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
+ {
+ return (2.0f/5.0f)*mass*radius*radius;
+ }
+
+ inline ::Oyster::Math::Float4x4 Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
+ {
+ ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
+ inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateSphere( mass , radius );
+ inertia.m[1][1] = inertia.m[0][0];
+ inertia.m[2][2] = inertia.m[0][0];
+
+ return inertia;
+ }
+
+ inline ::Oyster::Math::Float CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
+ {
+ return (2.0f/3.0f)*mass*radius*radius;
+ }
+
+ inline ::Oyster::Math::Float4x4 HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
+ {
+ ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
+ inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateHollowSphere( mass, radius );
+ inertia.m[1][1] = inertia.m[0][0];
+ inertia.m[2][2] = inertia.m[0][0];
+
+ return inertia;
+ }
+
+ inline ::Oyster::Math::Float CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth )
+ {
+ return (1.0f/12.0f)*mass*(height*height + depth*depth);
+ }
+
+ inline ::Oyster::Math::Float CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
+ {
+ return (1.0f/12.0f)*mass*(width*width + depth*depth);
+ }
+
+ inline ::Oyster::Math::Float CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height )
+ {
+ return (1.0f/12.0f)*mass*(height*height + width*width);
+ }
+
+ inline ::Oyster::Math::Float4x4 Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth )
+ {
+ ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
+ inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass , height, depth );
+ inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass , width, depth );
+ inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass , height, width );
+
+ return inertia;
+ }
+
+ inline ::Oyster::Math::Float CalculateRodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length )
+ {
+ return (1.0f/12.0f)*mass*(length*length);
+ }
+
+ inline ::Oyster::Math::Float4x4 RodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length )
+ {
+ ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
+ inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateRodCenter( mass , length );
+ inertia.m[1][1] = inertia.m[0][0];
+ inertia.m[2][2] = inertia.m[0][0];
+
+ return inertia;
+ }
+
+ inline ::Oyster::Math::Float CalculateCylinderXY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius )
+ {
+ return (1.0f/12.0f)*mass*(3.0f*radius*radius + height*height);
+ }
+
+ inline ::Oyster::Math::Float CalculateCylinderZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius )
+ {
+ return 0.5f*mass*(radius*radius);
+ }
+
+ inline ::Oyster::Math::Float4x4 Cylinder( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius )
+ {
+ ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity;
+ inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderXY( mass , height, radius );
+ inertia.m[1][1] = inertia.m[0][0];
+ inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderZ( mass , radius );
+
+ return inertia;
+ }
+
}
}
} }
diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp
index c999324b..d495584c 100644
--- a/Code/OysterPhysics3D/Plane.cpp
+++ b/Code/OysterPhysics3D/Plane.cpp
@@ -31,7 +31,7 @@ bool Plane::Intersects( const ICollideable *target ) const
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
case Type_plane: return Utility::Intersect( *this, *(Plane*)target );
- case Type_triangle: return false; // TODO:
+ // case Type_triangle: return false; // TODO:
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
case Type_box: return Utility::Intersect( *(Box*)target, *this );
case Type_frustrum: return false; // TODO:
@@ -47,7 +47,7 @@ bool Plane::Contains( const ICollideable *target ) const
case Type_point: return Utility::Intersect( *this, *(Point*)target );
case Type_ray: return Utility::Contains( *this, *(Ray*)target );
case Type_plane: return Utility::Contains( *this, *(Plane*)target );
- case Type_triangle: return false; // TODO:
+ // case Type_triangle: return false; // TODO:
default: return false;
}
}
\ No newline at end of file
diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp
index 39cc93af..bf1057f3 100644
--- a/Code/OysterPhysics3D/Point.cpp
+++ b/Code/OysterPhysics3D/Point.cpp
@@ -30,7 +30,7 @@ bool Point::Intersects( const ICollideable *target ) const
case Type_ray: return Utility::Intersect( *(Ray*)target, *this, ((Ray*)target)->collisionDistance );
case Type_sphere: Utility::Intersect( *(Sphere*)target, *this );
case Type_plane: return Utility::Intersect( *(Plane*)target, *this );
- case Type_triangle: return false; // TODO:
+ //case Type_triangle: return false; // TODO:
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
case Type_box: return Utility::Intersect( *(Box*)target, *this );
case Type_frustrum: return false; // TODO:
diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp
index f7873437..1983a9ba 100644
--- a/Code/OysterPhysics3D/Ray.cpp
+++ b/Code/OysterPhysics3D/Ray.cpp
@@ -33,7 +33,7 @@ bool Ray::Intersects( const ICollideable *target ) const
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, this->collisionDistance, ((Ray*)target)->collisionDistance );
case Type_sphere: return Utility::Intersect( *(Sphere*)target, *this, this->collisionDistance );
case Type_plane: return Utility::Intersect( *(Plane*)target, *this, this->collisionDistance );
- case Type_triangle: return false; // TODO:
+ // case Type_triangle: return false; // TODO:
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this, this->collisionDistance );
case Type_box: return Utility::Intersect( *(Box*)target, *this, this->collisionDistance );
case Type_frustrum: return false; // TODO:
diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp
index 214a1aee..748d2272 100644
--- a/Code/OysterPhysics3D/RigidBody.cpp
+++ b/Code/OysterPhysics3D/RigidBody.cpp
@@ -225,7 +225,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;
@@ -234,7 +234,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
{
@@ -246,9 +257,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 );
diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp
index f138208c..324abeeb 100644
--- a/Code/OysterPhysics3D/Sphere.cpp
+++ b/Code/OysterPhysics3D/Sphere.cpp
@@ -27,7 +27,7 @@ bool Sphere::Intersects( const ICollideable *target ) const
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
case Type_sphere: Utility::Intersect( *this, *(Sphere*)target );
case Type_plane: return Utility::Intersect( *(Plane*)target, *this );
- case Type_triangle: return false; // TODO:
+ // case Type_triangle: return false; // TODO:
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this );
case Type_box: return Utility::Intersect( *(Box*)target, *this );
case Type_frustrum: return false; // TODO:
@@ -41,7 +41,7 @@ bool Sphere::Contains( const ICollideable *target ) const
{
case Type_point: return Utility::Intersect( *this, *(Point*)target );
case Type_sphere: return Utility::Contains( *this, *(Sphere*)target );
- case Type_triangle: return false; // TODO:
+ // case Type_triangle: return false; // TODO:
case Type_box_axis_aligned: return false; // TODO:
case Type_box: return false; // TODO:
case Type_frustrum: return false; // TODO: