Added bunch of Quaternion functions

Needed one of them to create  a bug trap
This commit is contained in:
Dander7BD 2014-02-19 14:51:37 +01:00
parent 8917caf08a
commit 706395680f
1 changed files with 52 additions and 0 deletions

View File

@ -49,7 +49,16 @@ namespace LinearAlgebra
Quaternion<ScalarType> operator - ( const Quaternion<ScalarType> &quaternion ) const;
Quaternion<ScalarType> operator - ( ) const;
Quaternion<ScalarType> & Conjugate( );
Quaternion<ScalarType> & Normalize( );
Quaternion<ScalarType> & Inverse( );
Quaternion<ScalarType> GetConjugate( ) const;
Quaternion<ScalarType> GetNormalized( ) const;
Quaternion<ScalarType> GetInversed( ) const;
ScalarType GetNorm( ) const;
ScalarType GetModulus( ) const;
};
///////////////////////////////////////////////////////////////////////////////////
@ -205,11 +214,54 @@ namespace LinearAlgebra
return Quaternion<ScalarType>(-this->imaginary, -this->real);
}
template<typename ScalarType>
inline Quaternion<ScalarType> & Quaternion<ScalarType>::Conjugate( )
{
this->imaginary = -this->imaginary;
return *this;
}
template<typename ScalarType>
inline Quaternion<ScalarType> & Quaternion<ScalarType>::Normalize( )
{
return *this /= this->GetModulus();
}
template<typename ScalarType>
inline Quaternion<ScalarType> & Quaternion<ScalarType>::Inverse( )
{
return this->Conjugate() /= this->GetNorm();
}
template<typename ScalarType>
inline Quaternion<ScalarType> Quaternion<ScalarType>::GetConjugate( ) const
{
return Quaternion<ScalarType>(-this->imaginary, this->real );
}
template<typename ScalarType>
inline Quaternion<ScalarType> Quaternion<ScalarType>::GetNormalized( ) const
{
return *this / this->GetModulus();
}
template<typename ScalarType>
inline Quaternion<ScalarType> Quaternion<ScalarType>::GetInversed( ) const
{
return this->GetConjugate() /= this->GetNorm();
}
template<typename ScalarType>
inline ScalarType Quaternion<ScalarType>::GetNorm( ) const
{
return this->imaginary.Dot(this->imaginary) + this->real * this->real;
}
template<typename ScalarType>
inline ScalarType Quaternion<ScalarType>::GetModulus( ) const
{
return (ScalarType)::std::sqrt( this->GetNorm() );
}
}
#endif