Merge remote-tracking branch 'origin/RigidBody' into Graphics
This commit is contained in:
commit
8af3cde642
|
@ -145,7 +145,11 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Include\GamePhysics.h" />
|
<ClInclude Include="Implementation\PhysicsAPI_Impl.h" />
|
||||||
|
<ClInclude Include="PhysicsAPI.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|
|
@ -16,16 +16,21 @@
|
||||||
<Filter Include="Header Files\Implementation">
|
<Filter Include="Header Files\Implementation">
|
||||||
<UniqueIdentifier>{f2cb55b8-47a0-45c7-8dce-5b93f945a57b}</UniqueIdentifier>
|
<UniqueIdentifier>{f2cb55b8-47a0-45c7-8dce-5b93f945a57b}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="Source Files\Implementation">
|
|
||||||
<UniqueIdentifier>{cac9a78f-f09b-4850-b1aa-ea87e8368678}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files\Include">
|
<Filter Include="Header Files\Include">
|
||||||
<UniqueIdentifier>{792daa4b-b2f7-4664-9529-71a929365274}</UniqueIdentifier>
|
<UniqueIdentifier>{792daa4b-b2f7-4664-9529-71a929365274}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Include\GamePhysics.h">
|
<ClInclude Include="PhysicsAPI.h">
|
||||||
<Filter>Header Files\Include</Filter>
|
<Filter>Header Files\Include</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Implementation\PhysicsAPI_Impl.h">
|
||||||
|
<Filter>Header Files\Implementation</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -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<IRigidBody> handle )
|
||||||
|
{
|
||||||
|
/** @todo TODO: Fix this function.*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void API_Impl::DestroyObject( unsigned int objRef )
|
||||||
|
{
|
||||||
|
/** @todo TODO: Fix this function.*/
|
||||||
|
}
|
|
@ -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<IRigidBody> handle );
|
||||||
|
void DestroyObject( unsigned int objRef );
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,76 @@
|
||||||
|
#ifndef PHYSICS_API_H
|
||||||
|
#define PHYSICS_API_H
|
||||||
|
|
||||||
|
#include "OysterCollision3D.h"
|
||||||
|
#include "OysterMath.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Physics
|
||||||
|
{
|
||||||
|
class API;
|
||||||
|
class IRigidBody;
|
||||||
|
class IParticle;
|
||||||
|
|
||||||
|
enum UpdateState
|
||||||
|
{
|
||||||
|
resting,
|
||||||
|
altered
|
||||||
|
};
|
||||||
|
|
||||||
|
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<IRigidBody> );
|
||||||
|
|
||||||
|
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 bool IsInLimbo( unsigned int objRef ) = 0;
|
||||||
|
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 void DestroyObject( unsigned int objRef ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IRigidBody
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IRigidBody() {};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IParticle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Collision
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -161,6 +161,32 @@ namespace LinearAlgebra2D
|
||||||
return targetMem = ::LinearAlgebra::Matrix3x3<ScalarType>( c,-s, 0, s, c, 0, 0, 0, 1 );
|
return targetMem = ::LinearAlgebra::Matrix3x3<ScalarType>( c,-s, 0, s, c, 0, 0, 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix2x2<ScalarType> & InverseRotationMatrix( const ::LinearAlgebra::Matrix2x2<ScalarType> &rotationMatrix )
|
||||||
|
{
|
||||||
|
return rotationMatrix.GetTranspose();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> & InverseRotationMatrix( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotationMatrix )
|
||||||
|
{
|
||||||
|
return rotationMatrix.GetTranspose();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> OrientationMatrix( const ::LinearAlgebra::Matrix2x2<ScalarType> &rotation, const ::LinearAlgebra::Vector2<ScalarType> &translation )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix3x3<ScalarType>( ::LinearAlgebra::Vector3<ScalarType>(rotation.v[0], 0),
|
||||||
|
::LinearAlgebra::Vector3<ScalarType>(rotation.v[1], 0),
|
||||||
|
::LinearAlgebra::Vector3<ScalarType>(translation, 1) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> OrientationMatrix( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotation, const ::LinearAlgebra::Vector2<ScalarType> &translation )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix3x3<ScalarType>( rotation.v[0], rotation.v[1], ::LinearAlgebra::Vector3<ScalarType>(translation, 1) );
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ScalarType>
|
template<typename ScalarType>
|
||||||
inline ::LinearAlgebra::Matrix3x3<ScalarType> & OrientationMatrix( const ScalarType &radian, const ::LinearAlgebra::Vector2<ScalarType> &position, ::LinearAlgebra::Matrix3x3<ScalarType> &targetMem = ::LinearAlgebra::Matrix3x3<ScalarType>() )
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> & OrientationMatrix( const ScalarType &radian, const ::LinearAlgebra::Vector2<ScalarType> &position, ::LinearAlgebra::Matrix3x3<ScalarType> &targetMem = ::LinearAlgebra::Matrix3x3<ScalarType>() )
|
||||||
{
|
{
|
||||||
|
@ -197,6 +223,12 @@ namespace LinearAlgebra2D
|
||||||
orientationMatrix.m12, orientationMatrix.m22, -orientationMatrix.v[1].xy.Dot(orientationMatrix.v[2].xy),
|
orientationMatrix.m12, orientationMatrix.m22, -orientationMatrix.v[1].xy.Dot(orientationMatrix.v[2].xy),
|
||||||
0, 0, 1 );
|
0, 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> ExtractRotationMatrix( const ::LinearAlgebra::Matrix3x3<ScalarType> &orientationMatrix )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix3x3<ScalarType>( orientationMatrix.v[0], orientationMatrix.v[1], ::LinearAlgebra::Vector3<ScalarType>::standard_unit_z );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace LinearAlgebra3D
|
namespace LinearAlgebra3D
|
||||||
|
@ -283,6 +315,33 @@ namespace LinearAlgebra3D
|
||||||
return targetMem;
|
return targetMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix3x3<ScalarType> & InverseRotationMatrix( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotationMatrix )
|
||||||
|
{
|
||||||
|
return rotationMatrix.GetTranspose();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> & InverseRotationMatrix( const ::LinearAlgebra::Matrix4x4<ScalarType> &rotationMatrix )
|
||||||
|
{
|
||||||
|
return rotationMatrix.GetTranspose();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> OrientationMatrix( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotation, const ::LinearAlgebra::Vector3<ScalarType> &translation )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix4x4<ScalarType>( ::LinearAlgebra::Vector4<ScalarType>(rotation.v[0], 0),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>(rotation.v[1], 0),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>(rotation.v[2], 0),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>(translation, 1) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> OrientationMatrix( const ::LinearAlgebra::Matrix4x4<ScalarType> &rotation, const ::LinearAlgebra::Vector3<ScalarType> &translation )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix4x4<ScalarType>( rotation.v[0], rotation.v[1], rotation.v[2], ::LinearAlgebra::Vector4<ScalarType>(translation, 1) );
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ScalarType>
|
template<typename ScalarType>
|
||||||
::LinearAlgebra::Matrix4x4<ScalarType> & OrientationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &normalizedAxis, const ScalarType &deltaRadian, const ::LinearAlgebra::Vector3<ScalarType> &sumTranslation, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
|
::LinearAlgebra::Matrix4x4<ScalarType> & OrientationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &normalizedAxis, const ScalarType &deltaRadian, const ::LinearAlgebra::Vector3<ScalarType> &sumTranslation, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
|
||||||
{ /** @todo TODO: not tested */
|
{ /** @todo TODO: not tested */
|
||||||
|
@ -327,6 +386,23 @@ namespace LinearAlgebra3D
|
||||||
return targetMem;
|
return targetMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> OrientationMatrix_LookAtDirection( const ::LinearAlgebra::Vector3<ScalarType> &normalizedDirection, const ::LinearAlgebra::Vector3<ScalarType> &normalizedUpVector, const ::LinearAlgebra::Vector3<ScalarType> &worldPos )
|
||||||
|
{ // Righthanded system! Forward is considered to be along negative z axis. Up is considered along positive y axis.
|
||||||
|
::LinearAlgebra::Vector3<ScalarType> right = normalizedDirection.Cross( normalizedUpVector ).GetNormalized();
|
||||||
|
return ::LinearAlgebra::Matrix4x4<ScalarType>( ::LinearAlgebra::Vector4<ScalarType>( right, 0.0f ),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>( right.Cross( normalizedDirection ), 0.0f ),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>( -normalizedDirection, 0.0f ),
|
||||||
|
::LinearAlgebra::Vector4<ScalarType>( worldPos, 1.0f ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> OrientationMatrix_LookAtPos( const ::LinearAlgebra::Vector3<ScalarType> &worldLookAt, const ::LinearAlgebra::Vector3<ScalarType> &normalizedUpVector, const ::LinearAlgebra::Vector3<ScalarType> &worldPos )
|
||||||
|
{ // Righthanded system! Forward is considered to be along negative z axis. Up is considered along positive y axis.
|
||||||
|
::LinearAlgebra::Vector3<ScalarType> direction = ( worldLookAt - worldPos ).GetNormalized();
|
||||||
|
return OrientationMatrix_LookAtDirection( direction, normalizedUpVector, worldPos );
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ScalarType>
|
template<typename ScalarType>
|
||||||
inline ::LinearAlgebra::Matrix4x4<ScalarType> & InverseOrientationMatrix( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> & InverseOrientationMatrix( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
|
||||||
{
|
{
|
||||||
|
@ -349,6 +425,12 @@ namespace LinearAlgebra3D
|
||||||
return orientationMatrix;
|
return orientationMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Matrix4x4<ScalarType> ExtractRotationMatrix( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra::Matrix4x4<ScalarType>( orientationMatrix.v[0], orientationMatrix.v[1], orientationMatrix.v[2], ::LinearAlgebra::Vector4<ScalarType>::standard_unit_w );
|
||||||
|
}
|
||||||
|
|
||||||
/* Creates an orthographic projection matrix designed for DirectX enviroment.
|
/* Creates an orthographic projection matrix designed for DirectX enviroment.
|
||||||
width; of the projection sample volume.
|
width; of the projection sample volume.
|
||||||
height; of the projection sample volume.
|
height; of the projection sample volume.
|
||||||
|
@ -390,6 +472,10 @@ namespace LinearAlgebra3D
|
||||||
template<typename ScalarType>
|
template<typename ScalarType>
|
||||||
inline ::LinearAlgebra::Vector3<ScalarType> VectorProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &axis )
|
inline ::LinearAlgebra::Vector3<ScalarType> VectorProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &axis )
|
||||||
{ return axis * ( vector.Dot(axis) / axis.Dot(axis) ); }
|
{ return axis * ( vector.Dot(axis) / axis.Dot(axis) ); }
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
inline ::LinearAlgebra::Vector3<ScalarType> NormalProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &normalizedAxis )
|
||||||
|
{ return normalizedAxis * ( vector.Dot(normalizedAxis) ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
|
|
|
@ -33,17 +33,50 @@ namespace Oyster { namespace Math2D
|
||||||
Float3x3 & RotationMatrix( const Float &radian, Float3x3 &targetMem )
|
Float3x3 & RotationMatrix( const Float &radian, Float3x3 &targetMem )
|
||||||
{ return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); }
|
{ return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); }
|
||||||
|
|
||||||
|
Float2x2 & InverseRotationMatrix( const Float2x2 &rotation, Float2x2 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra2D::InverseRotationMatrix( rotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra2D::InverseRotationMatrix( rotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3x3 & OrientationMatrix( const Float2x2 &rotation, const Float2 &translation, Float3x3 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra2D::OrientationMatrix( rotation, translation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3x3 & OrientationMatrix( const Float3x3 &rotation, const Float2 &translation, Float3x3 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra2D::OrientationMatrix( rotation, translation );
|
||||||
|
}
|
||||||
|
|
||||||
Float3x3 & OrientationMatrix( const Float2 &position, const Float &radian, Float3x3 &targetMem )
|
Float3x3 & OrientationMatrix( const Float2 &position, const Float &radian, Float3x3 &targetMem )
|
||||||
{ return ::LinearAlgebra2D::OrientationMatrix( radian, position, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra2D::OrientationMatrix( radian, position, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float3x3 & OrientationMatrix( const Float2 &position, const Float2 &lookAt, Float3x3 &targetMem )
|
Float3x3 & OrientationMatrix( const Float2 &position, const Float2 &lookAt, Float3x3 &targetMem )
|
||||||
{ return ::LinearAlgebra2D::OrientationMatrix( lookAt, position, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra2D::OrientationMatrix( lookAt, position, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float3x3 & OrientationMatrix( const Float2 &position, Float radian, const Float2 &localCenterOfRotation, Float3x3 &targetMem )
|
Float3x3 & OrientationMatrix( const Float2 &position, Float radian, const Float2 &localCenterOfRotation, Float3x3 &targetMem )
|
||||||
{ return ::LinearAlgebra2D::OrientationMatrix( radian, position, localCenterOfRotation, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra2D::OrientationMatrix( radian, position, localCenterOfRotation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float3x3 & InverseOrientationMatrix( const Float3x3 &orientationMatrix, Float3x3 &targetMem )
|
Float3x3 & InverseOrientationMatrix( const Float3x3 &orientationMatrix, Float3x3 &targetMem )
|
||||||
{ return ::LinearAlgebra2D::InverseOrientationMatrix( orientationMatrix, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra2D::InverseOrientationMatrix( orientationMatrix, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3x3 & ExtractRotationMatrix( const Float3x3 &orientation, Float3x3 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra2D::ExtractRotationMatrix( orientation );
|
||||||
|
}
|
||||||
} }
|
} }
|
||||||
|
|
||||||
namespace Oyster { namespace Math3D
|
namespace Oyster { namespace Math3D
|
||||||
|
@ -63,29 +96,83 @@ namespace Oyster { namespace Math3D
|
||||||
Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem )
|
Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); }
|
{ return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); }
|
||||||
|
|
||||||
|
Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & InverseRotationMatrix( const Float4x4 &rotation, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & OrientationMatrix( const Float3x3 &rotation, const Float3 &translation, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::OrientationMatrix( rotation, translation );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & OrientationMatrix( const Float4x4 &rotation, const Float3 &translation, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::OrientationMatrix( rotation, translation );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & OrientationMatrix( const Float3 &normalizedAxis, const Float & deltaRadian, const Float3 &sumTranslation, Float4x4 &targetMem )
|
Float4x4 & OrientationMatrix( const Float3 &normalizedAxis, const Float & deltaRadian, const Float3 &sumTranslation, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::OrientationMatrix( normalizedAxis, deltaRadian, sumTranslation, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::OrientationMatrix( normalizedAxis, deltaRadian, sumTranslation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, Float4x4 &targetMem )
|
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::OrientationMatrix( sumDeltaAngularAxis, sumTranslation, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::OrientationMatrix( sumDeltaAngularAxis, sumTranslation, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 ¢erOfMass, Float4x4 &targetMem )
|
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 ¢erOfMass, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::OrientationMatrix( sumDeltaAngularAxis, sumTranslation, centerOfMass, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::OrientationMatrix( sumDeltaAngularAxis, sumTranslation, centerOfMass, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & OrientationMatrix_LookAtDirection( const Float3 &normalizedDirection, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::OrientationMatrix_LookAtDirection( normalizedDirection, normalizedUpVector, worldPos );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & OrientationMatrix_LookAtPos( const Float3 &worldLookAt, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::OrientationMatrix_LookAtPos( worldLookAt, normalizedUpVector, worldPos );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem )
|
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::InverseOrientationMatrix( orientationMatrix, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::InverseOrientationMatrix( orientationMatrix, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix )
|
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix )
|
||||||
{ return ::LinearAlgebra3D::UpdateOrientationMatrix( deltaPosition, deltaRotationMatrix, orientationMatrix ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::UpdateOrientationMatrix( deltaPosition, deltaRotationMatrix, orientationMatrix );
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4x4 & ExtractRotationMatrix( const Float4x4 &orientation, Float4x4 &targetMem )
|
||||||
|
{
|
||||||
|
return targetMem = ::LinearAlgebra3D::ExtractRotationMatrix( orientation );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & ProjectionMatrix_Orthographic( const Float &width, const Float &height, const Float &nearClip, const Float &farClip, Float4x4 &targetMem )
|
Float4x4 & ProjectionMatrix_Orthographic( const Float &width, const Float &height, const Float &nearClip, const Float &farClip, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::ProjectionMatrix_Orthographic( width, height, nearClip, farClip, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::ProjectionMatrix_Orthographic( width, height, nearClip, farClip, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & ProjectionMatrix_Perspective( const Float &verticalFoV, const Float &aspectRatio, const Float &nearClip, const Float &farClip, Float4x4 &targetMem )
|
Float4x4 & ProjectionMatrix_Perspective( const Float &verticalFoV, const Float &aspectRatio, const Float &nearClip, const Float &farClip, Float4x4 &targetMem )
|
||||||
{ return ::LinearAlgebra3D::ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, targetMem ); }
|
{
|
||||||
|
return ::LinearAlgebra3D::ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, targetMem );
|
||||||
|
}
|
||||||
|
|
||||||
Float3 VectorProjection( const Float3 &vector, const Float3 &axis )
|
Float3 VectorProjection( const Float3 &vector, const Float3 &axis )
|
||||||
{
|
{
|
||||||
return ::LinearAlgebra3D::VectorProjection( vector, axis );
|
return ::LinearAlgebra3D::VectorProjection( vector, axis );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Float3 NormalProjection( const Float3 &vector, const Float3 &normalizedAxis )
|
||||||
|
{
|
||||||
|
return ::LinearAlgebra3D::NormalProjection( vector, normalizedAxis );
|
||||||
|
}
|
||||||
} }
|
} }
|
|
@ -114,6 +114,18 @@ namespace Oyster { namespace Math2D /// Oyster's native math library specialized
|
||||||
/// Sets and returns targetMem as a counterclockwise rotationMatrix
|
/// Sets and returns targetMem as a counterclockwise rotationMatrix
|
||||||
Float3x3 & RotationMatrix( const Float &radian, Float3x3 &targetMem = Float3x3() );
|
Float3x3 & RotationMatrix( const Float &radian, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
/// If rotation is assumed to be by all definitions a rotation matrix. Then this is a much faster inverse method.
|
||||||
|
Float2x2 & InverseRotationMatrix( const Float2x2 &rotation, Float2x2 &targetMem = Float2x2() );
|
||||||
|
|
||||||
|
/// If rotation is assumed to be by all definitions a rotation matrix. Then this is a much faster inverse method.
|
||||||
|
Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
/// Sets and returns targetMem as an orientation Matrix composed by the rotation matrix and translation vector
|
||||||
|
Float3x3 & OrientationMatrix( const Float2x2 &rotation, const Float2 &translation, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
/// Sets and returns targetMem as an orientation Matrix composed by the rotation matrix and translation vector
|
||||||
|
Float3x3 & OrientationMatrix( const Float3x3 &rotation, const Float2 &translation, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
/// Sets and returns targetMem as an orientation Matrix with position as translation and radian rotation
|
/// Sets and returns targetMem as an orientation Matrix with position as translation and radian rotation
|
||||||
Float3x3 & OrientationMatrix( const Float2 &position, const Float &radian, Float3x3 &targetMem = Float3x3() );
|
Float3x3 & OrientationMatrix( const Float2 &position, const Float &radian, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
@ -126,6 +138,9 @@ namespace Oyster { namespace Math2D /// Oyster's native math library specialized
|
||||||
|
|
||||||
/// 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.
|
/// 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.
|
||||||
Float3x3 & InverseOrientationMatrix( const Float3x3 &orientationMatrix, Float3x3 &targetMem = Float3x3() );
|
Float3x3 & InverseOrientationMatrix( const Float3x3 &orientationMatrix, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
/// Returns targetmem after writing the rotation data from orientation, into it.
|
||||||
|
Float3x3 & ExtractRotationMatrix( const Float3x3 &orientation, Float3x3 &targetMem = Float3x3() );
|
||||||
} }
|
} }
|
||||||
|
|
||||||
namespace Oyster { namespace Math3D /// Oyster's native math library specialized for 3D
|
namespace Oyster { namespace Math3D /// Oyster's native math library specialized for 3D
|
||||||
|
@ -148,6 +163,18 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
|
||||||
/// Please make sure normalizedAxis is normalized.
|
/// Please make sure normalizedAxis is normalized.
|
||||||
Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem = Float4x4() );
|
Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
/// If rotation is assumed to be by all definitions a rotation matrix. Then this is a much faster inverse method.
|
||||||
|
Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem = Float3x3() );
|
||||||
|
|
||||||
|
/// If rotation is assumed to be by all definitions a rotation matrix. Then this is a much faster inverse method.
|
||||||
|
Float4x4 & InverseRotationMatrix( const Float4x4 &rotation, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
/// Sets and returns targetMem as an orientation Matrix composed by the rotation matrix and translation vector
|
||||||
|
Float4x4 & OrientationMatrix( const Float3x3 &rotation, const Float3 &translation, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
/// Sets and returns targetMem as an orientation Matrix composed by the rotation matrix and translation vector
|
||||||
|
Float4x4 & OrientationMatrix( const Float4x4 &rotation, const Float3 &translation, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
* Sets and returns targetMem as an orientation Matrix
|
* Sets and returns targetMem as an orientation Matrix
|
||||||
* @param normalizedAxis: The normalized vector parallell with the rotationAxis.
|
* @param normalizedAxis: The normalized vector parallell with the rotationAxis.
|
||||||
|
@ -180,6 +207,12 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
|
||||||
*******************************************************************/
|
*******************************************************************/
|
||||||
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 ¢erOfMass, Float4x4 &targetMem = Float4x4() );
|
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 ¢erOfMass, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
//! @todo TODO: Add documentation and not tested
|
||||||
|
Float4x4 & OrientationMatrix_LookAtDirection( const Float3 &normalizedDirection, const Float3 &normalizedUpVector, const Float3 &worldPos, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
//! @todo TODO: Add documentation and not tested
|
||||||
|
Float4x4 & OrientationMatrix_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.
|
/// 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() );
|
Float4x4 & InverseOrientationMatrix( const Float4x4 &orientationMatrix, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
@ -187,6 +220,9 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
|
||||||
// O1 = T1 * T0 * R1 * R0
|
// O1 = T1 * T0 * R1 * R0
|
||||||
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix );
|
Float4x4 & UpdateOrientationMatrix( const Float3 &deltaPosition, const Float4x4 &deltaRotationMatrix, Float4x4 &orientationMatrix );
|
||||||
|
|
||||||
|
/// Returns targetmem after writing the rotation data from orientation, into it.
|
||||||
|
Float4x4 & ExtractRotationMatrix( const Float4x4 &orientation, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
* Creates an orthographic projection matrix designed for DirectX enviroment.
|
* Creates an orthographic projection matrix designed for DirectX enviroment.
|
||||||
* @param width; of the projection sample volume.
|
* @param width; of the projection sample volume.
|
||||||
|
@ -214,14 +250,21 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
|
||||||
/// returns the component vector of vector that is parallell with axis
|
/// returns the component vector of vector that is parallell with axis
|
||||||
Float3 VectorProjection( const Float3 &vector, const Float3 &axis );
|
Float3 VectorProjection( const Float3 &vector, const Float3 &axis );
|
||||||
|
|
||||||
|
/// returns the component vector of vector that is parallell with axis. Faster than VectorProjection.
|
||||||
|
Float3 NormalProjection( const Float3 &vector, const Float3 &normalizedAxis );
|
||||||
|
|
||||||
/// Helper inline function that sets and then returns targetMem = projection * view
|
/// Helper inline function that sets and then returns targetMem = projection * view
|
||||||
inline Float4x4 & ViewProjectionMatrix( const Float4x4 &view, const Float4x4 &projection, Float4x4 &targetMem = Float4x4() )
|
inline Float4x4 & ViewProjectionMatrix( const Float4x4 &view, const Float4x4 &projection, Float4x4 &targetMem = Float4x4() )
|
||||||
{ return targetMem = projection * view; }
|
{ return targetMem = projection * view; }
|
||||||
|
|
||||||
/// Helper inline function that sets and then returns targetMem = transformer * transformee
|
/** Helper inline function that sets and then returns targetMem = transformer * transformee */
|
||||||
inline Float4x4 & TransformMatrix( const Float4x4 &transformer, const Float4x4 &transformee, Float4x4 &targetMem = Float4x4() )
|
inline Float4x4 & TransformMatrix( const Float4x4 &transformer, const Float4x4 &transformee, Float4x4 &targetMem )
|
||||||
{ return targetMem = transformer * transformee; }
|
{ 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
|
/// Helper inline function that sets and then returns targetMem = transformer * transformee
|
||||||
inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() )
|
inline Float4 & TransformVector( const Float4x4 &transformer, const Float4 &transformee, Float4 &targetMem = Float4() )
|
||||||
{ return targetMem = transformer * transformee; }
|
{ return targetMem = transformer * transformee; }
|
||||||
|
|
|
@ -8,19 +8,28 @@
|
||||||
using namespace ::Oyster::Collision3D;
|
using namespace ::Oyster::Collision3D;
|
||||||
using namespace ::Oyster::Math3D;
|
using namespace ::Oyster::Math3D;
|
||||||
|
|
||||||
Box::Box( ) : ICollideable(Type_box), orientation(Float4x4::identity), boundingOffset() {}
|
Box::Box( )
|
||||||
Box::Box( const Float4x4 &o, const Float3 &s ) : ICollideable(Type_box), orientation(o), boundingOffset(s*0.5) {}
|
: ICollideable(Type_box), rotation(Float4x4::identity), center(0.0f), boundingOffset(0.5f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Box::Box( const Float4x4 &r, const Float3 &p, const Float3 &s )
|
||||||
|
: ICollideable(Type_box), rotation(r), center(p), boundingOffset(s*0.5)
|
||||||
|
{}
|
||||||
|
|
||||||
Box::~Box( ) {}
|
Box::~Box( ) {}
|
||||||
|
|
||||||
Box & Box::operator = ( const Box &box )
|
Box & Box::operator = ( const Box &box )
|
||||||
{
|
{
|
||||||
this->orientation = box.orientation;
|
this->rotation = box.rotation;
|
||||||
|
this->center = box.center;
|
||||||
this->boundingOffset = box.boundingOffset;
|
this->boundingOffset = box.boundingOffset;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
::Utility::DynamicMemory::UniquePointer<ICollideable> Box::Clone( ) const
|
::Utility::DynamicMemory::UniquePointer<ICollideable> Box::Clone( ) const
|
||||||
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Box(*this) ); }
|
{
|
||||||
|
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Box(*this) );
|
||||||
|
}
|
||||||
|
|
||||||
bool Box::Intersects( const ICollideable *target ) const
|
bool Box::Intersects( const ICollideable *target ) const
|
||||||
{
|
{
|
||||||
|
@ -31,10 +40,10 @@ bool Box::Intersects( const ICollideable *target ) const
|
||||||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
||||||
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
||||||
case Type_plane: return Utility::Intersect( *this, *(Plane*)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( *this, *(BoxAxisAligned*)target );
|
case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)target );
|
||||||
case Type_box: return Utility::Intersect( *this, *(Box*)target );
|
case Type_box: return Utility::Intersect( *this, *(Box*)target );
|
||||||
case Type_frustrum: return false; // TODO: :
|
// case Type_frustrum: return false; // TODO: :
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,11 +53,11 @@ bool Box::Contains( const ICollideable *target ) const
|
||||||
switch( target->type )
|
switch( target->type )
|
||||||
{
|
{
|
||||||
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
||||||
case Type_sphere: return false; // TODO:
|
// case Type_sphere: return false; // TODO:
|
||||||
case Type_triangle: return false; // TODO:
|
// case Type_triangle: return false; // TODO:
|
||||||
case Type_box_axis_aligned: return false; // TODO:
|
// case Type_box_axis_aligned: return false; // TODO:
|
||||||
case Type_box: return false; // TODO:
|
// case Type_box: return false; // TODO:
|
||||||
case Type_frustrum: return false; // TODO:
|
// case Type_frustrum: return false; // TODO:
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,19 +16,18 @@ namespace Oyster { namespace Collision3D
|
||||||
public:
|
public:
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
struct{ ::Oyster::Math::Float4x4 orientation; ::Oyster::Math::Float3 boundingOffset; };
|
struct{ ::Oyster::Math::Float4x4 rotation; ::Oyster::Math::Float3 center, boundingOffset; };
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
::Oyster::Math::Float3 xAxis; ::Oyster::Math::Float paddingA;
|
::Oyster::Math::Float3 xAxis; ::Oyster::Math::Float paddingA;
|
||||||
::Oyster::Math::Float3 yAxis; ::Oyster::Math::Float paddingB;
|
::Oyster::Math::Float3 yAxis; ::Oyster::Math::Float paddingB;
|
||||||
::Oyster::Math::Float3 zAxis; ::Oyster::Math::Float paddingC;
|
::Oyster::Math::Float3 zAxis; ::Oyster::Math::Float paddingC;
|
||||||
::Oyster::Math::Float3 center;
|
|
||||||
};
|
};
|
||||||
char byte[sizeof(::Oyster::Math::Float4x4) + sizeof(::Oyster::Math::Float3)];
|
char byte[sizeof(::Oyster::Math::Float4x4) + 2*sizeof(::Oyster::Math::Float3)];
|
||||||
};
|
};
|
||||||
|
|
||||||
Box( );
|
Box( );
|
||||||
Box( const ::Oyster::Math::Float4x4 &orientation, const ::Oyster::Math::Float3 &size );
|
Box( const ::Oyster::Math::Float4x4 &rotation, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &size );
|
||||||
virtual ~Box( );
|
virtual ~Box( );
|
||||||
|
|
||||||
Box & operator = ( const Box &box );
|
Box & operator = ( const Box &box );
|
||||||
|
|
|
@ -33,10 +33,10 @@ bool BoxAxisAligned::Intersects( const ICollideable *target ) const
|
||||||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
||||||
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
||||||
case Type_plane: return Utility::Intersect( *this, *(Plane*)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( *this, *(BoxAxisAligned*)target );
|
case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)target );
|
||||||
case Type_box: return false; // TODO:
|
// case Type_box: return false; // TODO:
|
||||||
case Type_frustrum: return false; // TODO:
|
// case Type_frustrum: return false; // TODO:
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,12 @@ bool BoxAxisAligned::Contains( const ICollideable *target ) const
|
||||||
{
|
{
|
||||||
switch( target->type )
|
switch( target->type )
|
||||||
{
|
{
|
||||||
case Type_point: return false; // TODO:
|
// case Type_point: return false; // TODO:
|
||||||
case Type_sphere: return false; // TODO:
|
// case Type_sphere: return false; // TODO:
|
||||||
case Type_triangle: return false; // TODO:
|
// case Type_triangle: return false; // TODO:
|
||||||
case Type_box_axis_aligned: return false; // TODO:
|
// case Type_box_axis_aligned: return false; // TODO:
|
||||||
case Type_box: return false; // TODO:
|
// case Type_box: return false; // TODO:
|
||||||
case Type_frustrum: return false; // TODO:
|
// case Type_frustrum: return false; // TODO:
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -200,11 +200,11 @@ bool Frustrum::Intersects( const ICollideable *target ) const
|
||||||
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, ((Ray*)target)->collisionDistance );
|
||||||
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
case Type_sphere: return Utility::Intersect( *this, *(Sphere*)target );
|
||||||
case Type_plane: return Utility::Intersect( *this, *(Plane*)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( *this, *(BoxAxisAligned*)target );
|
case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)target );
|
||||||
case Type_box: return Utility::Intersect( *this, *(Box*)target );
|
case Type_box: return Utility::Intersect( *this, *(Box*)target );
|
||||||
case Type_frustrum: return Utility::Intersect( *this, *(Frustrum*)target );
|
case Type_frustrum: return Utility::Intersect( *this, *(Frustrum*)target );
|
||||||
case Type_line: return false; // TODO:
|
// case Type_line: return false; // TODO:
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,14 +214,14 @@ bool Frustrum::Contains( const ICollideable *target ) const
|
||||||
switch( target->type )
|
switch( target->type )
|
||||||
{
|
{
|
||||||
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
||||||
case Type_ray: return false; // TODO:
|
// case Type_ray: return false; // TODO:
|
||||||
case Type_sphere: return false; // TODO:
|
// case Type_sphere: return false; // TODO:
|
||||||
case Type_plane: return false; // TODO:
|
// case Type_plane: return false; // TODO:
|
||||||
case Type_triangle: return false; // TODO:
|
// case Type_triangle: return false; // TODO:
|
||||||
case Type_box_axis_aligned: return false; // TODO:
|
// case Type_box_axis_aligned: return false; // TODO:
|
||||||
case Type_box: return false; // TODO:
|
// case Type_box: return false; // TODO:
|
||||||
case Type_frustrum: return false; // TODO:
|
// case Type_frustrum: return false; // TODO:
|
||||||
case Type_line: return false; // TODO:
|
// case Type_line: return false; // TODO:
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ namespace Oyster { namespace Collision3D /// Contains a collection of 3D shapes
|
||||||
Type_ray,
|
Type_ray,
|
||||||
Type_sphere,
|
Type_sphere,
|
||||||
Type_plane,
|
Type_plane,
|
||||||
Type_triangle,
|
// Type_triangle,
|
||||||
Type_box_axis_aligned,
|
Type_box_axis_aligned,
|
||||||
Type_box,
|
Type_box,
|
||||||
Type_frustrum,
|
Type_frustrum,
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
using namespace Oyster::Math3D;
|
using namespace ::Oyster::Math3D;
|
||||||
|
using namespace ::Utility::Value;
|
||||||
|
|
||||||
namespace Oyster { namespace Collision3D { namespace Utility
|
namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
{
|
{
|
||||||
|
@ -19,13 +20,13 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
// Float calculations can suffer roundingerrors. Which is where epsilon = 1e-20 comes into the picture
|
// Float calculations can suffer roundingerrors. Which is where epsilon = 1e-20 comes into the picture
|
||||||
inline bool EqualsZero( const Float &value )
|
inline bool EqualsZero( const Float &value )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return ::Utility::Value::Abs( value ) < epsilon;
|
return Abs( value ) < epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Float calculations can suffer roundingerrors. Which is where epsilon = 1e-20 comes into the picture
|
// Float calculations can suffer roundingerrors. Which is where epsilon = 1e-20 comes into the picture
|
||||||
inline bool NotEqualsZero( const Float &value )
|
inline bool NotEqualsZero( const Float &value )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return ::Utility::Value::Abs( value ) > epsilon;
|
return Abs( value ) > epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if miss/reject
|
// returns true if miss/reject
|
||||||
|
@ -39,8 +40,8 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
t2 = e - boundingOffset;
|
t2 = e - boundingOffset;
|
||||||
t1 /= f; t2 /= f;
|
t1 /= f; t2 /= f;
|
||||||
if( t1 > t2 ) ::Utility::Element::Swap( t1, t2 );
|
if( t1 > t2 ) ::Utility::Element::Swap( t1, t2 );
|
||||||
tMin = ::Utility::Value::Max( tMin, t1 );
|
tMin = Max( tMin, t1 );
|
||||||
tMax = ::Utility::Value::Min( tMax, t2 );
|
tMax = Min( tMax, t2 );
|
||||||
if( tMin > tMax ) return true;
|
if( tMin > tMax ) return true;
|
||||||
if( tMax < 0.0f ) return true;
|
if( tMax < 0.0f ) return true;
|
||||||
}
|
}
|
||||||
|
@ -65,101 +66,140 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float3 c = (box.maxVertex + box.minVertex) * 0.5f, // box.Center
|
Float3 c = (box.maxVertex + box.minVertex) * 0.5f, // box.Center
|
||||||
h = (box.maxVertex - box.minVertex) * 0.5f; // box.halfSize
|
h = (box.maxVertex - box.minVertex) * 0.5f; // box.halfSize
|
||||||
boxExtend = h.x * ::Utility::Value::Abs(plane.normal.x); // Box max extending towards plane
|
boxExtend = h.x * Abs(plane.normal.x); // Box max extending towards plane
|
||||||
boxExtend += h.y * ::Utility::Value::Abs(plane.normal.y);
|
boxExtend += h.y * Abs(plane.normal.y);
|
||||||
boxExtend += h.z * ::Utility::Value::Abs(plane.normal.z);
|
boxExtend += h.z * Abs(plane.normal.z);
|
||||||
centerDistance = c.Dot(plane.normal) + plane.phasing; // distance between box center and plane
|
centerDistance = c.Dot(plane.normal) + plane.phasing; // distance between box center and plane
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compare( Float &boxExtend, Float ¢erDistance, const Plane &plane, const Box &box )
|
void Compare( Float &boxExtend, Float ¢erDistance, const Plane &plane, const Box &box )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
boxExtend = box.boundingOffset.x * ::Utility::Value::Abs(plane.normal.Dot(box.orientation.v[0].xyz)); // Box max extending towards plane
|
boxExtend = box.boundingOffset.x * Abs(plane.normal.Dot(box.xAxis)); // Box max extending towards plane
|
||||||
boxExtend += box.boundingOffset.y * ::Utility::Value::Abs(plane.normal.Dot(box.orientation.v[1].xyz));
|
boxExtend += box.boundingOffset.y * Abs(plane.normal.Dot(box.yAxis));
|
||||||
boxExtend += box.boundingOffset.z * ::Utility::Value::Abs(plane.normal.Dot(box.orientation.v[2].xyz));
|
boxExtend += box.boundingOffset.z * Abs(plane.normal.Dot(box.zAxis));
|
||||||
|
|
||||||
centerDistance = box.orientation.v[3].xyz.Dot(plane.normal) + plane.phasing; // distance between box center and plane
|
centerDistance = box.center.Dot(plane.normal) + plane.phasing; // distance between box center and plane
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FifteenAxisVsAlignedAxisOverlappingChecks( const Float3 &boundingOffsetA, const Float3 &boundingOffsetB, const Float4x4 &orientationB )
|
bool SeperatingAxisTest_AxisAlignedVsTransformedBox( const Float3 &boundingOffsetA, const Float3 &boundingOffsetB, const Float4x4 &rotationB, const Float3 &worldOffset )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float4x4 absOrientationB;
|
|
||||||
{
|
/*****************************************************************
|
||||||
Float4x4 tO = orientationB.GetTranspose();
|
* Uses the Seperating Axis Theorem
|
||||||
absOrientationB.v[0] = ::Utility::Value::Abs(tO.v[0]);
|
* if( |t dot s| > hA dot |s * RA| + hB dot |s * RB| ) then not intersecting
|
||||||
if( absOrientationB.v[0].w > boundingOffsetA.x + boundingOffsetB.Dot(absOrientationB.v[0].xyz) ) return false;
|
* |t dot s| > hA dot |s| + hB dot |s * RB| .. as RA = I
|
||||||
absOrientationB.v[1] = ::Utility::Value::Abs(tO.v[1]);
|
*
|
||||||
if( absOrientationB.v[1].w > boundingOffsetA.y + boundingOffsetB.Dot(absOrientationB.v[1].xyz) ) return false;
|
* t: objectB's offset from objectA [worldOffset]
|
||||||
absOrientationB.v[2] = ::Utility::Value::Abs(tO.v[2]);
|
* s: current comparison axis
|
||||||
if( absOrientationB.v[2].w > boundingOffsetA.z + boundingOffsetB.Dot(absOrientationB.v[2].xyz) ) return false;
|
* hA: boundingReach vector of objectA. Only absolute values is assumed. [boundingOffsetA]
|
||||||
|
* hB: boundingReach vector of objectB. Only absolute values is assumed. [boundingOffsetB]
|
||||||
|
* RA: rotation matrix of objectA. Is identity matrix here, thus omitted.
|
||||||
|
* RB: rotation matrix of objectB. Is transformed into objectA's view at this point. [rotationB]
|
||||||
|
*
|
||||||
|
* Note: s * RB = (RB^T * s)^T = (RB^-1 * s)^T .... vector == vector^T
|
||||||
|
*****************************************************************/
|
||||||
|
|
||||||
|
Float4x4 absRotationB = Abs(rotationB);
|
||||||
|
Float3 absWorldOffset = Abs(worldOffset); // |t|: [absWorldOffset]
|
||||||
|
|
||||||
|
// s = { 1, 0, 0 } [ RA.v[0] ]
|
||||||
|
if( absWorldOffset.x > boundingOffsetA.x + boundingOffsetB.Dot(Float3(absRotationB.v[0].x, absRotationB.v[1].x, absRotationB.v[2].x)) )
|
||||||
|
{ // |t dot s| > hA dot |s| + hB dot |s * RB| -->> t.x > hA.x + hB dot |{RB.v[0].x, RB.v[1].x, RB.v[2].x}|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
absOrientationB.Transpose();
|
// s = { 0, 1, 0 } [ RA.v[1] ]
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].Dot(orientationB.v[0])) > boundingOffsetB.x + boundingOffsetA.Dot(absOrientationB.v[0].xyz) ) return false;
|
if( absWorldOffset.y > boundingOffsetA.y + boundingOffsetB.Dot(Float3(absRotationB.v[0].y, absRotationB.v[1].y, absRotationB.v[2].y)) )
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].Dot(orientationB.v[1])) > boundingOffsetB.x + boundingOffsetA.Dot(absOrientationB.v[1].xyz) ) return false;
|
{ // t.y > hA.y + hB dot |{RB.v[0].y, RB.v[1].y, RB.v[2].y}|
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].Dot(orientationB.v[2])) > boundingOffsetB.x + boundingOffsetA.Dot(absOrientationB.v[2].xyz) ) return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ( 1,0,0 ) x orientationB.v[0].xyz:
|
// s = { 0, 0, 1 } [ RA.v[2] ]
|
||||||
Float d = boundingOffsetA.y * absOrientationB.v[0].z;
|
if( absWorldOffset.z > boundingOffsetA.z + boundingOffsetB.Dot(Float3(absRotationB.v[0].z, absRotationB.v[1].z, absRotationB.v[2].z)) )
|
||||||
d += boundingOffsetA.z * absOrientationB.v[0].y;
|
{ // t.z > hA.z + hB dot |{RB.v[0].z, RB.v[1].z, RB.v[2].z}|
|
||||||
d += boundingOffsetB.y * absOrientationB.v[2].x;
|
return false;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[1].x;
|
}
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].z*orientationB.v[0].y - orientationB.v[3].y*orientationB.v[0].z) > d ) return false;
|
|
||||||
|
|
||||||
// ( 1,0,0 ) x orientationB.v[1].xyz:
|
// s = RB.v[0].xyz
|
||||||
d = boundingOffsetA.y * absOrientationB.v[1].z;
|
if( Abs(worldOffset.Dot(rotationB.v[0].xyz)) > boundingOffsetA.Dot(absRotationB.v[0].xyz) + boundingOffsetB.x )
|
||||||
d += boundingOffsetA.z * absOrientationB.v[1].y;
|
{ // |t dot s| > hA dot |s| + hB dot |s * RB| -->> |t dot s| > hA dot |s| + hB dot |{1, 0, 0}| -->> |t dot s| > hA dot |s| + hB.x
|
||||||
d += boundingOffsetB.x * absOrientationB.v[2].x;
|
return false;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[0].x;
|
}
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].z*orientationB.v[1].y - orientationB.v[3].y*orientationB.v[1].z) > d ) return false;
|
|
||||||
|
|
||||||
// ( 1,0,0 ) x orientationB.v[2].xyz:
|
// s = RB.v[1].xyz
|
||||||
d = boundingOffsetA.y * absOrientationB.v[2].z;
|
if( Abs(worldOffset.Dot(rotationB.v[1].xyz)) > boundingOffsetA.Dot(absRotationB.v[1].xyz) + boundingOffsetB.y )
|
||||||
d += boundingOffsetA.z * absOrientationB.v[2].y;
|
{ // |t dot s| > hA dot |s| + hB.y
|
||||||
d += boundingOffsetB.x * absOrientationB.v[1].x;
|
return false;
|
||||||
d += boundingOffsetB.y * absOrientationB.v[0].x;
|
}
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].z*orientationB.v[2].y - orientationB.v[3].y*orientationB.v[2].z) > d ) return false;
|
|
||||||
|
|
||||||
// ( 0,1,0 ) x orientationB.v[0].xyz:
|
// s = RB.v[2].xyz
|
||||||
d = boundingOffsetA.x * absOrientationB.v[0].z;
|
if( Abs(worldOffset.Dot(rotationB.v[2].xyz)) > boundingOffsetA.Dot(absRotationB.v[2].xyz) + boundingOffsetB.z )
|
||||||
d += boundingOffsetA.z * absOrientationB.v[0].x;
|
{ // |t dot s| > hA dot |s| + hB.z
|
||||||
d += boundingOffsetB.y * absOrientationB.v[2].y;
|
return false;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[1].y;
|
}
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].x*orientationB.v[0].z - orientationB.v[3].z*orientationB.v[0].x) > d ) return false;
|
|
||||||
|
|
||||||
// ( 0,1,0 ) x orientationB.v[1].xyz:
|
// s = ( 1,0,0 ) x rotationB.v[0].xyz:
|
||||||
d = boundingOffsetA.x * absOrientationB.v[1].z;
|
Float d = boundingOffsetA.y * absRotationB.v[0].z;
|
||||||
d += boundingOffsetA.z * absOrientationB.v[1].x;
|
d += boundingOffsetA.z * absRotationB.v[0].y;
|
||||||
d += boundingOffsetB.x * absOrientationB.v[2].y;
|
d += boundingOffsetB.y * absRotationB.v[2].x;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[0].y;
|
d += boundingOffsetB.z * absRotationB.v[1].x;
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].x*orientationB.v[1].z - orientationB.v[3].z*orientationB.v[1].x) > d ) return false;
|
if( Abs(worldOffset.z*rotationB.v[0].y - worldOffset.y*rotationB.v[0].z) > d ) return false;
|
||||||
|
|
||||||
// ( 0,1,0 ) x orientationB.v[2].xyz:
|
// s = ( 1,0,0 ) x rotationB.v[1].xyz:
|
||||||
d = boundingOffsetA.x * absOrientationB.v[2].z;
|
d = boundingOffsetA.y * absRotationB.v[1].z;
|
||||||
d += boundingOffsetA.z * absOrientationB.v[2].x;
|
d += boundingOffsetA.z * absRotationB.v[1].y;
|
||||||
d += boundingOffsetB.x * absOrientationB.v[1].y;
|
d += boundingOffsetB.x * absRotationB.v[2].x;
|
||||||
d += boundingOffsetB.y * absOrientationB.v[0].y;
|
d += boundingOffsetB.z * absRotationB.v[0].x;
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].x*orientationB.v[2].z - orientationB.v[3].z*orientationB.v[2].x) > d ) return false;
|
if( Abs(worldOffset.z*rotationB.v[1].y - worldOffset.y*rotationB.v[1].z) > d ) return false;
|
||||||
|
|
||||||
// ( 0,0,1 ) x orientationB.v[0].xyz:
|
// s = ( 1,0,0 ) x rotationB.v[2].xyz:
|
||||||
d = boundingOffsetA.x * absOrientationB.v[0].y;
|
d = boundingOffsetA.y * absRotationB.v[2].z;
|
||||||
d += boundingOffsetA.y * absOrientationB.v[0].x;
|
d += boundingOffsetA.z * absRotationB.v[2].y;
|
||||||
d += boundingOffsetB.y * absOrientationB.v[2].z;
|
d += boundingOffsetB.x * absRotationB.v[1].x;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[1].z;
|
d += boundingOffsetB.y * absRotationB.v[0].x;
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].y*orientationB.v[0].x - orientationB.v[3].x*orientationB.v[0].y) > d ) return false;
|
if( Abs(worldOffset.z*rotationB.v[2].y - worldOffset.y*rotationB.v[2].z) > d ) return false;
|
||||||
|
|
||||||
// ( 0,0,1 ) x orientationB.v[1].xyz:
|
// s = ( 0,1,0 ) x rotationB.v[0].xyz:
|
||||||
d = boundingOffsetA.x * absOrientationB.v[1].y;
|
d = boundingOffsetA.x * absRotationB.v[0].z;
|
||||||
d += boundingOffsetA.y * absOrientationB.v[1].x;
|
d += boundingOffsetA.z * absRotationB.v[0].x;
|
||||||
d += boundingOffsetB.x * absOrientationB.v[2].z;
|
d += boundingOffsetB.y * absRotationB.v[2].y;
|
||||||
d += boundingOffsetB.z * absOrientationB.v[0].z;
|
d += boundingOffsetB.z * absRotationB.v[1].y;
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].y*orientationB.v[1].x - orientationB.v[3].x*orientationB.v[1].y) > d ) return false;
|
if( Abs(worldOffset.x*rotationB.v[0].z - worldOffset.z*rotationB.v[0].x) > d ) return false;
|
||||||
|
|
||||||
// ( 0,0,1 ) x orientationB.v[2].xyz:
|
// s = ( 0,1,0 ) x rotationB.v[1].xyz:
|
||||||
d = boundingOffsetA.x * absOrientationB.v[2].y;
|
d = boundingOffsetA.x * absRotationB.v[1].z;
|
||||||
d += boundingOffsetA.y * absOrientationB.v[2].x;
|
d += boundingOffsetA.z * absRotationB.v[1].x;
|
||||||
d += boundingOffsetB.x * absOrientationB.v[1].z;
|
d += boundingOffsetB.x * absRotationB.v[2].y;
|
||||||
d += boundingOffsetB.y * absOrientationB.v[0].z;
|
d += boundingOffsetB.z * absRotationB.v[0].y;
|
||||||
if( ::Utility::Value::Abs(orientationB.v[3].y*orientationB.v[2].x - orientationB.v[3].x*orientationB.v[2].y) > d ) return false;
|
if( Abs(worldOffset.x*rotationB.v[1].z - worldOffset.z*rotationB.v[1].x) > d ) return false;
|
||||||
|
|
||||||
|
// s = ( 0,1,0 ) x rotationB.v[2].xyz:
|
||||||
|
d = boundingOffsetA.x * absRotationB.v[2].z;
|
||||||
|
d += boundingOffsetA.z * absRotationB.v[2].x;
|
||||||
|
d += boundingOffsetB.x * absRotationB.v[1].y;
|
||||||
|
d += boundingOffsetB.y * absRotationB.v[0].y;
|
||||||
|
if( Abs(worldOffset.x*rotationB.v[2].z - worldOffset.z*rotationB.v[2].x) > d ) return false;
|
||||||
|
|
||||||
|
// s = ( 0,0,1 ) x rotationB.v[0].xyz:
|
||||||
|
d = boundingOffsetA.x * absRotationB.v[0].y;
|
||||||
|
d += boundingOffsetA.y * absRotationB.v[0].x;
|
||||||
|
d += boundingOffsetB.y * absRotationB.v[2].z;
|
||||||
|
d += boundingOffsetB.z * absRotationB.v[1].z;
|
||||||
|
if( Abs(worldOffset.y*rotationB.v[0].x - worldOffset.x*rotationB.v[0].y) > d ) return false;
|
||||||
|
|
||||||
|
// s = ( 0,0,1 ) x rotationB.v[1].xyz:
|
||||||
|
d = boundingOffsetA.x * absRotationB.v[1].y;
|
||||||
|
d += boundingOffsetA.y * absRotationB.v[1].x;
|
||||||
|
d += boundingOffsetB.x * absRotationB.v[2].z;
|
||||||
|
d += boundingOffsetB.z * absRotationB.v[0].z;
|
||||||
|
if( Abs(worldOffset.y*rotationB.v[1].x - worldOffset.x*rotationB.v[1].y) > d ) return false;
|
||||||
|
|
||||||
|
// s = ( 0,0,1 ) x rotationB.v[2].xyz:
|
||||||
|
d = boundingOffsetA.x * absRotationB.v[2].y;
|
||||||
|
d += boundingOffsetA.y * absRotationB.v[2].x;
|
||||||
|
d += boundingOffsetB.x * absRotationB.v[1].z;
|
||||||
|
d += boundingOffsetB.y * absRotationB.v[0].z;
|
||||||
|
if( Abs(worldOffset.y*rotationB.v[2].x - worldOffset.x*rotationB.v[2].y) > d ) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -353,8 +393,8 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
|
|
||||||
bool Intersect( const BoxAxisAligned &box, const Sphere &sphere )
|
bool Intersect( const BoxAxisAligned &box, const Sphere &sphere )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float3 e = ::Utility::Value::Max( box.minVertex - sphere.center, Float3::null );
|
Float3 e = Max( box.minVertex - sphere.center, Float3::null );
|
||||||
e += ::Utility::Value::Max( sphere.center - box.maxVertex, Float3::null );
|
e += Max( sphere.center - box.maxVertex, Float3::null );
|
||||||
|
|
||||||
if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false;
|
if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -385,17 +425,17 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
|
|
||||||
bool Intersect( const Box &box, const Point &point )
|
bool Intersect( const Box &box, const Point &point )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float3 dPos = point.center - box.orientation.v[3].xyz;
|
Float3 dPos = point.center - box.center;
|
||||||
|
|
||||||
Float coordinate = dPos.Dot( box.orientation.v[0].xyz );
|
Float coordinate = dPos.Dot( box.xAxis );
|
||||||
if( coordinate > box.boundingOffset.x ) return false;
|
if( coordinate > box.boundingOffset.x ) return false;
|
||||||
if( coordinate < -box.boundingOffset.x ) return false;
|
if( coordinate < -box.boundingOffset.x ) return false;
|
||||||
|
|
||||||
coordinate = dPos.Dot( box.orientation.v[1].xyz );
|
coordinate = dPos.Dot( box.yAxis );
|
||||||
if( coordinate > box.boundingOffset.y ) return false;
|
if( coordinate > box.boundingOffset.y ) return false;
|
||||||
if( coordinate < -box.boundingOffset.y ) return false;
|
if( coordinate < -box.boundingOffset.y ) return false;
|
||||||
|
|
||||||
coordinate = dPos.Dot( box.orientation.v[2].xyz );
|
coordinate = dPos.Dot( box.zAxis );
|
||||||
if( coordinate > box.boundingOffset.z ) return false;
|
if( coordinate > box.boundingOffset.z ) return false;
|
||||||
if( coordinate < -box.boundingOffset.z ) return false;
|
if( coordinate < -box.boundingOffset.z ) return false;
|
||||||
|
|
||||||
|
@ -419,11 +459,11 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
|
|
||||||
bool Intersect( const Box &box, const Sphere &sphere )
|
bool Intersect( const Box &box, const Sphere &sphere )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float3 e = sphere.center - box.orientation.v[3].xyz,
|
Float3 e = sphere.center - box.center,
|
||||||
centerL = Float3( e.Dot(box.orientation.v[0].xyz), e.Dot(box.orientation.v[1].xyz), e.Dot(box.orientation.v[2].xyz) );
|
centerL = Float3( e.Dot(box.xAxis), e.Dot(box.yAxis), e.Dot(box.zAxis) );
|
||||||
|
|
||||||
e = ::Utility::Value::Max( (box.boundingOffset + centerL)*=-1.0f, Float3::null );
|
e = Max( (box.boundingOffset + centerL)*=-1.0f, Float3::null );
|
||||||
e += ::Utility::Value::Max( centerL - box.boundingOffset, Float3::null );
|
e += Max( centerL - box.boundingOffset, Float3::null );
|
||||||
|
|
||||||
if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false;
|
if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -440,20 +480,20 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
|
|
||||||
bool Intersect( const Box &boxA, const BoxAxisAligned &boxB )
|
bool Intersect( const Box &boxA, const BoxAxisAligned &boxB )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float3 alignedOffsetBoundaries = boxB.maxVertex - boxB.minVertex;
|
Float3 alignedOffsetBoundaries = (boxB.maxVertex - boxB.minVertex) * 0.5f,
|
||||||
Float4x4 translated = boxA.orientation;
|
offset = boxA.center - Average( boxB.minVertex, boxB.maxVertex );
|
||||||
translated.v[3].xyz -= boxB.minVertex;
|
return Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries, boxA.boundingOffset, boxA.rotation, offset );
|
||||||
translated.v[3].xyz += alignedOffsetBoundaries * 0.5f;
|
|
||||||
alignedOffsetBoundaries = ::Utility::Value::Abs(alignedOffsetBoundaries);
|
|
||||||
return Private::FifteenAxisVsAlignedAxisOverlappingChecks( alignedOffsetBoundaries, boxA.boundingOffset, translated );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Intersect( const Box &boxA, const Box &boxB )
|
bool Intersect( const Box &boxA, const Box &boxB )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float4x4 M;
|
Float4x4 orientationA = OrientationMatrix(boxA.rotation, boxA.center),
|
||||||
InverseOrientationMatrix( boxA.orientation, M );
|
orientationB = OrientationMatrix(boxB.rotation, boxB.center),
|
||||||
TransformMatrix( M, boxB.orientation, M ); /// TODO: not verified
|
invOrientationA = InverseOrientationMatrix( orientationA );
|
||||||
return Private::FifteenAxisVsAlignedAxisOverlappingChecks( boxA.boundingOffset, boxB.boundingOffset, M );
|
|
||||||
|
orientationB = TransformMatrix( invOrientationA, orientationB );
|
||||||
|
|
||||||
|
return Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, ExtractRotationMatrix(orientationB), orientationB.v[3].xyz );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Intersect( const Frustrum &frustrum, const Point &point )
|
bool Intersect( const Frustrum &frustrum, const Point &point )
|
||||||
|
@ -490,37 +530,37 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
if( Intersect(frustrum.leftPlane, ray, distance) )
|
if( Intersect(frustrum.leftPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Intersect(frustrum.rightPlane, ray, distance) )
|
if( Intersect(frustrum.rightPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Intersect(frustrum.bottomPlane, ray, distance) )
|
if( Intersect(frustrum.bottomPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Intersect(frustrum.topPlane, ray, distance) )
|
if( Intersect(frustrum.topPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Intersect(frustrum.nearPlane, ray, distance) )
|
if( Intersect(frustrum.nearPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Intersect(frustrum.farPlane, ray, distance) )
|
if( Intersect(frustrum.farPlane, ray, distance) )
|
||||||
{
|
{
|
||||||
intersected = true;
|
intersected = true;
|
||||||
connectDistance = ::Utility::Value::Min( connectDistance, distance );
|
connectDistance = Min( connectDistance, distance );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( intersected ) return true;
|
if( intersected ) return true;
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace Oyster { namespace Physics3D
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local angular momentum of a mass in rotation.
|
* Returns the world angular momentum of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 AngularMomentum( const ::Oyster::Math::Float4x4 &momentOfInertia, const ::Oyster::Math::Float3 &angularVelocity )
|
inline ::Oyster::Math::Float3 AngularMomentum( const ::Oyster::Math::Float4x4 &momentOfInertia, const ::Oyster::Math::Float3 &angularVelocity )
|
||||||
|
@ -58,39 +58,39 @@ namespace Oyster { namespace Physics3D
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local angular momentum of a mass in rotation.
|
* Returns the world angular momentum of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 AngularMomentum( const ::Oyster::Math::Float3 linearMomentum, const ::Oyster::Math::Float3 &offset )
|
inline ::Oyster::Math::Float3 AngularMomentum( const ::Oyster::Math::Float3 linearMomentum, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return offset.Cross( linearMomentum );
|
return worldOffset.Cross( linearMomentum );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local tangential momentum at localPos, of a mass in rotation.
|
* Returns the world tangential momentum at worldPos, of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &localOffset )
|
inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return angularMomentum.Cross( localOffset );
|
return angularMomentum.Cross( worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local tangential momentum at localPos, of a mass in rotation.
|
* Returns the world tangential momentum at worldPos, of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float4x4 &momentOfInertia, const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &localOffset )
|
inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float4x4 &momentOfInertia, const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return TangentialLinearMomentum( AngularMomentum(momentOfInertia, angularVelocity), localOffset );
|
return TangentialLinearMomentum( AngularMomentum(momentOfInertia, angularVelocity), worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local impulse force at localPos, of a mass in angular acceleration.
|
* Returns the world impulse force at worldPos, of a mass in angular acceleration.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialImpulseForce( const ::Oyster::Math::Float3 &impulseTorque, const ::Oyster::Math::Float3 &localOffset )
|
inline ::Oyster::Math::Float3 TangentialImpulseForce( const ::Oyster::Math::Float3 &impulseTorque, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return impulseTorque.Cross( localOffset );
|
return impulseTorque.Cross( worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
|
@ -106,22 +106,22 @@ namespace Oyster { namespace Physics3D
|
||||||
*
|
*
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 AngularImpulseAcceleration( const ::Oyster::Math::Float3 &linearImpulseAcceleration, const ::Oyster::Math::Float3 &offset )
|
inline ::Oyster::Math::Float3 AngularImpulseAcceleration( const ::Oyster::Math::Float3 &linearImpulseAcceleration, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return offset.Cross( linearImpulseAcceleration );
|
return worldOffset.Cross( linearImpulseAcceleration );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local impulse acceleration at localPos, of a mass in angular acceleration.
|
* Returns the world impulse acceleration at ( worldOffset = worldPos - body's center of gravity ), of a mass in angular acceleration.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialImpulseAcceleration( const ::Oyster::Math::Float4x4 &momentOfInertiaInversed, const ::Oyster::Math::Float3 &impulseTorque, const ::Oyster::Math::Float3 &localOffset )
|
inline ::Oyster::Math::Float3 TangentialImpulseAcceleration( const ::Oyster::Math::Float4x4 &worldMomentOfInertiaInversed, const ::Oyster::Math::Float3 &worldImpulseTorque, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return AngularImpulseAcceleration( momentOfInertiaInversed, impulseTorque ).Cross( localOffset );
|
return AngularImpulseAcceleration( worldMomentOfInertiaInversed, worldImpulseTorque ).Cross( worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local angular velocity of a mass in rotation.
|
* Returns the world angular velocity of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 AngularVelocity( const ::Oyster::Math::Float4x4 &momentOfInertiaInversed, const ::Oyster::Math::Float3 &angularMomentum )
|
inline ::Oyster::Math::Float3 AngularVelocity( const ::Oyster::Math::Float4x4 &momentOfInertiaInversed, const ::Oyster::Math::Float3 &angularMomentum )
|
||||||
|
@ -130,21 +130,30 @@ namespace Oyster { namespace Physics3D
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local tangential velocity at localPos, of a mass in rotation.
|
* Returns the world angular velocity of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialLinearVelocity( const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &offset )
|
inline ::Oyster::Math::Float3 AngularVelocity( const ::Oyster::Math::Float3 &linearVelocity, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return angularVelocity.Cross( offset );
|
return worldOffset.Cross( linearVelocity );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Returns the local tangential velocity at localPos, of a mass in rotation.
|
* Returns the world tangential velocity at worldPos, of a mass in rotation.
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 TangentialLinearVelocity( const ::Oyster::Math::Float4x4 &momentOfInertiaInversed, const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &offset )
|
inline ::Oyster::Math::Float3 TangentialLinearVelocity( const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return TangentialLinearVelocity( AngularVelocity(momentOfInertiaInversed, angularMomentum), offset );
|
return angularVelocity.Cross( worldOffset );
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* Returns the world tangential velocity at worldPos, of a mass in rotation.
|
||||||
|
* @todo TODO: improve doc
|
||||||
|
******************************************************************/
|
||||||
|
inline ::Oyster::Math::Float3 TangentialLinearVelocity( const ::Oyster::Math::Float4x4 &momentOfInertiaInversed, const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
|
{
|
||||||
|
return TangentialLinearVelocity( AngularVelocity(momentOfInertiaInversed, angularMomentum), worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
|
@ -169,9 +178,9 @@ namespace Oyster { namespace Physics3D
|
||||||
*
|
*
|
||||||
* @todo TODO: improve doc
|
* @todo TODO: improve doc
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
inline ::Oyster::Math::Float3 ImpulseTorque( const ::Oyster::Math::Float3 & impulseForce, const ::Oyster::Math::Float3 &offset )
|
inline ::Oyster::Math::Float3 ImpulseTorque( const ::Oyster::Math::Float3 & impulseForce, const ::Oyster::Math::Float3 &worldOffset )
|
||||||
{
|
{
|
||||||
return offset.Cross( impulseForce );
|
return worldOffset.Cross( impulseForce );
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
|
@ -183,6 +192,12 @@ namespace Oyster { namespace Physics3D
|
||||||
return ( momentOfInertia * ::Oyster::Math::Float4(angularImpulseAcceleration, 0.0f) ).xyz;
|
return ( momentOfInertia * ::Oyster::Math::Float4(angularImpulseAcceleration, 0.0f) ).xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ::Oyster::Math::Float3 Impulse( )
|
||||||
|
{
|
||||||
|
//! @todo TODO: implement calculation for impulse. Hijack Mattias Eriksson
|
||||||
|
return ::Oyster::Math::Float3::null;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MomentOfInertia
|
namespace MomentOfInertia
|
||||||
{ /// Library of Formulas to calculate moment of inerta for simple shapes
|
{ /// Library of Formulas to calculate moment of inerta for simple shapes
|
||||||
/** @todo TODO: add MomentOfInertia tensor formulas */
|
/** @todo TODO: add MomentOfInertia tensor formulas */
|
||||||
|
|
|
@ -39,20 +39,21 @@ RigidBody & RigidBody::operator = ( const RigidBody &body )
|
||||||
void RigidBody::Update_LeapFrog( Float deltaTime )
|
void RigidBody::Update_LeapFrog( Float deltaTime )
|
||||||
{ // by Dan Andersson: Euler leap frog update when Runga Kutta is not needed
|
{ // 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.rotation, this->momentOfInertiaTensor ); // RI
|
||||||
|
|
||||||
// updating the linear
|
// updating the linear
|
||||||
// dv = dt * a = dt * F / m
|
// dG = F * dt
|
||||||
// ds = dt * avg_v
|
// ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G
|
||||||
Float3 deltaLinearVelocity = this->impulseForceSum;
|
Float3 linearImpulse = this->impulseForceSum * deltaTime; // aka deltaLinearMomentum
|
||||||
deltaLinearVelocity *= (deltaTime / this->mass);
|
Float3 deltaPos = ( deltaTime / this->mass ) * ::Utility::Value::AverageWithDelta( this->linearMomentum, linearImpulse );
|
||||||
Float3 deltaPos = deltaTime * ::Utility::Value::AverageWithDelta( Formula::LinearVelocity(this->mass, this->linearMomentum), deltaLinearVelocity );
|
|
||||||
|
|
||||||
// updating the angular
|
// updating the angular
|
||||||
// dw = dt * a = dt * ( I^-1 * T )
|
// dH = T * dt
|
||||||
// rotation = dt * avg_w
|
// dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H
|
||||||
Float4x4 inversedMomentOfInertiaTensor = this->momentOfInertiaTensor.GetInverse();
|
Float3 angularImpulse = this->impulseTorqueSum * deltaTime; // aka deltaAngularMomentum
|
||||||
Float3 deltaAngularVelocity = Formula::AngularImpulseAcceleration( inversedMomentOfInertiaTensor, this->impulseTorqueSum ); // I^-1 * T
|
Float3 rotationAxis = Formula::AngularVelocity( wMomentOfInertiaTensor.GetInverse(),
|
||||||
deltaAngularVelocity *= deltaTime;
|
::Utility::Value::AverageWithDelta(this->angularMomentum, angularImpulse) );
|
||||||
Float3 rotationAxis = ::Utility::Value::AverageWithDelta( Formula::AngularVelocity(inversedMomentOfInertiaTensor,this->angularMomentum), deltaAngularVelocity );
|
|
||||||
|
|
||||||
Float deltaRadian = rotationAxis.Dot( rotationAxis );
|
Float deltaRadian = rotationAxis.Dot( rotationAxis );
|
||||||
if( deltaRadian != 0.0f )
|
if( deltaRadian != 0.0f )
|
||||||
|
@ -60,95 +61,72 @@ void RigidBody::Update_LeapFrog( Float deltaTime )
|
||||||
deltaRadian = ::std::sqrt( deltaRadian );
|
deltaRadian = ::std::sqrt( deltaRadian );
|
||||||
rotationAxis /= deltaRadian;
|
rotationAxis /= deltaRadian;
|
||||||
|
|
||||||
// using rotationAxis, deltaRadian and deltaPos to create a matrix to update the orientation matrix
|
// using rotationAxis, deltaRadian and deltaPos to create a matrix to update the box
|
||||||
UpdateOrientationMatrix( deltaPos, RotationMatrix(deltaRadian, rotationAxis), this->box.orientation );
|
this->box.center += deltaPos;
|
||||||
|
TransformMatrix( RotationMatrix(deltaRadian, rotationAxis), this->box.rotation, this->box.rotation );
|
||||||
/** @todo TODO: ISSUE! how is momentOfInertiaTensor related to the orientation of the RigidBody? */
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // no rotation, only use deltaPos to translate the RigidBody
|
{ // no rotation, only use deltaPos to translate the RigidBody
|
||||||
this->box.center += deltaPos;
|
this->box.center += deltaPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update movements and clear impulses
|
// update momentums and clear impulseForceSum and impulseTorqueSum
|
||||||
this->linearMomentum += Formula::LinearMomentum( this->mass, deltaLinearVelocity );
|
this->linearMomentum += linearImpulse;
|
||||||
this->impulseForceSum = Float3::null;
|
this->impulseForceSum = Float3::null;
|
||||||
this->angularMomentum += Formula::AngularMomentum( this->momentOfInertiaTensor, deltaAngularVelocity );
|
this->angularMomentum += angularImpulse;
|
||||||
this->impulseTorqueSum = Float3::null;
|
this->impulseTorqueSum = Float3::null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyImpulseForce( const Float3 &f )
|
void RigidBody::ApplyImpulseForce( const Float3 &worldF )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseForceSum += f;
|
this->impulseForceSum += worldF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyImpulseForceAt_Local( const Float3 &localForce, const Float3 &localOffset )
|
void RigidBody::ApplyImpulseForceAt( const Float3 &worldF, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
if( localOffset != Float3::null )
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
|
if( worldOffset != Float3::null )
|
||||||
{
|
{
|
||||||
this->impulseForceSum += VectorProjection( localForce, localOffset );
|
this->impulseForceSum += VectorProjection( worldF, worldOffset );
|
||||||
this->impulseTorqueSum += Formula::ImpulseTorque( localForce, localOffset );
|
this->impulseTorqueSum += Formula::ImpulseTorque( worldF, worldOffset );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->impulseForceSum += localForce;
|
this->impulseForceSum += worldF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyImpulseForceAt_World( const Float3 &worldForce, const Float3 &worldPos )
|
void RigidBody::ApplyLinearImpulseAcceleration( const Float3 &worldA )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float4x4 view = this->GetView();
|
this->impulseForceSum += Formula::ImpulseForce( this->mass, worldA );
|
||||||
this->ApplyImpulseForceAt_Local( (view * Float4(worldForce, 0.0f)).xyz,
|
|
||||||
(view * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyLinearImpulseAcceleration( const Float3 &a )
|
void RigidBody::ApplyLinearImpulseAccelerationAt( const Float3 &worldA, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseForceSum += Formula::ImpulseForce( this->mass, a );
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
}
|
if( worldOffset != Float3::null )
|
||||||
|
|
||||||
void RigidBody::ApplyLinearImpulseAccelerationAt_Local( const Float3 &localImpulseLinearAcc, const Float3 &localOffset )
|
|
||||||
{ // by Dan Andersson
|
|
||||||
if( localOffset != Float3::null )
|
|
||||||
{
|
{
|
||||||
this->impulseForceSum += Formula::ImpulseForce( this->mass, VectorProjection(localImpulseLinearAcc, localOffset) );
|
this->impulseForceSum += Formula::ImpulseForce( this->mass, VectorProjection(worldA, worldOffset) );
|
||||||
|
|
||||||
// tanAcc = angularAcc x localPosition
|
// tanAcc = angularAcc x localPosition
|
||||||
// angularAcc = localPosition x tanAcc = localPosition x linearAcc
|
// angularAcc = localPosition x tanAcc = localPosition x linearAcc
|
||||||
// T = I * angularAcc
|
// T = I * angularAcc
|
||||||
this->impulseTorqueSum += Formula::ImpulseTorque( this->momentOfInertiaTensor, Formula::AngularImpulseAcceleration(localImpulseLinearAcc, localOffset) );
|
this->impulseTorqueSum += Formula::ImpulseTorque( this->momentOfInertiaTensor, Formula::AngularImpulseAcceleration(worldA, worldOffset) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->impulseForceSum += Formula::ImpulseForce( this->mass, localImpulseLinearAcc );
|
this->impulseForceSum += Formula::ImpulseForce( this->mass, worldA );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyLinearImpulseAccelerationAt_World( const Float3 &worldImpulseLinearAcc, const Float3 &worldPos )
|
void RigidBody::ApplyImpulseTorque( const Float3 &worldT )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
Float4x4 view = this->GetView();
|
this->impulseTorqueSum += worldT;
|
||||||
this->ApplyLinearImpulseAccelerationAt_Local( (view * Float4(worldImpulseLinearAcc, 0.0f)).xyz,
|
|
||||||
(view * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::ApplyImpulseTorque( const Float3 &t )
|
void RigidBody::ApplyAngularImpulseAcceleration( const Float3 &worldA )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseTorqueSum += t;
|
this->impulseTorqueSum += Formula::ImpulseTorque( this->momentOfInertiaTensor, worldA );
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBody::ApplyAngularImpulseAcceleration( const Float3 &a )
|
|
||||||
{ // by Dan Andersson
|
|
||||||
this->impulseTorqueSum += Formula::ImpulseTorque( this->momentOfInertiaTensor, a );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float4x4 & RigidBody::AccessOrientation()
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->box.orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Float4x4 & RigidBody::AccessOrientation() const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->box.orientation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Float3 & RigidBody::AccessBoundingReach()
|
Float3 & RigidBody::AccessBoundingReach()
|
||||||
|
@ -181,14 +159,14 @@ const Float & RigidBody::GetMass() const
|
||||||
return this->mass;
|
return this->mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Float4x4 & RigidBody::GetOrientation() const
|
const Float4x4 RigidBody::GetOrientation() const
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return this->box.orientation;
|
return OrientationMatrix( this->box.rotation, this->box.center );
|
||||||
}
|
}
|
||||||
|
|
||||||
Float4x4 RigidBody::GetView() const
|
Float4x4 RigidBody::GetView() const
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return InverseOrientationMatrix( this->box.orientation );
|
return InverseOrientationMatrix( this->GetOrientation() );
|
||||||
}
|
}
|
||||||
|
|
||||||
const Float3 & RigidBody::GetBoundingReach() const
|
const Float3 & RigidBody::GetBoundingReach() const
|
||||||
|
@ -246,106 +224,21 @@ Float3 RigidBody::GetLinearVelocity() const
|
||||||
return Formula::LinearVelocity( this->mass, this->linearMomentum );
|
return Formula::LinearVelocity( this->mass, this->linearMomentum );
|
||||||
}
|
}
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialImpulseForceAt_Local( const Float3 &localPos ) const
|
void RigidBody::GetMomentumAt( const Float3 &worldPos, const Float3 &surfaceNormal, Float3 &normalMomentum, Float3 &tangentialMomentum ) const
|
||||||
{ // by Dan Andersson
|
{
|
||||||
return Formula::TangentialImpulseForce( this->impulseTorqueSum, localPos );
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
|
Float3 momentum = Formula::TangentialLinearMomentum( this->angularMomentum, worldOffset );
|
||||||
|
momentum += this->linearMomentum;
|
||||||
|
|
||||||
|
normalMomentum = NormalProjection( momentum, surfaceNormal );
|
||||||
|
tangentialMomentum = momentum - normalMomentum;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialImpulseForceAt_World( const Float3 &worldPos ) const
|
void RigidBody::SetMomentOfInertia( const Float4x4 &localI )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return this->GetTangentialImpulseForceAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
if( localI.GetDeterminant() != 0.0f ) // insanitycheck! momentOfInertiaTensor must be invertable
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialLinearMomentumAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return Formula::TangentialLinearMomentum( this->angularMomentum, localPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialLinearMomentumAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->GetTangentialLinearMomentumAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialImpulseAccelerationAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return Formula::TangentialImpulseAcceleration( this->momentOfInertiaTensor.GetInverse(), this->impulseTorqueSum, localPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialImpulseAccelerationAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->GetTangentialImpulseAccelerationAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialLinearVelocityAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return Formula::TangentialLinearVelocity( this->momentOfInertiaTensor.GetInverse(), this->angularMomentum, localPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetTangentialLinearVelocityAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->GetTangentialLinearVelocityAt_Local( (this->GetView() * Float4(worldPos, 1.0f)).xyz ); // should not be any disform thus result.w = 1.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetImpulseForceAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
return this->impulseForceSum + Formula::TangentialImpulseForce( this->impulseForceSum, localPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetImpulseForceAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
Float4 localForce = Float4( this->GetImpulseForceAt_Local((this->GetView() * Float4(worldPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
|
|
||||||
return (this->box.orientation * localForce).xyz; // should not be any disform thus result.w = 0.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetLinearMomentumAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Momentum is a world value.
|
|
||||||
return Float3::null; // TODO:
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetLinearMomentumAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Momentum is a world value.
|
|
||||||
Float4 localMomentum = Float4( this->GetLinearMomentumAt_Local((this->GetView() * Float4(worldPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
|
|
||||||
return (this->box.orientation * localMomentum).xyz; // should not be any disform thus result.w = 0.0f
|
|
||||||
|
|
||||||
// TODO: angularMomentum is a local value!!
|
|
||||||
return this->linearMomentum + Formula::TangentialLinearMomentum( this->angularMomentum, worldPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetImpulseAccelerationAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Acceleration is a world value.
|
|
||||||
Float4 worldAccel = Float4( this->GetImpulseAccelerationAt_Local((this->box.orientation * Float4(localPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
|
|
||||||
return (this->GetView() * worldAccel).xyz; // should not be any disform thus result.w = 0.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetImpulseAccelerationAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Acceleration is a world value.
|
|
||||||
return Formula::LinearImpulseAcceleration( this->mass, this->impulseForceSum )
|
|
||||||
+ Formula::TangentialImpulseAcceleration( this->momentOfInertiaTensor.GetInverse(), this->impulseTorqueSum, worldPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetLinearVelocityAt_Local( const Float3 &localPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Velocity is a world value.
|
|
||||||
Float4 worldV = Float4( this->GetLinearVelocityAt_Local((this->box.orientation * Float4(localPos, 1.0f)).xyz), 0.0f ); // should not be any disform thus result.w = 1.0f
|
|
||||||
return (this->GetView() * worldV).xyz; // should not be any disform thus result.w = 0.0f
|
|
||||||
}
|
|
||||||
|
|
||||||
Float3 RigidBody::GetLinearVelocityAt_World( const Float3 &worldPos ) const
|
|
||||||
{ // by Dan Andersson
|
|
||||||
// Reminder! Velocity is a world value.
|
|
||||||
return Formula::LinearVelocity( this->mass, this->linearMomentum )
|
|
||||||
+ Formula::TangentialLinearVelocity( this->momentOfInertiaTensor.GetInverse(), this->angularMomentum, worldPos );
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBody::SetMomentOfInertia( const Float4x4 &i )
|
|
||||||
{ // by Dan Andersson
|
|
||||||
if( i.GetDeterminant() != 0.0f ) // insanitycheck! momentOfInertiaTensor must be invertable
|
|
||||||
{
|
{
|
||||||
this->momentOfInertiaTensor = i;
|
this->momentOfInertiaTensor = localI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +262,8 @@ void RigidBody::SetMass_KeepMomentum( const Float &m )
|
||||||
|
|
||||||
void RigidBody::SetOrientation( const Float4x4 &o )
|
void RigidBody::SetOrientation( const Float4x4 &o )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->box.orientation = o;
|
ExtractRotationMatrix( o, this->box.rotation );
|
||||||
|
this->box.center = o.v[3].xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetSize( const Float3 &widthHeight )
|
void RigidBody::SetSize( const Float3 &widthHeight )
|
||||||
|
@ -377,98 +271,77 @@ void RigidBody::SetSize( const Float3 &widthHeight )
|
||||||
this->box.boundingOffset = 0.5f * widthHeight;
|
this->box.boundingOffset = 0.5f * widthHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetCenter( const Float3 &p )
|
void RigidBody::SetCenter( const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->box.center = p;
|
this->box.center = worldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetImpulseTorque( const Float3 &t )
|
void RigidBody::SetImpulseTorque( const Float3 &worldT )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseTorqueSum = t;
|
this->impulseTorqueSum = worldT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetAngularMomentum( const Float3 &h )
|
void RigidBody::SetAngularMomentum( const Float3 &worldH )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->angularMomentum = h;
|
this->angularMomentum = worldH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetAngularImpulseAcceleration( const Float3 &a )
|
void RigidBody::SetAngularImpulseAcceleration( const Float3 &worldA )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseTorqueSum = Formula::ImpulseTorque( this->momentOfInertiaTensor, a );
|
this->impulseTorqueSum = Formula::ImpulseTorque( this->momentOfInertiaTensor, worldA );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetAngularVelocity( const Float3 &w )
|
void RigidBody::SetAngularVelocity( const Float3 &worldW )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->angularMomentum = Formula::AngularMomentum( this->momentOfInertiaTensor, w );
|
this->angularMomentum = Formula::AngularMomentum( this->momentOfInertiaTensor, worldW );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetImpulseForce( const Float3 &f )
|
void RigidBody::SetImpulseForce( const Float3 &worldF )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseForceSum = f;
|
this->impulseForceSum = worldF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetLinearMomentum( const Float3 &g )
|
void RigidBody::SetLinearMomentum( const Float3 &worldG )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->linearMomentum = g;
|
this->linearMomentum = worldG;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetLinearImpulseAcceleration( const Float3 &a )
|
void RigidBody::SetLinearImpulseAcceleration( const Float3 &worldA )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->impulseForceSum = Formula::ImpulseForce( this->mass, a );
|
this->impulseForceSum = Formula::ImpulseForce( this->mass, worldA );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetLinearVelocity( const Float3 &v )
|
void RigidBody::SetLinearVelocity( const Float3 &worldV )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
this->linearMomentum = Formula::LinearMomentum( this->mass, v );
|
this->linearMomentum = Formula::LinearMomentum( this->mass, worldV );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetImpulseForceAt_Local( const Float3 &localForce, const Float3 &localPos )
|
void RigidBody::SetImpulseForceAt( const Float3 &worldForce, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
// Reminder! Impulse force and torque is world values.
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
Float3 worldForce = ( this->box.orientation * Float4(localForce, 0.0f) ).xyz,
|
this->impulseForceSum = VectorProjection( worldForce, worldOffset );
|
||||||
worldPos = ( this->box.orientation * Float4(localPos, 1.0f) ).xyz;
|
this->impulseTorqueSum = Formula::ImpulseTorque( worldForce, worldOffset );
|
||||||
this->SetImpulseForceAt_World( worldForce, worldPos );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetImpulseForceAt_World( const Float3 &worldForce, const Float3 &worldPos )
|
void RigidBody::SetLinearMomentumAt( const Float3 &worldG, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
// Reminder! Impulse force and torque is world values.
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
this->impulseForceSum = VectorProjection( worldForce, worldPos );
|
this->linearMomentum = VectorProjection( worldG, worldOffset );
|
||||||
this->impulseTorqueSum = Formula::ImpulseTorque( worldForce, worldPos );
|
this->angularMomentum = Formula::AngularMomentum( worldG, worldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetLinearMomentumAt_Local( const Float3 &localG, const Float3 &localPos )
|
void RigidBody::SetImpulseAccelerationAt( const Float3 &worldA, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
// Reminder! Linear and angular momentum is world values.
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
Float3 worldG = ( this->box.orientation * Float4(localG, 0.0f) ).xyz,
|
this->impulseForceSum = Formula::ImpulseForce( this->mass, VectorProjection(worldA, worldOffset) );
|
||||||
worldPos = ( this->box.orientation * Float4(localPos, 1.0f) ).xyz;
|
this->impulseTorqueSum = Formula::ImpulseTorque( this->box.rotation * this->momentOfInertiaTensor,
|
||||||
this->SetLinearMomentumAt_World( worldG, worldPos );
|
Formula::AngularImpulseAcceleration(worldA, worldOffset) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetLinearMomentumAt_World( const Float3 &worldG, const Float3 &worldPos )
|
void RigidBody::SetLinearVelocityAt( const Float3 &worldV, const Float3 &worldPos )
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
// Reminder! Linear and angular momentum is world values.
|
Float3 worldOffset = worldPos - this->box.center;
|
||||||
this->linearMomentum = VectorProjection( worldG, worldPos );
|
this->linearMomentum = Formula::LinearMomentum( this->mass, VectorProjection(worldV, worldOffset) );
|
||||||
this->angularMomentum = Formula::AngularMomentum( worldG, worldPos );
|
this->angularMomentum = Formula::AngularMomentum( this->box.rotation * this->momentOfInertiaTensor,
|
||||||
}
|
Formula::AngularVelocity(worldV, worldOffset) );
|
||||||
|
|
||||||
void RigidBody::SetImpulseAccelerationAt_Local( const Float3 &a, const Float3 &pos )
|
|
||||||
{ // by Dan Andersson
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBody::SetImpulseAccelerationAt_World( const Float3 &a, const Float3 &pos )
|
|
||||||
{ // by
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBody::SetLinearVelocityAt_Local( const Float3 &v, const Float3 &pos )
|
|
||||||
{ // by
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RigidBody::SetLinearVelocityAt_World( const Float3 &v, const Float3 &pos )
|
|
||||||
{ // by
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -14,30 +14,26 @@ namespace Oyster { namespace Physics3D
|
||||||
struct RigidBody
|
struct RigidBody
|
||||||
{ /// A struct of a simple rigid body.
|
{ /// A struct of a simple rigid body.
|
||||||
public:
|
public:
|
||||||
::Oyster::Collision3D::Box box; /// Contains data representing physical presence.
|
::Oyster::Collision3D::Box box; /** Contains data representing physical presence. (worldValue) */
|
||||||
::Oyster::Math::Float3 angularMomentum, /// The angular momentum H (Nm*s) around an parallell axis.
|
::Oyster::Math::Float3 angularMomentum, /** The angular momentum H (Nm*s) around an parallell axis. (worldValue) */
|
||||||
linearMomentum, /// The linear momentum G (kg*m/s).
|
linearMomentum, /** The linear momentum G (kg*m/s). (worldValue) */
|
||||||
impulseTorqueSum, /// The impulse torque T (Nm) that will be consumed each update.
|
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.
|
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( const ::Oyster::Collision3D::Box &box = ::Oyster::Collision3D::Box(), ::Oyster::Math::Float mass = 1.0f );
|
||||||
|
|
||||||
RigidBody & operator = ( const RigidBody &body );
|
RigidBody & operator = ( const RigidBody &body );
|
||||||
|
|
||||||
void Update_LeapFrog( ::Oyster::Math::Float deltaTime );
|
void Update_LeapFrog( ::Oyster::Math::Float deltaTime );
|
||||||
void ApplyImpulseForce( const ::Oyster::Math::Float3 &f );
|
void ApplyImpulseForce( const ::Oyster::Math::Float3 &worldF );
|
||||||
void ApplyImpulseForceAt_Local( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
|
void ApplyImpulseForceAt( const ::Oyster::Math::Float3 &worldF, const ::Oyster::Math::Float3 &worldPos );
|
||||||
void ApplyImpulseForceAt_World( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos ); /// ApplyImpulseForce_LocalPos is preferred
|
void ApplyLinearImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
|
||||||
void ApplyLinearImpulseAcceleration( const ::Oyster::Math::Float3 &a );
|
void ApplyLinearImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldA, const ::Oyster::Math::Float3 &worldPos );
|
||||||
void ApplyLinearImpulseAccelerationAt_Local( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos );
|
void ApplyImpulseTorque( const ::Oyster::Math::Float3 &worldT );
|
||||||
void ApplyLinearImpulseAccelerationAt_World( const ::Oyster::Math::Float3 &a, const ::Oyster::Math::Float3 &pos ); /// ApplyLinearImpulseAcceleration_LocalPos is preferred
|
void ApplyAngularImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
|
||||||
void ApplyImpulseTorque( const ::Oyster::Math::Float3 &t );
|
|
||||||
void ApplyAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a );
|
|
||||||
|
|
||||||
// ACCESS METHODS /////////////////////////////
|
// ACCESS METHODS /////////////////////////////
|
||||||
|
|
||||||
::Oyster::Math::Float4x4 & AccessOrientation();
|
|
||||||
const ::Oyster::Math::Float4x4 & AccessOrientation() const;
|
|
||||||
::Oyster::Math::Float3 & AccessBoundingReach();
|
::Oyster::Math::Float3 & AccessBoundingReach();
|
||||||
const ::Oyster::Math::Float3 & AccessBoundingReach() const;
|
const ::Oyster::Math::Float3 & AccessBoundingReach() const;
|
||||||
::Oyster::Math::Float3 & AccessCenter();
|
::Oyster::Math::Float3 & AccessCenter();
|
||||||
|
@ -48,7 +44,7 @@ namespace Oyster { namespace Physics3D
|
||||||
const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
|
const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
|
||||||
const ::Oyster::Math::Float & GetMass() const;
|
const ::Oyster::Math::Float & GetMass() const;
|
||||||
|
|
||||||
const ::Oyster::Math::Float4x4 & GetOrientation() const;
|
const ::Oyster::Math::Float4x4 GetOrientation() const;
|
||||||
::Oyster::Math::Float4x4 GetView() const;
|
::Oyster::Math::Float4x4 GetView() const;
|
||||||
const ::Oyster::Math::Float4x4 & GetToWorldMatrix() const;
|
const ::Oyster::Math::Float4x4 & GetToWorldMatrix() const;
|
||||||
::Oyster::Math::Float4x4 GetToLocalMatrix() const;
|
::Oyster::Math::Float4x4 GetToLocalMatrix() const;
|
||||||
|
@ -68,56 +64,36 @@ namespace Oyster { namespace Physics3D
|
||||||
::Oyster::Math::Float3 GetLinearImpulseAcceleration() const;
|
::Oyster::Math::Float3 GetLinearImpulseAcceleration() const;
|
||||||
::Oyster::Math::Float3 GetLinearVelocity() const;
|
::Oyster::Math::Float3 GetLinearVelocity() const;
|
||||||
|
|
||||||
::Oyster::Math::Float3 GetTangentialImpulseForceAt_Local( const ::Oyster::Math::Float3 &pos ) const;
|
void GetMomentumAt( const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &surfaceNormal, ::Oyster::Math::Float3 &normalMomentum, ::Oyster::Math::Float3 &tangentialMomentum ) 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 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;
|
|
||||||
|
|
||||||
// SET METHODS ////////////////////////////////
|
// 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_KeepVelocity( const ::Oyster::Math::Float &m );
|
||||||
void SetMass_KeepMomentum( const ::Oyster::Math::Float &m );
|
void SetMass_KeepMomentum( const ::Oyster::Math::Float &m );
|
||||||
|
|
||||||
void SetOrientation( const ::Oyster::Math::Float4x4 &o );
|
void SetOrientation( const ::Oyster::Math::Float4x4 &o );
|
||||||
void SetSize( const ::Oyster::Math::Float3 &widthHeight );
|
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 SetImpulseTorque( const ::Oyster::Math::Float3 &worldT );
|
||||||
void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
|
void SetAngularMomentum( const ::Oyster::Math::Float3 &worldH );
|
||||||
void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &a );
|
void SetAngularImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
|
||||||
void SetAngularVelocity( const ::Oyster::Math::Float3 &w );
|
void SetAngularVelocity( const ::Oyster::Math::Float3 &worldW );
|
||||||
|
|
||||||
void SetImpulseForce( const ::Oyster::Math::Float3 &f );
|
void SetImpulseForce( const ::Oyster::Math::Float3 &worldF );
|
||||||
void SetLinearMomentum( const ::Oyster::Math::Float3 &g );
|
void SetLinearMomentum( const ::Oyster::Math::Float3 &worldG );
|
||||||
void SetLinearImpulseAcceleration( const ::Oyster::Math::Float3 &a );
|
void SetLinearImpulseAcceleration( const ::Oyster::Math::Float3 &worldA );
|
||||||
void SetLinearVelocity( const ::Oyster::Math::Float3 &v );
|
void SetLinearVelocity( const ::Oyster::Math::Float3 &worldV );
|
||||||
|
|
||||||
void SetImpulseForceAt_Local( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
|
void SetImpulseForceAt( const ::Oyster::Math::Float3 &worldF, const ::Oyster::Math::Float3 &worldPos );
|
||||||
void SetImpulseForceAt_World( const ::Oyster::Math::Float3 &f, const ::Oyster::Math::Float3 &pos );
|
void SetLinearMomentumAt( const ::Oyster::Math::Float3 &worldG, const ::Oyster::Math::Float3 &worldPos );
|
||||||
void SetLinearMomentumAt_Local( const ::Oyster::Math::Float3 &g, const ::Oyster::Math::Float3 &pos );
|
void SetImpulseAccelerationAt( const ::Oyster::Math::Float3 &worldA, const ::Oyster::Math::Float3 &worldPos );
|
||||||
void SetLinearMomentumAt_World( const ::Oyster::Math::Float3 &g, const ::Oyster::Math::Float3 &pos );
|
void SetLinearVelocityAt( const ::Oyster::Math::Float3 &worldV, const ::Oyster::Math::Float3 &worldPos );
|
||||||
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 );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::Oyster::Math::Float mass; /// m (kg)
|
::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::Float4x4 momentOfInertiaTensor; /** I (Nm*s) Tensor matrix ( only need to be 3x3 matrix, but is 4x4 for future hardware acceleration ) (localValue) */
|
||||||
};
|
};
|
||||||
|
|
||||||
// INLINE IMPLEMENTATIONS ///////////////////////////////////////
|
// INLINE IMPLEMENTATIONS ///////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue