lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::scene::Light Class Reference

Class representing a light source in a 3D scene. More...

#include <light.hpp>

Public Member Functions

 Light (LightType type=LightType::Point)
 Constructs a Light object with the specified type.
 
virtual ~Light ()=default
 Virtual destructor for the Light class.
 
LightType get_type () const
 Gets the type of the light.
 
const glm::vec3 & get_color () const
 Sets the type of the light.
 
void set_color (const glm::vec3 &color)
 Sets the color of the light.
 
float get_intensity () const
 Gets the intensity of the light.
 
void set_intensity (float intensity)
 Sets the intensity of the light.
 
const glm::vec3 & get_direction () const
 Gets the direction of the light.
 
void set_direction (const glm::vec3 &direction)
 Sets the direction of the light.
 
const glm::vec3 & get_position () const
 Gets the position of the light.
 
void set_position (const glm::vec3 &position)
 Sets the position of the light.
 
float get_range () const
 Gets the range of the light.
 
void set_range (float range)
 Sets the range of the light.
 
float get_inner_cone () const
 Gets the inner cone angle of the spotlight.
 
void set_inner_cone (float inner_cone)
 Sets the inner cone angle of the spotlight.
 
float get_outer_cone () const
 Gets the outer cone angle of the spotlight.
 
void set_outer_cone (float outer_cone)
 Sets the outer cone angle of the spotlight.
 
bool casts_shadows () const
 Checks if the light casts shadows.
 
void set_casts_shadows (bool casts_shadows)
 Sets whether the light casts shadows.
 

Static Public Member Functions

static std::shared_ptr< Lightcreate_directional (const glm::vec3 &direction, const glm::vec3 &color=glm::vec3(1.0f))
 Creates a directional light.
 
static std::shared_ptr< Lightcreate_point (const glm::vec3 &position, float range=10.0f, const glm::vec3 &color=glm::vec3(1.0f))
 Creates a point light.
 
static std::shared_ptr< Lightcreate_spot (const glm::vec3 &position, const glm::vec3 &direction, float angle=45.0f, const glm::vec3 &color=glm::vec3(1.0f))
 Creates a spotlight.
 

Protected Attributes

LightType m_type
 The type of the light.
 
glm::vec3 m_color {1.0f, 1.0f, 1.0f}
 The color of the light.
 
float m_intensity {1.0f}
 The intensity of the light.
 
glm::vec3 m_direction {0.0f, -1.0f, 0.0f}
 The direction of the light.
 
glm::vec3 m_position {0.0f, 0.0f, 0.0f}
 The position of the light.
 
float m_range {10.0f}
 The range of the light.
 
float m_inner_cone {glm::radians(30.0f)}
 The inner cone angle of the spotlight in radians.
 
float m_outer_cone {glm::radians(45.0f)}
 The outer cone angle of the spotlight in radians.
 
bool m_casts_shadows {false}
 Flag indicating whether the light casts shadows.
 

Detailed Description

Class representing a light source in a 3D scene.

The Light class encapsulates properties and behaviors of a light source, including its type, color, intensity, and position/direction.

Constructor & Destructor Documentation

◆ Light()

lmgl::scene::Light::Light ( LightType type = LightType::Point)

Constructs a Light object with the specified type.

Parameters
typeThe type of the light (Directional, Point, Spot).

◆ ~Light()

virtual lmgl::scene::Light::~Light ( )
virtualdefault

Virtual destructor for the Light class.

Cleans up resources used by the Light object.

Member Function Documentation

◆ casts_shadows()

bool lmgl::scene::Light::casts_shadows ( ) const
inline

Checks if the light casts shadows.

Returns
True if the light casts shadows, false otherwise.

◆ create_directional()

std::shared_ptr< Light > lmgl::scene::Light::create_directional ( const glm::vec3 & direction,
const glm::vec3 & color = glm::vec3(1.0f) )
static

Creates a directional light.

Parameters
directionThe direction of the light as a glm::vec3.
colorThe color of the light as a glm::vec3 (default is white).
Returns
A shared pointer to the created Light object.

