Merge branch 'Physics' of https://github.com/dean11/Danbias into Graphics

Conflicts:
	Code/Debug/Tester.ilk
	Code/Debug/Tester.pdb
This commit is contained in:
lanariel 2013-11-22 11:05:04 +01:00
commit 08b4fb5dfd
21 changed files with 569 additions and 74 deletions

Binary file not shown.

Binary file not shown.

View File

@ -146,10 +146,13 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Implementation\PhysicsAPI_Impl.h" />
<ClInclude Include="Implementation\SimpleRigidBody.h" />
<ClInclude Include="PhysicsAPI.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Implementation\NullBody.cpp" />
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
<ClCompile Include="Implementation\SimpleRigidBody.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -27,10 +27,19 @@
<ClInclude Include="Implementation\PhysicsAPI_Impl.h">
<Filter>Header Files\Implementation</Filter>
</ClInclude>
<ClInclude Include="Implementation\SimpleRigidBody.h">
<Filter>Header Files\Implementation</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Implementation\SimpleRigidBody.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Implementation\NullBody.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -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<ICustomBody> 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 ) {}

View File

@ -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<IRigidBody> handle )
unsigned int API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle )
{
/** @todo TODO: Fix this function.*/
return 0;
}
::Utility::DynamicMemory::UniquePointer<ICustomBody> 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<ICustomBody> API_Impl::CreateSimpleRigidBody() const
{
return new SimpleRigidBody();
}

View File

@ -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<IRigidBody> handle );
unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle );
::Utility::DynamicMemory::UniquePointer<ICustomBody> 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<ICustomBody> CreateSimpleRigidBody() const;
};
}

View File

@ -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<ICustomBody> 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
}

View File

@ -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<ICustomBody> 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

View File

@ -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

View File

@ -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<IRigidBody> );
typedef void (*EventAction_Destruction)( unsigned int, ::Utility::DynamicMemory::UniquePointer<ICustomBody> );
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<IRigidBody> handle ) = 0;
virtual ::Utility::DynamicMemory::UniquePointer<IRigidBody> ExtractObject( unsigned int objRef ) = 0;
virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle ) = 0;
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> 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<ICustomBody> CreateSimpleRigidBody() const = 0;
protected:
virtual ~API() {}
};
class IRigidBody
class ICustomBody
{
public:
virtual ~IRigidBody() {};
virtual ~ICustomBody() {};
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const = 0;
virtual bool IsSubscribingCollisions() const = 0;
virtual bool IsIntersecting( const IRigidBody &object, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) = 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 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
{
const unsigned int not_a_reference = ::Utility::Value::numeric_limits<unsigned int>::max();
class NullBody : public ICustomBody
{
public:
virtual ~NullBody();
};
::Utility::DynamicMemory::UniquePointer<ICustomBody> 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

View File

@ -444,8 +444,8 @@ namespace LinearAlgebra3D
ScalarType c = 1 / (nearClip - farClip);
return targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>( 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,7 +460,7 @@ namespace LinearAlgebra3D
*******************************************************************/
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & ProjectionMatrix_Perspective( const ScalarType &vertFoV, const ScalarType &aspect, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{ /** @todo TODO: not tested */
{
ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ),
dDepth = farClip / (farClip - nearClip);
return targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>( fov / aspect, 0, 0, 0,
@ -469,6 +469,18 @@ namespace LinearAlgebra3D
0, 0, 1, 0 );
}
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & ProjectionMatrix_Perspective( const ScalarType &left, const ScalarType &right, const ScalarType &top, const ScalarType &bottom, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{ /** @todo TODO: not tested */
ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ),
dDepth = farClip / (farClip - nearClip);
return targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>( 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<typename ScalarType>
inline ::LinearAlgebra::Vector3<ScalarType> VectorProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &axis )
{ return axis * ( vector.Dot(axis) / axis.Dot(axis) ); }

View File

@ -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 );

View File

@ -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() );

View File

@ -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;
}
}
}
} }

View File

@ -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;
}
}

View File

@ -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:

View File

@ -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:

View File

@ -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 );
}
}

View File

@ -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 );

View File

@ -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: