lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
light.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <glm/glm.hpp>
15
16#include <memory>
17
18namespace lmgl {
19
20namespace scene {
21
28enum class LightType {
32};
33
40class Light {
41 public:
48
54 virtual ~Light() = default;
55
61 inline LightType get_type() const { return m_type; }
62
68 inline const glm::vec3 &get_color() const { return m_color; }
69
75 inline void set_color(const glm::vec3 &color) { m_color = color; }
76
82 inline float get_intensity() const { return m_intensity; }
83
89 inline void set_intensity(float intensity) { m_intensity = intensity; }
90
96 inline const glm::vec3 &get_direction() const { return m_direction; }
97
103 inline void set_direction(const glm::vec3 &direction) { m_direction = glm::normalize(direction); }
104
110 inline const glm::vec3 &get_position() const { return m_position; }
111
117 inline void set_position(const glm::vec3 &position) { m_position = position; }
118
124 inline float get_range() const { return m_range; }
125
131 inline void set_range(float range) { m_range = range; }
132
138 inline float get_inner_cone() const { return m_inner_cone; }
139
145 inline void set_inner_cone(float inner_cone) { m_inner_cone = inner_cone; }
146
152 inline float get_outer_cone() const { return m_outer_cone; }
153
159 inline void set_outer_cone(float outer_cone) { m_outer_cone = outer_cone; }
160
166 inline bool casts_shadows() const { return m_casts_shadows; }
167
174
175 // Factory methods
176
183 static std::shared_ptr<Light> create_directional(const glm::vec3 &direction,
184 const glm::vec3 &color = glm::vec3(1.0f));
185
193 static std::shared_ptr<Light> create_point(const glm::vec3 &position, float range = 10.0f,
194 const glm::vec3 &color = glm::vec3(1.0f));
195
204 static std::shared_ptr<Light> create_spot(const glm::vec3 &position, const glm::vec3 &direction,
205 float angle = 45.0f, const glm::vec3 &color = glm::vec3(1.0f));
206
207 protected:
210
212 glm::vec3 m_color{1.0f, 1.0f, 1.0f};
213
215 float m_intensity{1.0f};
216
218 glm::vec3 m_direction{0.0f, -1.0f, 0.0f};
219
221 glm::vec3 m_position{0.0f, 0.0f, 0.0f};
222
224 float m_range{10.0f};
225
227 float m_inner_cone{glm::radians(30.0f)};
228
230 float m_outer_cone{glm::radians(45.0f)};
231
233 bool m_casts_shadows{false};
234};
235
236} // namespace scene
237
238} // namespace lmgl
void set_intensity(float intensity)
Sets the intensity of the light.
Definition light.hpp:89
float get_intensity() const
Gets the intensity of the light.
Definition light.hpp:82
static std::shared_ptr< Light > create_spot(const glm::vec3 &position, const glm::vec3 &direction, float angle=45.0f, const glm::vec3 &color=glm::vec3(1.0f))
Creates a spotlight.
Definition light.cpp:24
void set_position(const glm::vec3 &position)
Sets the position of the light.
Definition light.hpp:117
float get_range() const
Gets the range of the light.
Definition light.hpp:124
void set_inner_cone(float inner_cone)
Sets the inner cone angle of the spotlight.
Definition light.hpp:145
LightType get_type() const
Gets the type of the light.
Definition light.hpp:61
float m_inner_cone
The inner cone angle of the spotlight in radians.
Definition light.hpp:227
float m_intensity
The intensity of the light.
Definition light.hpp:215
virtual ~Light()=default
Virtual destructor for the Light class.
void set_direction(const glm::vec3 &direction)
Sets the direction of the light.
Definition light.hpp:103
const glm::vec3 & get_color() const
Sets the type of the light.
Definition light.hpp:68
Light(LightType type=LightType::Point)
Constructs a Light object with the specified type.
Definition light.cpp:7
glm::vec3 m_color
The color of the light.
Definition light.hpp:212
float get_inner_cone() const
Gets the inner cone angle of the spotlight.
Definition light.hpp:138
void set_range(float range)
Sets the range of the light.
Definition light.hpp:131
void set_outer_cone(float outer_cone)
Sets the outer cone angle of the spotlight.
Definition light.hpp:159
static std::shared_ptr< Light > create_point(const glm::vec3 &position, float range=10.0f, const glm::vec3 &color=glm::vec3(1.0f))
Creates a point light.
Definition light.cpp:16
LightType m_type
The type of the light.
Definition light.hpp:209
glm::vec3 m_direction
The direction of the light.
Definition light.hpp:218
float m_range
The range of the light.
Definition light.hpp:224
glm::vec3 m_position
The position of the light.
Definition light.hpp:221
const glm::vec3 & get_direction() const
Gets the direction of the light.
Definition light.hpp:96
const glm::vec3 & get_position() const
Gets the position of the light.
Definition light.hpp:110
bool casts_shadows() const
Checks if the light casts shadows.
Definition light.hpp:166
void set_casts_shadows(bool casts_shadows)
Sets whether the light casts shadows.
Definition light.hpp:173
static std::shared_ptr< Light > create_directional(const glm::vec3 &direction, const glm::vec3 &color=glm::vec3(1.0f))
Creates a directional light.
Definition light.cpp:9
float m_outer_cone
The outer cone angle of the spotlight in radians.
Definition light.hpp:230
void set_color(const glm::vec3 &color)
Sets the color of the light.
Definition light.hpp:75
bool m_casts_shadows
Flag indicating whether the light casts shadows.
Definition light.hpp:233
float get_outer_cone() const
Gets the outer cone angle of the spotlight.
Definition light.hpp:152
Namespace for scene-related classes and functions.
Definition camera.cpp:7
LightType
Enumeration of different light types.
Definition light.hpp:28
@ Point
Point light source.
Definition light.hpp:30
@ Spot
Spotlight source.
Definition light.hpp:31
@ Directional
Directional light source.
Definition light.hpp:29
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12