diff --git a/include/Nazara/Graphics/Light.hpp b/include/Nazara/Graphics/Light.hpp index b478e62e1..c14cdd075 100644 --- a/include/Nazara/Graphics/Light.hpp +++ b/include/Nazara/Graphics/Light.hpp @@ -34,8 +34,12 @@ class NAZARA_API NzLight : public NzRenderable NzColor GetColor() const; float GetDiffuseFactor() const; float GetInnerAngle() const; + float GetInnerAngleCosine() const; + float GetInvRadius() const; nzLightType GetLightType() const; float GetOuterAngle() const; + float GetOuterAngleCosine() const; + float GetOuterAngleTangent() const; float GetRadius() const; void SetAmbientFactor(float factor); @@ -60,7 +64,11 @@ class NAZARA_API NzLight : public NzRenderable float m_attenuation; float m_diffuseFactor; float m_innerAngle; + float m_innerAngleCosine; + float m_invRadius; float m_outerAngle; + float m_outerAngleCosine; + float m_outerAngleTangent; float m_radius; }; @@ -85,4 +93,6 @@ struct NzLightUniforms }; }; +#include + #endif // NAZARA_LIGHT_HPP diff --git a/include/Nazara/Graphics/Light.inl b/include/Nazara/Graphics/Light.inl new file mode 100644 index 000000000..a46a8e5c0 --- /dev/null +++ b/include/Nazara/Graphics/Light.inl @@ -0,0 +1,92 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Graphics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +inline float NzLight::GetAmbientFactor() const +{ + return m_ambientFactor; +} + +inline float NzLight::GetAttenuation() const +{ + return m_attenuation; +} + +inline NzColor NzLight::GetColor() const +{ + return m_color; +} + +inline float NzLight::GetDiffuseFactor() const +{ + return m_diffuseFactor; +} + +inline float NzLight::GetInnerAngle() const +{ + return m_innerAngle; +} + +inline nzLightType NzLight::GetLightType() const +{ + return m_type; +} + +inline float NzLight::GetOuterAngle() const +{ + return m_outerAngle; +} + +inline float NzLight::GetRadius() const +{ + return m_radius; +} + +inline void NzLight::SetAmbientFactor(float factor) +{ + m_ambientFactor = factor; +} + +inline void NzLight::SetAttenuation(float attenuation) +{ + m_attenuation = attenuation; +} + +inline void NzLight::SetColor(const NzColor& color) +{ + m_color = color; +} + +inline void NzLight::SetDiffuseFactor(float factor) +{ + m_diffuseFactor = factor; +} + +inline void NzLight::SetInnerAngle(float innerAngle) +{ + m_innerAngle = innerAngle; + m_innerAngleCosine = std::cos(NzDegreeToRadian(m_innerAngle)); +} + +inline void NzLight::SetLightType(nzLightType type) +{ + m_type = type; +} + +inline void NzLight::SetOuterAngle(float outerAngle) +{ + m_outerAngle = outerAngle; + m_outerAngleCosine = std::cos(NzDegreeToRadian(m_outerAngle)); + m_outerAngleTangent = std::tan(NzDegreeToRadian(m_outerAngle)); + + InvalidateBoundingVolume(); +} + +inline void NzLight::SetRadius(float radius) +{ + m_radius = radius; + + m_invRadius = 1.f / m_radius; + + InvalidateBoundingVolume(); +} diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp index ce1b5f2bb..db3f5bd58 100644 --- a/src/Nazara/Graphics/Light.cpp +++ b/src/Nazara/Graphics/Light.cpp @@ -17,15 +17,15 @@ ///TODO: Scale ? NzLight::NzLight(nzLightType type) : -m_type(type), -m_color(NzColor::White), -m_ambientFactor((type == nzLightType_Directional) ? 0.2f : 0.f), -m_attenuation(0.9f), -m_diffuseFactor(1.f), -m_innerAngle(15.f), -m_outerAngle(45.f), -m_radius(5.f) +m_type(type) { + SetAmbientFactor((type == nzLightType_Directional) ? 0.2f : 0.f); + SetAttenuation(0.9f); + SetColor(NzColor::White); + SetDiffuseFactor(1.f); + SetInnerAngle(15.f); + SetOuterAngle(45.f); + SetRadius(5.f); } void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const @@ -77,90 +77,6 @@ bool NzLight::Cull(const NzFrustumf& frustum, const NzBoundingVolumef& volume, c return false; } -float NzLight::GetAmbientFactor() const -{ - return m_ambientFactor; -} - -float NzLight::GetAttenuation() const -{ - return m_attenuation; -} - -NzColor NzLight::GetColor() const -{ - return m_color; -} - -float NzLight::GetDiffuseFactor() const -{ - return m_diffuseFactor; -} - -float NzLight::GetInnerAngle() const -{ - return m_innerAngle; -} - -nzLightType NzLight::GetLightType() const -{ - return m_type; -} - -float NzLight::GetOuterAngle() const -{ - return m_outerAngle; -} - -float NzLight::GetRadius() const -{ - return m_radius; -} - -void NzLight::SetAmbientFactor(float factor) -{ - m_ambientFactor = factor; -} - -void NzLight::SetAttenuation(float attenuation) -{ - m_attenuation = attenuation; -} - -void NzLight::SetColor(const NzColor& color) -{ - m_color = color; -} - -void NzLight::SetDiffuseFactor(float factor) -{ - m_diffuseFactor = factor; -} - -void NzLight::SetInnerAngle(float innerAngle) -{ - m_innerAngle = innerAngle; -} - -void NzLight::SetLightType(nzLightType type) -{ - m_type = type; -} - -void NzLight::SetOuterAngle(float outerAngle) -{ - m_outerAngle = outerAngle; - - InvalidateBoundingVolume(); -} - -void NzLight::SetRadius(float radius) -{ - m_radius = radius; - - InvalidateBoundingVolume(); -} - void NzLight::UpdateBoundingVolume(NzBoundingVolumef* boundingVolume, const NzMatrix4f& transformMatrix) const { NazaraAssert(boundingVolume, "Invalid bounding volume"); @@ -209,7 +125,7 @@ void NzLight::MakeBoundingVolume() const // Il nous faut maintenant le rayon du cercle projeté à cette distance // Tangente = Opposé/Adjaçent <=> Opposé = Adjaçent*Tangente - float radius = m_radius*std::tan(NzDegreeToRadian(m_outerAngle)); + float radius = m_radius * m_outerAngleTangent; NzVector3f lExtend = NzVector3f::Left()*radius; NzVector3f uExtend = NzVector3f::Up()*radius;