2013-12-08 16:56:59 +00:00
|
|
|
#include "LightStatus.h"
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "LightingManager.h"
|
2015-09-29 20:31:25 +00:00
|
|
|
#include "LightComponent.h"
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "Color.h"
|
|
|
|
#include "SurfaceMaterial.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
LightStatus::LightStatus(LightingManager *manager, const Vector3 &location, const Vector3 &eye, bool filtered) {
|
2015-10-15 22:14:54 +00:00
|
|
|
this->safety_offset = -0.0000001;
|
2013-12-26 18:03:19 +00:00
|
|
|
this->max_power = 0.0;
|
2013-12-08 16:56:59 +00:00
|
|
|
this->manager = manager;
|
|
|
|
this->location = location;
|
|
|
|
this->eye = eye;
|
2015-09-29 20:31:25 +00:00
|
|
|
this->filtered = filtered;
|
2013-12-08 16:56:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void LightStatus::pushComponent(LightComponent component) {
|
|
|
|
if (filtered) {
|
2015-09-29 20:31:25 +00:00
|
|
|
double power = component.color.getPower();
|
2015-11-09 21:30:46 +00:00
|
|
|
if (component.altered && (power < max_power * 0.05 || power < 0.001)) {
|
2015-09-29 20:31:25 +00:00
|
|
|
// Exclude filtered lights that are owerpowered by a previous one
|
|
|
|
return;
|
|
|
|
}
|
2013-12-26 18:03:19 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (manager->alterLight(component, location.add(component.direction.scale(safety_offset)))) {
|
|
|
|
if (power > max_power) {
|
2015-09-29 20:31:25 +00:00
|
|
|
max_power = power;
|
|
|
|
}
|
|
|
|
components.push_back(component);
|
2013-12-26 18:03:19 +00:00
|
|
|
}
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2013-12-08 19:54:34 +00:00
|
|
|
components.push_back(component);
|
2013-12-08 16:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
Color LightStatus::apply(const Vector3 &normal, const SurfaceMaterial &material) {
|
2013-12-20 16:30:27 +00:00
|
|
|
Color final(0.0, 0.0, 0.0, 0.0);
|
2013-12-08 16:56:59 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
for (auto component : components) {
|
2013-12-08 19:54:34 +00:00
|
|
|
final = final.add(manager->applyFinalComponent(component, eye, location, normal, material));
|
2013-12-08 16:56:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 17:14:59 +00:00
|
|
|
final.a = material.base->a;
|
2013-12-08 16:56:59 +00:00
|
|
|
return final;
|
|
|
|
}
|
2015-09-29 20:31:25 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
Color LightStatus::getSum() const {
|
2015-09-29 20:31:25 +00:00
|
|
|
Color final = COLOR_BLACK;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
for (auto component : components) {
|
2015-09-29 20:31:25 +00:00
|
|
|
final = final.add(component.color);
|
|
|
|
}
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
2015-10-15 22:14:54 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void LightStatus::setSafetyOffset(double safety_offset) {
|
2015-10-15 22:14:54 +00:00
|
|
|
this->safety_offset = -safety_offset;
|
|
|
|
}
|