Added quaternion to angular axis in Math

This commit is contained in:
Robin Engman 2014-02-11 14:00:38 +01:00
parent 1aa66dc79f
commit 5d245d7151
2 changed files with 52 additions and 0 deletions

View File

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

View File

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