diff --git a/include/zeus/CSphere.hpp b/include/zeus/CSphere.hpp index fac6f28..43d9593 100644 --- a/include/zeus/CSphere.hpp +++ b/include/zeus/CSphere.hpp @@ -12,7 +12,7 @@ public: CSphere(const CVector3f& position, float radius) : position(position), radius(radius) {} - inline CVector3f getSurfaceNormal(const CVector3f& coord) const { return (position - coord).normalized(); } + inline CVector3f getSurfaceNormal(const CVector3f& coord) const { return (coord - position).normalized(); } inline bool intersects(const CSphere& other) { diff --git a/src/CQuaternion.cpp b/src/CQuaternion.cpp index 19747f2..5663817 100644 --- a/src/CQuaternion.cpp +++ b/src/CQuaternion.cpp @@ -309,8 +309,8 @@ CQuaternion CQuaternion::shortestRotationArc(const zeus::CVector3f& v0, const ze } else { - float w = (1.f + zeus::clamp(-1.f, v0N.dot(v1N), 1.f)) * 2.f; - return CQuaternion(0.5f * w, cross * (1.f / std::sqrt(w))); + float w = std::sqrt((1.f + zeus::clamp(-1.f, v0N.dot(v1N), 1.f)) * 2.f); + return CQuaternion(0.5f * w, cross * (1.f / w)); } } diff --git a/src/Math.cpp b/src/Math.cpp index 7baa235..c4410d8 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -180,11 +180,12 @@ CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3 return CTransform(rmBasis, pos); } -CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t) +CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, + const CVector3f& c, const CVector3f& d, float t) { - const float oneMinusTime = (1.0 - t); - return (a * oneMinusTime * oneMinusTime) + (b * 3.f * t * oneMinusTime) + (c * 3.f * t * t * oneMinusTime) + - (d * t * t * t); + const float omt = 1.f - t; + return ((a * omt + b * t) * omt + (b * omt + c * t) * t) * omt + + ((b * omt + c * t) * omt + (c * omt + d * t) * t) * t; } int floorPowerOfTwo(int x)