From 6f69ed2561009d3c099d90b680773781f453d245 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 20 May 2015 09:11:48 -0700 Subject: [PATCH] Fix calculated dimensions of spotlight The spotlights region of effect is the intersection of the spotlight with radius r, and the sphere of radius r --- examples/libraries/entitySelectionTool.js | 2 +- libraries/entities/src/LightEntityItem.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index f3ea18aef3..1790767bec 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1213,7 +1213,7 @@ SelectionDisplay = (function () { rotation: rotation, visible: true, }); - var distance = (properties.dimensions.z / 2) * Math.tan(properties.cutoff * (Math.PI / 180)); + var distance = (properties.dimensions.z / 2) * Math.sin(properties.cutoff * (Math.PI / 180)); Overlays.editOverlay(grabberSpotLightL, { position: EdgeNL, diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a66cb56bd2..fa09c9bd60 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -46,7 +46,7 @@ void LightEntityItem::setDimensions(const glm::vec3& value) { // If we are a spotlight, treat the z value as our radius or length, and // recalculate the x/y dimensions to properly encapsulate the spotlight. const float length = value.z; - const float width = length * glm::tan(glm::radians(_cutoff)); + const float width = length * glm::sin(glm::radians(_cutoff)); _dimensions = glm::vec3(width, width, length); } else { float maxDimension = glm::max(value.x, value.y, value.z); @@ -73,7 +73,7 @@ void LightEntityItem::setIsSpotlight(bool value) { if (_isSpotlight) { const float length = _dimensions.z; - const float width = length * glm::tan(glm::radians(_cutoff)); + const float width = length * glm::sin(glm::radians(_cutoff)); _dimensions = glm::vec3(width, width, length); } else { float maxDimension = glm::max(_dimensions.x, _dimensions.y, _dimensions.z); @@ -89,7 +89,7 @@ void LightEntityItem::setCutoff(float value) { // If we are a spotlight, adjusting the cutoff will affect the area we encapsulate, // so update the dimensions to reflect this. const float length = _dimensions.z; - const float width = length * glm::tan(glm::radians(_cutoff)); + const float width = length * glm::sin(glm::radians(_cutoff)); _dimensions = glm::vec3(width, width, length); } }