From 706395680f6d1914dd4a1d05fc269ff1a365bd23 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:51:37 +0100 Subject: [PATCH] Added bunch of Quaternion functions Needed one of them to create a bug trap --- Code/Misc/OysterMath/Quaternion.h | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index f5ea5951..b2390a2d 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -49,7 +49,16 @@ namespace LinearAlgebra Quaternion operator - ( const Quaternion &quaternion ) const; Quaternion operator - ( ) const; + Quaternion & Conjugate( ); + Quaternion & Normalize( ); + Quaternion & Inverse( ); + Quaternion GetConjugate( ) const; + Quaternion GetNormalized( ) const; + Quaternion GetInversed( ) const; + ScalarType GetNorm( ) const; + ScalarType GetModulus( ) const; + }; /////////////////////////////////////////////////////////////////////////////////// @@ -205,11 +214,54 @@ namespace LinearAlgebra return Quaternion(-this->imaginary, -this->real); } + template + inline Quaternion & Quaternion::Conjugate( ) + { + this->imaginary = -this->imaginary; + return *this; + } + + template + inline Quaternion & Quaternion::Normalize( ) + { + return *this /= this->GetModulus(); + } + + template + inline Quaternion & Quaternion::Inverse( ) + { + return this->Conjugate() /= this->GetNorm(); + } + template inline Quaternion Quaternion::GetConjugate( ) const { return Quaternion(-this->imaginary, this->real ); } + + template + inline Quaternion Quaternion::GetNormalized( ) const + { + return *this / this->GetModulus(); + } + + template + inline Quaternion Quaternion::GetInversed( ) const + { + return this->GetConjugate() /= this->GetNorm(); + } + + template + inline ScalarType Quaternion::GetNorm( ) const + { + return this->imaginary.Dot(this->imaginary) + this->real * this->real; + } + + template + inline ScalarType Quaternion::GetModulus( ) const + { + return (ScalarType)::std::sqrt( this->GetNorm() ); + } } #endif \ No newline at end of file