mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-05-30 19:21:25 +00:00
Made a fix to CQuaternion::Slerp to fix animation jitteriness
This commit is contained in:
parent
cf84f9909a
commit
07609cfa14
@ -43,6 +43,12 @@ CVector3f CQuaternion::ZAxis() const
|
|||||||
return (*this * CVector3f::skUnitZ);
|
return (*this * CVector3f::skUnitZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CQuaternion CQuaternion::Normalized() const
|
||||||
|
{
|
||||||
|
float Norm = Math::Sqrt( (W * W) + (X * X) + (Y * Y) + (Z * Z) );
|
||||||
|
return CQuaternion(W/Norm, X/Norm, Y/Norm, Z/Norm);
|
||||||
|
}
|
||||||
|
|
||||||
CQuaternion CQuaternion::Inverse() const
|
CQuaternion CQuaternion::Inverse() const
|
||||||
{
|
{
|
||||||
float Norm = (W * W) + (X * X) + (Y * Y) + (Z * Z);
|
float Norm = (W * W) + (X * X) + (Y * Y) + (Z * Z);
|
||||||
@ -56,13 +62,24 @@ CQuaternion CQuaternion::Inverse() const
|
|||||||
return CQuaternion::skZero;
|
return CQuaternion::skZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CQuaternion CQuaternion::Lerp(const CQuaternion& rkRight, float t) const
|
||||||
|
{
|
||||||
|
CQuaternion Out( Math::Lerp<float>(W, rkRight.W, t), Math::Lerp<float>(X, rkRight.X, t),
|
||||||
|
Math::Lerp<float>(Y, rkRight.Y, t), Math::Lerp<float>(Z, rkRight.Z, t) );
|
||||||
|
|
||||||
|
return Out.Normalized();
|
||||||
|
}
|
||||||
|
|
||||||
CQuaternion CQuaternion::Slerp(const CQuaternion& rkRight, float t) const
|
CQuaternion CQuaternion::Slerp(const CQuaternion& rkRight, float t) const
|
||||||
{
|
{
|
||||||
// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
|
// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
|
||||||
float CosHalfTheta = (W * rkRight.W) + (X * rkRight.X) + (Y * rkRight.Y) + (Z * rkRight.Z);
|
float CosHalfTheta = (W * rkRight.W) + (X * rkRight.X) + (Y * rkRight.Y) + (Z * rkRight.Z);
|
||||||
|
|
||||||
if (Math::Abs(CosHalfTheta) >= 1.f)
|
if (Math::Abs(CosHalfTheta) >= 1.f)
|
||||||
return *this;
|
{
|
||||||
|
// Fall back on lerp in this situation.
|
||||||
|
return Lerp(rkRight, t);
|
||||||
|
}
|
||||||
|
|
||||||
float ScalarA, ScalarB;
|
float ScalarA, ScalarB;
|
||||||
float SinHalfTheta = Math::Sqrt(1.f - (CosHalfTheta * CosHalfTheta));
|
float SinHalfTheta = Math::Sqrt(1.f - (CosHalfTheta * CosHalfTheta));
|
||||||
|
@ -15,7 +15,9 @@ public:
|
|||||||
CVector3f XAxis() const;
|
CVector3f XAxis() const;
|
||||||
CVector3f YAxis() const;
|
CVector3f YAxis() const;
|
||||||
CVector3f ZAxis() const;
|
CVector3f ZAxis() const;
|
||||||
|
CQuaternion Normalized() const;
|
||||||
CQuaternion Inverse() const;
|
CQuaternion Inverse() const;
|
||||||
|
CQuaternion Lerp(const CQuaternion& rkRight, float t) const;
|
||||||
CQuaternion Slerp(const CQuaternion& rkRight, float t) const;
|
CQuaternion Slerp(const CQuaternion& rkRight, float t) const;
|
||||||
CVector3f ToEuler() const;
|
CVector3f ToEuler() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user