Added OrientationMatrix build methods + other stuff

This commit is contained in:
Dander7BD 2013-11-21 15:19:32 +01:00
parent 938826b84e
commit dc9f4597e2
6 changed files with 58 additions and 7 deletions

View File

@ -30,7 +30,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp"> <ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
<Filter>Header Files\Implementation</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,6 +1,7 @@
#ifndef PHYSICS_API_H #ifndef PHYSICS_API_H
#define PHYSICS_API_H #define PHYSICS_API_H
#include "OysterCollision3D.h"
#include "OysterMath.h" #include "OysterMath.h"
#include "Utilities.h" #include "Utilities.h"
@ -12,6 +13,12 @@ namespace Oyster
class IRigidBody; class IRigidBody;
class IParticle; class IParticle;
enum UpdateState
{
resting,
altered
};
namespace Constant namespace Constant
{ {
const float gravity_constant = (const float)6.67284e-11; // The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields. const float gravity_constant = (const float)6.67284e-11; // The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields.
@ -32,17 +39,28 @@ namespace Oyster
virtual void Update() = 0; virtual void Update() = 0;
virtual void MoveToLimbo( unsigned int objRef ); virtual bool IsInLimbo( unsigned int objRef ) = 0;
virtual void ReleaseFromLimbo( unsigned int objRef ); virtual void MoveToLimbo( unsigned int objRef ) = 0;
virtual void ReleaseFromLimbo( unsigned int objRef ) = 0;
virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer<IRigidBody> handle ); virtual unsigned int AddObject( ::Utility::DynamicMemory::UniquePointer<IRigidBody> handle ) = 0;
virtual void DestroyObject( unsigned int objRef ); virtual ::Utility::DynamicMemory::UniquePointer<IRigidBody> ExtractObject( unsigned int objRef ) = 0;
virtual void DestroyObject( unsigned int objRef ) = 0;
}; };
class IRigidBody class IRigidBody
{ {
public: 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 class IParticle

View File

@ -386,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>() )
{ {
@ -458,7 +475,7 @@ namespace LinearAlgebra3D
template<typename ScalarType> template<typename ScalarType>
inline ::LinearAlgebra::Vector3<ScalarType> NormalProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &normalizedAxis ) inline ::LinearAlgebra::Vector3<ScalarType> NormalProjection( const ::LinearAlgebra::Vector3<ScalarType> &vector, const ::LinearAlgebra::Vector3<ScalarType> &normalizedAxis )
{ return axis * ( vector.Dot(axis) ); } { return normalizedAxis * ( vector.Dot(normalizedAxis) ); }
} }
#include "Utilities.h" #include "Utilities.h"

View File

@ -131,6 +131,16 @@ namespace Oyster { namespace Math3D
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 );

View File

@ -207,6 +207,12 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
*******************************************************************/ *******************************************************************/
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 &centerOfMass, Float4x4 &targetMem = Float4x4() ); Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 &centerOfMass, 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() );

View File

@ -70,7 +70,7 @@ void RigidBody::Update_LeapFrog( Float deltaTime )
this->box.center += deltaPos; this->box.center += deltaPos;
} }
// update movements and clear impulseForceSum and impulseTorqueSum // update momentums and clear impulseForceSum and impulseTorqueSum
this->linearMomentum += linearImpulse; this->linearMomentum += linearImpulse;
this->impulseForceSum = Float3::null; this->impulseForceSum = Float3::null;
this->angularMomentum += angularImpulse; this->angularMomentum += angularImpulse;