diff --git a/examples/edit.js b/examples/edit.js index edf60110c4..b33f47c2b7 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1224,7 +1224,8 @@ PropertiesTool = function(opts) { entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation); } if (entity.properties.keyLightDirection !== undefined) { - entity.properties.keyLightDirection = Vec3.toPolar(entity.properties.keyLightDirection); + entity.properties.keyLightDirection = Vec3.multiply(RADIANS_TO_DEGREES, Vec3.toPolar(entity.properties.keyLightDirection)); + entity.properties.keyLightDirection.z = 0.0; } selections.push(entity); } @@ -1254,7 +1255,8 @@ PropertiesTool = function(opts) { data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z); } if (data.properties.keyLightDirection !== undefined) { - data.properties.keyLightDirection = Vec3.fromPolar(data.properties.keyLightDirection.x, data.properties.keyLightDirection.y); + data.properties.keyLightDirection = Vec3.fromPolar( + data.properties.keyLightDirection.x * DEGREES_TO_RADIANS, data.properties.keyLightDirection.y * DEGREES_TO_RADIANS); } Entities.editEntity(selectionManager.selections[0], data.properties); if (data.properties.name != undefined) { diff --git a/libraries/script-engine/src/Vec3.cpp b/libraries/script-engine/src/Vec3.cpp index 26ef298493..4ed16b2ef0 100644 --- a/libraries/script-engine/src/Vec3.cpp +++ b/libraries/script-engine/src/Vec3.cpp @@ -80,22 +80,23 @@ glm::vec3 Vec3::toPolar(const glm::vec3& v) { if (glm::abs(radius) < EPSILON) { return glm::vec3(0.0f, 0.0f, 0.0f); } + glm::vec3 u = v / radius; - float azimuth, elevation; + float elevation, azimuth; - azimuth = glm::asin(-u.y); - elevation = atan2(v.x, v.z); + elevation = glm::asin(-u.y); + azimuth = atan2(v.x, v.z); // Round off small decimal values - if (glm::abs(azimuth) < EPSILON) { - azimuth = 0.0f; - } if (glm::abs(elevation) < EPSILON) { elevation = 0.0f; } + if (glm::abs(azimuth) < EPSILON) { + azimuth = 0.0f; + } - return glm::vec3(azimuth, elevation, radius); + return glm::vec3(elevation, azimuth, radius); } glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { @@ -113,12 +114,12 @@ glm::vec3 Vec3::fromPolar(const glm::vec3& polar) { if (glm::abs(z) < EPSILON) { z = 0.0f; } - + return polar.z * glm::vec3(x, y, z); } -glm::vec3 Vec3::fromPolar(float azimuth, float elevation) { - glm::vec3 v = glm::vec3(azimuth, elevation, 1.0f); +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 2b202b7a2d..82062ca80d 100644 --- a/libraries/script-engine/src/Vec3.h +++ b/libraries/script-engine/src/Vec3.h @@ -42,7 +42,7 @@ public slots: bool equal(const glm::vec3& v1, const glm::vec3& v2); glm::vec3 toPolar(const glm::vec3& v); glm::vec3 fromPolar(const glm::vec3& polar); - glm::vec3 fromPolar(float pitch, float yaw); + glm::vec3 fromPolar(float elevation, float azimuth); };