Radium Engine  1.5.20
Loading...
Searching...
No Matches
SpotLight.hpp
1#pragma once
2
3#include <Core/Math/Math.hpp>
4#include <Engine/RaEngine.hpp>
5#include <Engine/Scene/Light.hpp>
6
7namespace Ra {
8namespace Engine {
9
10namespace Scene {
11class Entity;
15class RA_ENGINE_API SpotLight final : public Ra::Engine::Scene::Light
16{
17
18 public:
19 explicit SpotLight( Entity* entity, const std::string& name = "spotlight" );
20 ~SpotLight() override = default;
21
22 void setPosition( const Eigen::Matrix<Scalar, 3, 1>& position ) override;
23 inline const Eigen::Matrix<Scalar, 3, 1>& getPosition() const;
24
25 void setDirection( const Eigen::Matrix<Scalar, 3, 1>& direction ) override;
26 inline const Eigen::Matrix<Scalar, 3, 1>& getDirection() const;
27
28 inline void setInnerAngleInRadians( Scalar angle );
29 inline void setOuterAngleInRadians( Scalar angle );
30 inline void setInnerAngleInDegrees( Scalar angle );
31 inline void setOuterAngleInDegrees( Scalar angle );
32
33 inline Scalar getInnerAngle() const;
34 inline Scalar getOuterAngle() const;
35
36 inline void setAttenuation( const Attenuation& attenuation );
37 inline void setAttenuation( Scalar constant, Scalar linear, Scalar quadratic );
38 inline const Attenuation& getAttenuation() const;
39
40 std::string getShaderInclude() const override;
41
42 private:
43 Eigen::Matrix<Scalar, 3, 1> m_position { 0, 0, 0 };
44 Eigen::Matrix<Scalar, 3, 1> m_direction { 0, -1, 0 };
45
46 Scalar m_innerAngle { Core::Math::PiDiv4 };
47 Scalar m_outerAngle { Core::Math::PiDiv2 };
48
49 Attenuation m_attenuation { 1, 0, 0 };
50};
51
52// ---------------------------------------------------------------------------------------------
53// ---- inline methods implementation
54
55inline void SpotLight::setPosition( const Eigen::Matrix<Scalar, 3, 1>& position ) {
56 m_position = position;
57 getRenderParameters().setVariable( "light.spot.position", m_position );
58}
59
60inline const Eigen::Matrix<Scalar, 3, 1>& Scene::SpotLight::getPosition() const {
61 return m_position;
62}
63
64inline void SpotLight::setDirection( const Eigen::Matrix<Scalar, 3, 1>& direction ) {
65 m_direction = direction.normalized();
66 getRenderParameters().setVariable( "light.spot.direction", m_direction );
67}
68
69inline const Eigen::Matrix<Scalar, 3, 1>& SpotLight::getDirection() const {
70 return m_direction;
71}
72
73inline void SpotLight::setInnerAngleInRadians( Scalar angle ) {
74 m_innerAngle = angle;
75 getRenderParameters().setVariable( "light.spot.innerAngle", m_innerAngle );
76}
77
78inline void SpotLight::setOuterAngleInRadians( Scalar angle ) {
79 m_outerAngle = angle;
80 getRenderParameters().setVariable( "light.spot.outerAngle", m_outerAngle );
81}
82
83inline void SpotLight::setInnerAngleInDegrees( Scalar angle ) {
84 m_innerAngle = angle * Core::Math::toRad;
85}
86
87inline void SpotLight::setOuterAngleInDegrees( Scalar angle ) {
88 m_outerAngle = Core::Math::toRad * angle;
89}
90
91inline Scalar SpotLight::getInnerAngle() const {
92 return m_innerAngle;
93}
94
95inline Scalar SpotLight::getOuterAngle() const {
96 return m_outerAngle;
97}
98
99inline void SpotLight::setAttenuation( const Attenuation& attenuation ) {
100 m_attenuation = attenuation;
101 getRenderParameters().setVariable( "light.spot.attenuation.constant", m_attenuation.constant );
102 getRenderParameters().setVariable( "light.spot.attenuation.linear", m_attenuation.linear );
103 getRenderParameters().setVariable( "light.spot.attenuation.quadratic",
104 m_attenuation.quadratic );
105}
106
107inline void SpotLight::setAttenuation( Scalar constant, Scalar linear, Scalar quadratic ) {
108 setAttenuation( { constant, linear, quadratic } );
109}
110
111inline const SpotLight::Attenuation& SpotLight::getAttenuation() const {
112 return m_attenuation;
113}
114
115} // namespace Scene
116} // namespace Engine
117} // namespace Ra
void setVariable(const std::string &name, RenderParameters &rp)
overload create ref wrapper for RenderParameters variable
An entity is an scene element. It ties together components with a transform.
Definition Entity.hpp:23
const Data::RenderParameters & getRenderParameters() const
Gives read-only access to the renderParameters of the light.
Definition Light.hpp:93
void setDirection(const Eigen::Matrix< Scalar, 3, 1 > &direction) override
Definition SpotLight.hpp:64
void setPosition(const Eigen::Matrix< Scalar, 3, 1 > &position) override
Definition SpotLight.hpp:55
Scalar angle(const Vector_ &v1, const Vector_ &v2)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3