mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 00:40:06 +02:00
Add entity light cutoff/dimensions constraints
This commit is contained in:
parent
01dc1b058c
commit
5fd960fb43
2 changed files with 39 additions and 4 deletions
|
@ -41,8 +41,16 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityI
|
|||
}
|
||||
|
||||
void LightEntityItem::setDimensions(const glm::vec3& value) {
|
||||
float maxDimension = glm::max(value.x, value.y, value.z);
|
||||
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
|
||||
if (_isSpotlight) {
|
||||
// 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));
|
||||
_dimensions = glm::vec3(width, width, length);
|
||||
} else {
|
||||
float maxDimension = glm::max(value.x, value.y, value.z);
|
||||
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,6 +66,33 @@ EntityItemProperties LightEntityItem::getProperties() const {
|
|||
return properties;
|
||||
}
|
||||
|
||||
void LightEntityItem::setIsSpotlight(bool value) {
|
||||
if (value != _isSpotlight) {
|
||||
_isSpotlight = value;
|
||||
|
||||
if (_isSpotlight) {
|
||||
const float length = _dimensions.z;
|
||||
const float width = length * glm::tan(glm::radians(_cutoff));
|
||||
_dimensions = glm::vec3(width, width, length);
|
||||
} else {
|
||||
float maxDimension = glm::max(_dimensions.x, _dimensions.y, _dimensions.z);
|
||||
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LightEntityItem::setCutoff(float value) {
|
||||
_cutoff = glm::clamp(value, 0.0f, 90.0f);
|
||||
|
||||
if (_isSpotlight) {
|
||||
// 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));
|
||||
_dimensions = glm::vec3(width, width, length);
|
||||
}
|
||||
}
|
||||
|
||||
bool LightEntityItem::setProperties(const EntityItemProperties& properties) {
|
||||
bool somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
}
|
||||
|
||||
bool getIsSpotlight() const { return _isSpotlight; }
|
||||
void setIsSpotlight(bool value) { _isSpotlight = value; }
|
||||
void setIsSpotlight(bool value);
|
||||
|
||||
float getIntensity() const { return _intensity; }
|
||||
void setIntensity(float value) { _intensity = value; }
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
void setExponent(float value) { _exponent = value; }
|
||||
|
||||
float getCutoff() const { return _cutoff; }
|
||||
void setCutoff(float value) { _cutoff = value; }
|
||||
void setCutoff(float value);
|
||||
|
||||
static bool getLightsArePickable() { return _lightsArePickable; }
|
||||
static void setLightsArePickable(bool value) { _lightsArePickable = value; }
|
||||
|
|
Loading…
Reference in a new issue