mirror of https://github.com/AxioDL/zeus.git
Proper getAngleDiff implementations
This commit is contained in:
parent
a240b39a11
commit
cb4ede8097
|
@ -9,12 +9,11 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b) {
|
||||||
float mag1 = a.magnitude();
|
float mag1 = a.magnitude();
|
||||||
float mag2 = b.magnitude();
|
float mag2 = b.magnitude();
|
||||||
|
|
||||||
if (!mag1 || !mag2)
|
if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON)
|
||||||
return 0;
|
return 0.f;
|
||||||
|
|
||||||
float dot = a.dot(b);
|
float dot = a.dot(b);
|
||||||
float theta = std::acos(dot / (mag1 * mag2));
|
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
|
||||||
return theta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) {
|
CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) {
|
||||||
|
|
|
@ -11,12 +11,11 @@ float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) {
|
||||||
float mag1 = a.magnitude();
|
float mag1 = a.magnitude();
|
||||||
float mag2 = b.magnitude();
|
float mag2 = b.magnitude();
|
||||||
|
|
||||||
if (!mag1 || !mag2)
|
if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON)
|
||||||
return 0.f;
|
return 0.f;
|
||||||
|
|
||||||
float dot = a.dot(b);
|
float dot = a.dot(b);
|
||||||
float theta = std::acos(dot / (mag1 * mag2));
|
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
|
||||||
return theta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {
|
CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {
|
||||||
|
|
Loading…
Reference in New Issue