Minor mathematical fix

AngularAxis had a bug.
SnapAngularAxis is determined broken. Do not use. :(
This commit is contained in:
Dander7BD 2014-02-24 14:35:38 +01:00
parent 7bb67b6a85
commit 6e0338ee6b
1 changed files with 8 additions and 4 deletions

View File

@ -376,10 +376,14 @@ namespace LinearAlgebra3D
template<typename ScalarType> template<typename ScalarType>
inline ::LinearAlgebra::Vector3<ScalarType> AngularAxis( const ::LinearAlgebra::Quaternion<ScalarType> &rotation ) inline ::LinearAlgebra::Vector3<ScalarType> AngularAxis( const ::LinearAlgebra::Quaternion<ScalarType> &rotation )
{ // see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm { // see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
ScalarType angle = ScalarType(2) * (ScalarType)::std::acos( rotation.real ), if( rotation.real < ScalarType(1) )
multiplier = angle / (ScalarType)::std::sqrt( ScalarType(1) - rotation.real * rotation.real ); {
ScalarType angle = ScalarType(2) * ScalarType( ::std::acos(rotation.real) ),
multiplier = angle / ScalarType( ::std::sqrt(ScalarType(1) - rotation.real * rotation.real) );
return multiplier * rotation.imaginary; return multiplier * rotation.imaginary;
} }
else return ::LinearAlgebra::Vector3<ScalarType>::null;
}
// All Matrix to AngularAxis conversions here is incorrect // All Matrix to AngularAxis conversions here is incorrect
//template<typename ScalarType> //template<typename ScalarType>
@ -838,7 +842,7 @@ namespace LinearAlgebra3D
template<typename ScalarType> template<typename ScalarType>
::LinearAlgebra::Vector3<ScalarType> & SnapAngularAxis( const ::LinearAlgebra::Vector3<ScalarType> &startAngularAxis, const ::LinearAlgebra::Vector3<ScalarType> &localStartNormal, const ::LinearAlgebra::Vector3<ScalarType> &worldEndNormal, ::LinearAlgebra::Vector3<ScalarType> &targetMem = ::LinearAlgebra::Vector3<ScalarType>() ) ::LinearAlgebra::Vector3<ScalarType> & SnapAngularAxis( const ::LinearAlgebra::Vector3<ScalarType> &startAngularAxis, const ::LinearAlgebra::Vector3<ScalarType> &localStartNormal, const ::LinearAlgebra::Vector3<ScalarType> &worldEndNormal, ::LinearAlgebra::Vector3<ScalarType> &targetMem = ::LinearAlgebra::Vector3<ScalarType>() )
{ { //! @todo TODO: This code is broken and do not work!
::LinearAlgebra::Vector3<ScalarType> worldStartNormal( WorldAxisOf(Rotation(startAngularAxis), localStartNormal) ); ::LinearAlgebra::Vector3<ScalarType> worldStartNormal( WorldAxisOf(Rotation(startAngularAxis), localStartNormal) );
targetMem = worldStartNormal.Cross( worldEndNormal ); targetMem = worldStartNormal.Cross( worldEndNormal );
targetMem *= (ScalarType)::std::acos( ::Utility::Value::Clamp(worldStartNormal.Dot(worldEndNormal), (ScalarType)0, (ScalarType)1) ); targetMem *= (ScalarType)::std::acos( ::Utility::Value::Clamp(worldStartNormal.Dot(worldEndNormal), (ScalarType)0, (ScalarType)1) );