zeus/src/CVector3f.cpp

26 lines
653 B
C++
Raw Permalink Normal View History

2016-03-04 15:03:26 -08:00
#include "zeus/CVector3f.hpp"
#include <algorithm>
2017-12-29 00:06:22 -08:00
#include <cassert>
#include <cfloat>
#include <cmath>
#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);
return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f));
2015-04-19 13:39:16 -07: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