Quaternion to angular axis complete

This commit is contained in:
Robin Engman 2014-02-11 13:53:44 +01:00
parent 7075e6add6
commit 1aa66dc79f
3 changed files with 28 additions and 4 deletions

View File

@ -186,6 +186,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
{ {

View File

@ -38,6 +38,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;

View File

@ -146,10 +146,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.