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
This commit is contained in:
Ryan Huffman 2015-05-20 09:11:48 -07:00
parent bb38b3eb3f
commit 6f69ed2561
2 changed files with 4 additions and 4 deletions

View file

@ -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,

View file

@ -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);
}
}