diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 04e3a4fe05..88d6373b6d 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -58,3 +58,27 @@ glm::vec3 Vec3::toPolar(const glm::vec3& v) { return glm::vec3(elevation, azimuth, radius); } + +glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { + float x = glm::cos(polar.x) * glm::sin(polar.y); + float y = glm::sin(-polar.x); + float z = glm::cos(polar.x) * glm::cos(polar.y); + + // Round small values to 0 + if (glm::abs(x) < EPSILON) { + x = 0.0f; + } + if (glm::abs(y) < EPSILON) { + y = 0.0f; + } + if (glm::abs(z) < EPSILON) { + z = 0.0f; + } + + return polar.z * glm::vec3(x, y, z); +} + +glm::vec3 Vec3::fromPolar(float elevation, float azimuth) { + glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f); + return fromPolar(v); +} diff --git a/libraries/script-engine/src/Vec3.h b/libraries/script-engine/src/Vec3.h index 2d703ac87e..b05e729a49 100644 --- a/libraries/script-engine/src/Vec3.h +++ b/libraries/script-engine/src/Vec3.h @@ -43,8 +43,8 @@ public slots: bool withinEpsilon(const glm::vec3& v1, const glm::vec3& v2, float epsilon); // FIXME misnamed, should be 'spherical' or 'euler' depending on the implementation glm::vec3 toPolar(const glm::vec3& v); - glm::vec3 fromPolar(const glm::vec3& polar) { return fromSpherical(polar); } - glm::vec3 fromPolar(float elevation, float azimuth) { return fromSpherical(elevation, azimuth); } + glm::vec3 fromPolar(const glm::vec3& polar); + glm::vec3 fromPolar(float elevation, float azimuth); const glm::vec3& UNIT_X() { return Vectors::UNIT_X; } const glm::vec3& UNIT_Y() { return Vectors::UNIT_Y; } const glm::vec3& UNIT_Z() { return Vectors::UNIT_Z; } diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 3d705cf99e..7d56157e53 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -225,30 +225,6 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { return glm::angleAxis(angle, axis); } -glm::vec3 fromSpherical(const glm::vec3& spherical) { - float x = glm::cos(spherical.x) * glm::sin(spherical.y); - float y = glm::sin(-spherical.x); - float z = glm::cos(spherical.x) * glm::cos(spherical.y); - - // Round small values to 0 - if (glm::abs(x) < EPSILON) { - x = 0.0f; - } - if (glm::abs(y) < EPSILON) { - y = 0.0f; - } - if (glm::abs(z) < EPSILON) { - z = 0.0f; - } - - return spherical.z * glm::vec3(x, y, z); -} - -glm::vec3 fromSpherical(float elevation, float azimuth) { - glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f); - return fromSpherical(v); -} - bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) { glm::vec3 v1 = p0 - p1, v2 = p2 - p1; // Non-collinear vectors contained in the plane glm::vec3 n = glm::cross(v1, v2); // Plane's normal vector, pointing out of the triangle diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index 0245ca926f..6683088306 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -117,10 +117,6 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2); glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2); -glm::vec3 fromSpherical(const glm::vec3& spherical); - -glm::vec3 fromSpherical(float elevation, float azimuth); - bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2); glm::vec3 extractTranslation(const glm::mat4& matrix);