2016-03-04 15:03:26 -08:00
|
|
|
#include "zeus/CVector3f.hpp"
|
2019-09-01 00:38:45 -07:00
|
|
|
|
|
|
|
#include <algorithm>
|
2017-12-29 00:06:22 -08:00
|
|
|
#include <cassert>
|
2019-09-01 00:38:45 -07:00
|
|
|
#include <cfloat>
|
|
|
|
#include <cmath>
|
|
|
|
|
2018-12-12 23:36:29 -08:00
|
|
|
#include "zeus/CRelAngle.hpp"
|
2015-04-19 13:39:16 -07:00
|
|
|
|
2018-12-07 17:16:50 -08:00
|
|
|
namespace zeus {
|
|
|
|
float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) {
|
|
|
|
float mag1 = a.magnitude();
|
|
|
|
float mag2 = b.magnitude();
|
2015-04-19 13:39:16 -07:00
|
|
|
|
2019-03-10 01:14:23 -08:00
|
|
|
if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON)
|
2018-12-07 17:16:50 -08:00
|
|
|
return 0.f;
|
2015-04-19 13:39:16 -07:00
|
|
|
|
2018-12-07 17:16:50 -08:00
|
|
|
float dot = a.dot(b);
|
2020-04-19 18:01:49 -07:00
|
|
|
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
|
2015-04-19 13:39:16 -07:00
|
|
|
}
|
|
|
|
|
2018-12-12 23:36:29 -08:00
|
|
|
CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {
|
|
|
|
return a * std::cos(clampAngle) + a.cross(b).normalized().cross(a) * std::sin(clampAngle);
|
2015-04-19 13:39:16 -07:00
|
|
|
}
|
2018-12-07 21:23:50 -08:00
|
|
|
} // namespace zeus
|