From 6e0338ee6bb61d16052aeb2ee766d80ca50c86a8 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 24 Feb 2014 14:35:38 +0100 Subject: [PATCH] Minor mathematical fix AngularAxis had a bug. SnapAngularAxis is determined broken. Do not use. :( --- Code/Misc/OysterMath/LinearMath.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Code/Misc/OysterMath/LinearMath.h b/Code/Misc/OysterMath/LinearMath.h index 25b65331..5b87d83d 100644 --- a/Code/Misc/OysterMath/LinearMath.h +++ b/Code/Misc/OysterMath/LinearMath.h @@ -376,9 +376,13 @@ namespace LinearAlgebra3D template inline ::LinearAlgebra::Vector3 AngularAxis( const ::LinearAlgebra::Quaternion &rotation ) { // see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm - ScalarType angle = ScalarType(2) * (ScalarType)::std::acos( rotation.real ), - multiplier = angle / (ScalarType)::std::sqrt( ScalarType(1) - rotation.real * rotation.real ); - return multiplier * rotation.imaginary; + if( rotation.real < ScalarType(1) ) + { + ScalarType angle = ScalarType(2) * ScalarType( ::std::acos(rotation.real) ), + multiplier = angle / ScalarType( ::std::sqrt(ScalarType(1) - rotation.real * rotation.real) ); + return multiplier * rotation.imaginary; + } + else return ::LinearAlgebra::Vector3::null; } // All Matrix to AngularAxis conversions here is incorrect @@ -838,7 +842,7 @@ namespace LinearAlgebra3D template ::LinearAlgebra::Vector3 & SnapAngularAxis( const ::LinearAlgebra::Vector3 &startAngularAxis, const ::LinearAlgebra::Vector3 &localStartNormal, const ::LinearAlgebra::Vector3 &worldEndNormal, ::LinearAlgebra::Vector3 &targetMem = ::LinearAlgebra::Vector3() ) - { + { //! @todo TODO: This code is broken and do not work! ::LinearAlgebra::Vector3 worldStartNormal( WorldAxisOf(Rotation(startAngularAxis), localStartNormal) ); targetMem = worldStartNormal.Cross( worldEndNormal ); targetMem *= (ScalarType)::std::acos( ::Utility::Value::Clamp(worldStartNormal.Dot(worldEndNormal), (ScalarType)0, (ScalarType)1) );