Added Quaternion::(Make)RotationBetween

Former-commit-id: e28517580bd17970e77a38f54e7c114cdaf402d5
This commit is contained in:
Lynix 2013-05-13 12:52:39 +02:00
parent 16004fd41c
commit 6c743a89b9
2 changed files with 23 additions and 0 deletions

View File

@ -37,6 +37,7 @@ template<typename T> class NzQuaternion
NzQuaternion& Inverse();
NzQuaternion& MakeIdentity();
NzQuaternion& MakeRotationBetween(const NzVector3<T>& from, const NzVector3<T>& to);
NzQuaternion& MakeZero();
T Magnitude() const;
@ -75,6 +76,7 @@ template<typename T> class NzQuaternion
static NzQuaternion Identity();
static NzQuaternion Lerp(const NzQuaternion& from, const NzQuaternion& to, T interpolation);
static NzQuaternion RotationBetween(const NzVector3<T>& from, const NzVector3<T>& to);
static NzQuaternion Slerp(const NzQuaternion& from, const NzQuaternion& to, T interpolation);
static NzQuaternion Zero();

View File

@ -129,6 +129,18 @@ NzQuaternion<T>& NzQuaternion<T>::MakeIdentity()
return Set(F(1.0), F(0.0), F(0.0), F(0.0));
}
template<typename T>
NzQuaternion<T>& NzQuaternion<T>::MakeRotationBetween(const NzVector3<T>& from, const NzVector3<T>& to)
{
NzVector3f a = from.CrossProduct(to);
x = a.x;
y = a.y;
z = a.z;
w = std::sqrt(std::pow(from.GetLength(), 2.f) * std::pow(to.GetLength(), 2.f)) + from.DotProduct(to);
return Normalize();
}
template<typename T>
NzQuaternion<T>& NzQuaternion<T>::MakeZero()
{
@ -382,6 +394,15 @@ NzQuaternion<T> NzQuaternion<T>::Lerp(const NzQuaternion& from, const NzQuaterni
return interpolated;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::RotationBetween(const NzVector3<T>& from, const NzVector3<T>& to)
{
NzQuaternion quaternion;
quaternion.MakeRotationBetween(from, to);
return quaternion;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& from, const NzQuaternion& to, T interpolation)
{