From d688e5f915187b33a55f30f5f30678d48b076d51 Mon Sep 17 00:00:00 2001 From: bwent Date: Tue, 21 Jul 2015 10:50:56 -0700 Subject: [PATCH] fix case where v not normalizable --- libraries/script-engine/src/Vec3.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 71b04eb321..17e7c56276 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -76,7 +76,12 @@ bool Vec3::equal(const glm::vec3& v1, const glm::vec3& v2) { } glm::vec3 Vec3::toPolar(const glm::vec3& v) { - glm::vec3 u = normalize(v); + float radius = length(v); + if (glm::abs(radius) < EPSILON) { + return glm::vec3(0.0f, 0.0f, 0.0f); + } + glm::vec3 u = v / radius; + float azimuth, elevation; azimuth = glm::asin(-u.y); @@ -109,7 +114,7 @@ glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { z = 0.0f; } - return multiply(polar.z, glm::vec3(x, y, z)); + return polar.z * glm::vec3(x, y, z); } glm::vec3 Vec3::fromPolar(float azimuth, float elevation) {