◆ create_point()

std::shared_ptr< Light > lmgl::scene::Light::create_point ( const glm::vec3 & position,
float range = 10.0f,
const glm::vec3 & color = glm::vec3(1.0f) )
static

Creates a point light.

Parameters
positionThe position of the light as a glm::vec3.
rangeThe range of the light as a float (default is 10.0f).
colorThe color of the light as a glm::vec3 (default is white).
Returns
A shared pointer to the created Light object.

◆ create_spot()

std::shared_ptr< Light > lmgl::scene::Light::create_spot ( const glm::vec3 & position,
const glm::vec3 & direction,
float angle = 45.0f,
const glm::vec3 & color = glm::vec3(1.0f) )
static

Creates a spotlight.

Parameters
positionThe position of the light as a glm::vec3.
directionThe direction of the light as a glm::vec3.
rangeThe range of the light as a float (default is 10.0f).
colorThe color of the light as a glm::vec3 (default is white).
Returns
A shared pointer to the created Light object.

◆ get_color()

const glm::vec3 & lmgl::scene::Light::get_color ( ) const
inline

Sets the type of the light.

Parameters
typeThe new LightType for the light.

◆ get_direction()

const glm::vec3 & lmgl::scene::Light::get_direction ( ) const
inline

Gets the direction of the light.

Returns
The direction of the light as a glm::vec3.

◆ get_inner_cone()

float lmgl::scene::Light::get_inner_cone ( ) const
inline

Gets the inner cone angle of the spotlight.

Returns
The inner cone angle in radians as a float.

◆ get_intensity()

float lmgl::scene::Light::get_intensity ( ) const
inline

Gets the intensity of the light.

Returns
The intensity of the light as a float.

◆ get_outer_cone()

float lmgl::scene::Light::get_outer_cone ( ) const
inline

Gets the outer cone angle of the spotlight.

Returns
The outer cone angle in radians as a float.

◆ get_position()

const glm::vec3 & lmgl::scene::Light::get_position ( ) const
inline

Gets the position of the light.

Returns
The position of the light as a glm::vec3.

◆ get_range()

float lmgl::scene::Light::get_range ( ) const
inline

Gets the range of the light.

Returns
The range of the light as a float.

◆ get_type()

LightType lmgl::scene::Light::get_type ( ) const
inline

Gets the type of the light.

Returns
The LightType of the light.

◆ set_casts_shadows()

void lmgl::scene::Light::set_casts_shadows ( bool casts_shadows)
inline

Sets whether the light casts shadows.

Parameters
casts_shadowsTrue to enable shadow casting, false to disable.

◆ set_color()

void lmgl::scene::Light::set_color ( const glm::vec3 & color)
inline

Sets the color of the light.

Parameters
colorThe new color for the light as a glm::vec3.

◆ set_direction()

void lmgl::scene::Light::set_direction ( const glm::vec3 & direction)
inline

Sets the direction of the light.

Parameters
directionThe new direction for the light as a glm::vec3.

◆ set_inner_cone()

void lmgl::scene::Light::set_inner_cone ( float inner_cone)
inline

Sets the inner cone angle of the spotlight.

Parameters
inner_coneThe new inner cone angle in radians as a float.

◆ set_intensity()

void lmgl::scene::Light::set_intensity ( float intensity)
inline

Sets the intensity of the light.

Parameters
intensityThe new intensity for the light as a float.

◆ set_outer_cone()

void lmgl::scene::Light::set_outer_cone ( float outer_cone)
inline

Sets the outer cone angle of the spotlight.

Parameters
outer_coneThe new outer cone angle in radians as a float.

◆ set_position()

void lmgl::scene::Light::set_position ( const glm::vec3 & position)
inline

Sets the position of the light.

Parameters
positionThe new position for the light as a glm::vec3.

◆ set_range()

void lmgl::scene::Light::set_range ( float range)
inline

Sets the range of the light.

Parameters
rangeThe new range for the light as a float.

The documentation for this class was generated from the following files: