Proper getAngleDiff implementations

This commit is contained in:
Jack Andersen 2019-03-09 23:14:23 -10:00
parent a240b39a11
commit cb4ede8097
2 changed files with 5 additions and 7 deletions

View File

@ -9,12 +9,11 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b) {
float mag1 = a.magnitude();
float mag2 = b.magnitude();
if (!mag1 || !mag2)
return 0;
if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON)
return 0.f;
float dot = a.dot(b);
float theta = std::acos(dot / (mag1 * mag2));
return theta;
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
}
CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) {

View File

@ -11,12 +11,11 @@ float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) {
float mag1 = a.magnitude();
float mag2 = b.magnitude();
if (!mag1 || !mag2)
if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON)
return 0.f;
float dot = a.dot(b);
float theta = std::acos(dot / (mag1 * mag2));
return theta;
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
}
CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {