Radium Engine  1.5.0
PointLight.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 #include <Engine/Scene/Light.hpp>
5 
6 namespace Ra {
7 namespace Engine {
8 
9 namespace Scene {
10 class Entity;
14 class RA_ENGINE_API PointLight final : public Ra::Engine::Scene::Light
15 {
16  public:
17  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
18 
19  explicit PointLight( Entity* entity, const std::string& name = "pointlight" );
20  ~PointLight() override = default;
21 
22  void setPosition( const Eigen::Matrix<Scalar, 3, 1>& pos ) override;
23  inline const Eigen::Matrix<Scalar, 3, 1>& getPosition() const;
24 
25  inline void setAttenuation( const Attenuation& attenuation );
26  inline void setAttenuation( Scalar constant, Scalar linear, Scalar quadratic );
27  inline const Attenuation& getAttenuation() const;
28 
29  std::string getShaderInclude() const override;
30 
31  private:
32  Eigen::Matrix<Scalar, 3, 1> m_position { 0, 0, 0 };
33 
34  Attenuation m_attenuation { 1, 0, 0 };
35 };
36 
37 // ---------------------------------------------------------------------------------------------
38 // ---- inline methods implementation
39 
40 inline void PointLight::setPosition( const Eigen::Matrix<Scalar, 3, 1>& pos ) {
41  m_position = pos;
42  getRenderParameters().addParameter( "light.point.position", m_position );
43 }
44 
45 inline const Eigen::Matrix<Scalar, 3, 1>& PointLight::getPosition() const {
46  return m_position;
47 }
48 
49 inline void PointLight::setAttenuation( const PointLight::Attenuation& attenuation ) {
50  m_attenuation = attenuation;
51  getRenderParameters().addParameter( "light.point.attenuation.constant",
52  m_attenuation.constant );
53  getRenderParameters().addParameter( "light.point.attenuation.linear", m_attenuation.linear );
54  getRenderParameters().addParameter( "light.point.attenuation.quadratic",
55  m_attenuation.quadratic );
56 }
57 
58 inline void PointLight::setAttenuation( Scalar constant, Scalar linear, Scalar quadratic ) {
59  setAttenuation( { constant, linear, quadratic } );
60 }
61 
62 inline const PointLight::Attenuation& PointLight::getAttenuation() const {
63  return m_attenuation;
64 }
65 } // namespace Scene
66 } // namespace Engine
67 } // namespace Ra
void addParameter(const std::string &name, T value, typename std::enable_if<!std::is_class< T > {}, bool >::type=true)
Add a parameter by value.
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:95
void setPosition(const Eigen::Matrix< Scalar, 3, 1 > &pos) override
Definition: PointLight.hpp:40
Definition: Cage.cpp:3