Radium Engine  1.5.0
Light.hpp
1 #pragma once
2 
3 #include <Core/Utils/Color.hpp>
4 #include <Engine/RaEngine.hpp>
5 #include <Engine/Scene/Component.hpp>
6 
7 #include <Engine/Data/RenderParameters.hpp>
8 
9 namespace Ra {
10 namespace Engine {
11 namespace Scene {
12 
13 class Entity;
14 
15 // Radium-V2 : this class could totally be renamed LightComponent and get a Light struct embedded.
16 // Thoughts are welcome !
20 class RA_ENGINE_API Light : public Component
21 {
22  public:
27  enum LightType : int { DIRECTIONAL = 0, POINT, SPOT, POLYGONAL };
28 
34  struct Attenuation {
35  Scalar constant { 1 };
36  Scalar linear { 0 };
37  Scalar quadratic { 0 };
38  Attenuation() = default;
39  };
40 
41  public:
42  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 
50  Light( Entity* entity, const LightType& type, const std::string& name = "light" );
51  ~Light() override = default;
52 
57  inline const Core::Utils::Color& getColor() const { return m_color; }
62  inline void setColor( const Core::Utils::Color& color );
63 
69  virtual void setDirection( const Eigen::Matrix<Scalar, 3, 1>& /*dir*/ ) {}
75  virtual void setPosition( const Eigen::Matrix<Scalar, 3, 1>& /*pos*/ ) {}
76  // ...
77 
82  inline const LightType& getType() const { return m_type; }
83 
89  void getRenderParameters( Data::RenderParameters& params ) const;
90 
95  const Data::RenderParameters& getRenderParameters() const { return m_params; }
96 
108  virtual std::string getShaderInclude() const;
109 
113  void initialize() override;
114 
115  private:
116  Data::RenderParameters m_params;
117  Core::Utils::Color m_color = Core::Utils::Color::White();
118  LightType m_type { LightType::DIRECTIONAL };
119 };
120 
121 // ---------------------------------------------------------------------------------------------
122 // ---- inline methods implementation
123 
124 inline void Light::setColor( const Core::Utils::Color& color ) {
125  m_color = color;
126  m_params.addParameter( "light.color", m_color );
127 }
128 
129 } // namespace Scene
130 } // namespace Engine
131 } // 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.
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
An entity is an scene element. It ties together components with a transform.
Definition: Entity.hpp:23
Data::RenderParameters & getRenderParameters()
Gives read-write access to the renderParameters of the light.
Definition: Light.hpp:101
void setColor(const Core::Utils::Color &color)
Definition: Light.hpp:124
const Core::Utils::Color & getColor() const
Definition: Light.hpp:57
const Data::RenderParameters & getRenderParameters() const
Gives read-only access to the renderParameters of the light.
Definition: Light.hpp:95
const LightType & getType() const
Definition: Light.hpp:82
virtual void setDirection(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition: Light.hpp:69
virtual void setPosition(const Eigen::Matrix< Scalar, 3, 1 > &)
Definition: Light.hpp:75
Definition: Cage.cpp:3