From bb38b3eb3f8094b6e200c27ee7f7862971d835e3 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 20 May 2015 09:11:21 -0700 Subject: [PATCH 1/2] Update default light cutoff to PI / 2 --- libraries/entities/src/EntityItemProperties.cpp | 2 +- libraries/entities/src/EntityItemPropertiesDefaults.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index fd3d0e9361..61b25fd7de 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -64,7 +64,7 @@ EntityItemProperties::EntityItemProperties() : CONSTRUCT_PROPERTY(isSpotlight, false), CONSTRUCT_PROPERTY(intensity, 1.0f), CONSTRUCT_PROPERTY(exponent, 0.0f), - CONSTRUCT_PROPERTY(cutoff, PI), + CONSTRUCT_PROPERTY(cutoff, ENTITY_ITEM_DEFAULT_CUTOFF), CONSTRUCT_PROPERTY(locked, ENTITY_ITEM_DEFAULT_LOCKED), CONSTRUCT_PROPERTY(textures, ""), CONSTRUCT_PROPERTY(animationSettings, ""), diff --git a/libraries/entities/src/EntityItemPropertiesDefaults.h b/libraries/entities/src/EntityItemPropertiesDefaults.h index b33e6de1ac..c3dea91daa 100644 --- a/libraries/entities/src/EntityItemPropertiesDefaults.h +++ b/libraries/entities/src/EntityItemPropertiesDefaults.h @@ -64,6 +64,8 @@ const float ENTITY_ITEM_DEFAULT_FRICTION = 0.5f; const bool ENTITY_ITEM_DEFAULT_IGNORE_FOR_COLLISIONS = false; const bool ENTITY_ITEM_DEFAULT_COLLISIONS_WILL_MOVE = false; +const float ENTITY_ITEM_DEFAULT_CUTOFF = PI / 2; + const QString ENTITY_ITEM_DEFAULT_NAME = QString(""); #endif // hifi_EntityItemPropertiesDefaults_h From 6f69ed2561009d3c099d90b680773781f453d245 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 20 May 2015 09:11:48 -0700 Subject: [PATCH 2/2] 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); } }