Merge branch 'GamePhysics' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
4c9d62b163
|
@ -67,6 +67,11 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
|
||||||
this->state = state;
|
this->state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::ApplyImpulse(Float3 impulse)
|
||||||
|
{
|
||||||
|
this->rigidBody->applyImpulse(btVector3(impulse.x, impulse.y, impulse.z), btVector3(0.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape)
|
void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape)
|
||||||
{
|
{
|
||||||
this->collisionShape = shape;
|
this->collisionShape = shape;
|
||||||
|
@ -186,6 +191,28 @@ Float4x4 SimpleRigidBody::GetRotation() const
|
||||||
{
|
{
|
||||||
return this->state.GetRotation();
|
return this->state.GetRotation();
|
||||||
}
|
}
|
||||||
|
Float4 SimpleRigidBody::GetRotationAsAngularAxis()
|
||||||
|
{
|
||||||
|
Float4 axis = Float4::null;
|
||||||
|
Float s = sqrtf(1 - this->state.quaternion.real*this->state.quaternion.real);
|
||||||
|
|
||||||
|
axis.w = 2*acos(this->state.quaternion.real*this->state.quaternion.real);
|
||||||
|
|
||||||
|
if(1 - this->state.quaternion.real > 0.001f)
|
||||||
|
{
|
||||||
|
axis.x = this->state.quaternion.imaginary.x/s;
|
||||||
|
axis.y = this->state.quaternion.imaginary.y/s;
|
||||||
|
axis.z = this->state.quaternion.imaginary.z/s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
axis.x = this->state.quaternion.imaginary.x;
|
||||||
|
axis.y = this->state.quaternion.imaginary.y;
|
||||||
|
axis.z = this->state.quaternion.imaginary.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return axis;
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 SimpleRigidBody::GetOrientation() const
|
Float4x4 SimpleRigidBody::GetOrientation() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,8 @@ namespace Oyster
|
||||||
State& GetState( State &targetMem ) const;
|
State& GetState( State &targetMem ) const;
|
||||||
void SetState( const State &state );
|
void SetState( const State &state );
|
||||||
|
|
||||||
|
void ApplyImpulse(Math::Float3 impulse);
|
||||||
|
|
||||||
void SetCollisionShape(btCollisionShape* shape);
|
void SetCollisionShape(btCollisionShape* shape);
|
||||||
void SetMotionState(btDefaultMotionState* motionState);
|
void SetMotionState(btDefaultMotionState* motionState);
|
||||||
void SetRigidBody(btRigidBody* rigidBody);
|
void SetRigidBody(btRigidBody* rigidBody);
|
||||||
|
@ -38,6 +40,7 @@ namespace Oyster
|
||||||
void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward);
|
void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward);
|
||||||
|
|
||||||
Math::Float4x4 GetRotation() const;
|
Math::Float4x4 GetRotation() const;
|
||||||
|
Math::Float4 GetRotationAsAngularAxis();
|
||||||
Math::Float4x4 GetOrientation() const;
|
Math::Float4x4 GetOrientation() const;
|
||||||
Math::Float4x4 GetView() const;
|
Math::Float4x4 GetView() const;
|
||||||
Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
|
Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
|
||||||
|
|
|
@ -134,6 +134,8 @@ namespace Oyster
|
||||||
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
||||||
virtual void SetSubscription(EventAction_Move function) = 0;
|
virtual void SetSubscription(EventAction_Move function) = 0;
|
||||||
|
|
||||||
|
virtual void ApplyImpulse(::Oyster::Math::Float3 impulse) = 0;
|
||||||
|
|
||||||
virtual void SetLinearVelocity(::Oyster::Math::Float3 velocity) = 0;
|
virtual void SetLinearVelocity(::Oyster::Math::Float3 velocity) = 0;
|
||||||
virtual void SetPosition(::Oyster::Math::Float3 position) = 0;
|
virtual void SetPosition(::Oyster::Math::Float3 position) = 0;
|
||||||
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
||||||
|
@ -146,10 +148,11 @@ namespace Oyster
|
||||||
virtual void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right) = 0;
|
virtual void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right) = 0;
|
||||||
virtual void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward) = 0;
|
virtual void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward) = 0;
|
||||||
|
|
||||||
::Oyster::Math::Float4x4 GetRotation() const;
|
virtual ::Oyster::Math::Float4x4 GetRotation() const = 0;
|
||||||
::Oyster::Math::Float4x4 GetOrientation() const;
|
virtual ::Oyster::Math::Float4 GetRotationAsAngularAxis() = 0;
|
||||||
::Oyster::Math::Float4x4 GetView() const;
|
virtual ::Oyster::Math::Float4x4 GetOrientation() const = 0;
|
||||||
::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
|
virtual ::Oyster::Math::Float4x4 GetView() const = 0;
|
||||||
|
virtual ::Oyster::Math::Float4x4 GetView(const ::Oyster::Math::Float3 &offset) const = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @return the void pointer set by SetCustomTag.
|
* @return the void pointer set by SetCustomTag.
|
||||||
|
|
|
@ -96,6 +96,52 @@ namespace Oyster { namespace Math3D
|
||||||
// return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
|
// return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
Float4 QuaternionToAngularAxis(Float4 quaternion)
|
||||||
|
{
|
||||||
|
Float4 axis = Float4::null;
|
||||||
|
Float s = sqrtf(1 - quaternion.w*quaternion.w);
|
||||||
|
|
||||||
|
axis.w = 2*acos(quaternion.w*quaternion.w);
|
||||||
|
|
||||||
|
if(1 - quaternion.w > 0.001f)
|
||||||
|
{
|
||||||
|
axis.x = quaternion.x/s;
|
||||||
|
axis.y = quaternion.y/s;
|
||||||
|
axis.z = quaternion.z/s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
axis.x = quaternion.x;
|
||||||
|
axis.y = quaternion.y;
|
||||||
|
axis.z = quaternion.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float4 QuaternionToAngularAxis(Quaternion quaternion)
|
||||||
|
{
|
||||||
|
Float4 axis = Float4::null;
|
||||||
|
Float s = sqrtf(1 - quaternion.real*quaternion.real);
|
||||||
|
|
||||||
|
axis.w = 2*acos(quaternion.real*quaternion.real);
|
||||||
|
|
||||||
|
if(1 - quaternion.real > 0.001f)
|
||||||
|
{
|
||||||
|
axis.x = quaternion.imaginary.x/s;
|
||||||
|
axis.y = quaternion.imaginary.y/s;
|
||||||
|
axis.z = quaternion.imaginary.z/s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
axis.x = quaternion.imaginary.x;
|
||||||
|
axis.y = quaternion.imaginary.y;
|
||||||
|
axis.z = quaternion.imaginary.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return axis;
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
|
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
|
||||||
{
|
{
|
||||||
return ::LinearAlgebra3D::TranslationMatrix( position, targetMem );
|
return ::LinearAlgebra3D::TranslationMatrix( position, targetMem );
|
||||||
|
|
|
@ -149,6 +149,12 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
|
||||||
////! Extracts the angularAxis from orientationMatrix
|
////! Extracts the angularAxis from orientationMatrix
|
||||||
//Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
|
//Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
|
||||||
|
|
||||||
|
//! Converts a quaternion as Float4 to angular axis as Float4
|
||||||
|
Float4 QuaternionToAngularAxis(Float4 quaternion);
|
||||||
|
|
||||||
|
//! Converts a quaternion to angular axis as Float4
|
||||||
|
Float4 QuaternionToAngularAxis(Quaternion quaternion);
|
||||||
|
|
||||||
//! Sets and returns targetMem to a translationMatrix with position as translation.
|
//! Sets and returns targetMem to a translationMatrix with position as translation.
|
||||||
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );
|
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue