Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
jop::LightSource Class Referencefinal

#include <LightSource.hpp>

Inheritance diagram for jop::LightSource:
jop::Component

Public Types

enum  Type { Type::Point, Type::Spot, Type::Directional }
 
enum  Intensity { Intensity::Ambient, Intensity::Diffuse, Intensity::Specular }
 
enum  Attenuation { Attenuation::Constant, Attenuation::Linear, Attenuation::Quadratic }
 

Public Member Functions

 LightSource (Object &object, Renderer &renderer, const Type type)
 Constructor. More...
 
 ~LightSource () override
 Destructor. More...
 
void setRenderMask (const uint32 mask)
 Set the render mask. More...
 
uint32 getRenderMask () const
 Get the render mask. More...
 
Type getType () const
 Get the light type. More...
 
LightSourcesetCastShadows (const bool castShadows, const glm::uvec2 &resolution=glm::uvec2(0))
 Set shadow casting for this light. More...
 
bool castsShadows () const
 Check if this light casts shadows. More...
 
const glm::mat4 & getLightspaceMatrix (const Cubemap::Face face=Cubemap::Face::First) const
 Get a light space matrix. More...
 
const TexturegetShadowMap () const
 Get the shadow map. More...
 
LightSourcesetIntensity (const Intensity intensity, const Color &color)
 Set a specific intensity value. More...
 
LightSourcesetIntensity (const Color &ambient, const Color &diffuse, const Color &specular)
 Set all intensity values. More...
 
LightSourcesetIntensity (const Color &intensity)
 Set all intensity values. More...
 
const ColorgetIntensity (const Intensity intensity) const
 Get an intensity value. More...
 
LightSourcesetAttenuation (const Attenuation attenuation, const float value)
 Set a single attenuation value. More...
 
LightSourcesetAttenuation (const float constant, const float linear, const float quadratic)
 Set the attenuation values. More...
 
LightSourcesetAttenuation (const float range)
 Set the attenuation values using a range. More...
 
float getAttenuation (const Attenuation attenuation) const
 Get an attenuation value. More...
 
glm::vec3 getAttenuation () const
 Get the attenuation values as a vector. More...
 
float getRange () const
 Get the approximate maximum range. More...
 
LightSourcesetCutoff (const float inner, const float outer)
 Set the cutoff. More...
 
const glm::vec2 & getCutoff () const
 Get the cutoff values. More...
 
- Public Member Functions inherited from jop::Component
virtual ~Component ()=0
 Virtual destructor. More...
 
Message::Result sendMessage (const Message &message)
 Send a message to this component. More...
 
virtual void update (const float deltaTime)
 Update function. More...
 
uint32 getID () const
 Get the identifier. More...
 
void setID (const uint32 ID)
 Set the identifier. More...
 
WeakReference< ObjectgetObject ()
 Get the object this component is bound to. More...
 
WeakReference< const ObjectgetObject () const
 Get the object this component is bound to. More...
 
bool isActive () const
 Check if this component is active. More...
 
void removeSelf ()
 Remove this component from its object. More...
 

Static Public Member Functions

static unsigned int getMaximumLights (const Type type)
 Get the setting for the maximum number of lights. More...
 
static void makeCubemapMatrices (const glm::mat4 &projection, const glm::vec3 &position, std::vector< glm::mat4 > &viewMats)
 Calculate cube map view matrices. More...
 

Protected Member Functions

Message::Result receiveMessage (const Message &message) override
 Receive a message. More...
 
- Protected Member Functions inherited from jop::Component
 Component (Object &object, const uint32 ID)
 Constructor. More...
 
 Component (const Component &other, Object &newObj)
 Copy constructor. More...
 

Friends

class Renderer
 

Detailed Description

Definition at line 48 of file LightSource.hpp.

Member Enumeration Documentation

The attenuation attribute

Enumerator
Constant 
Linear 
Quadratic 

Definition at line 78 of file LightSource.hpp.

The intensity attribute

Enumerator
Ambient 
Diffuse 
Specular 

Definition at line 69 of file LightSource.hpp.

The light type

Enumerator
Point 
Spot 
Directional 

Definition at line 60 of file LightSource.hpp.

Constructor & Destructor Documentation

jop::LightSource::LightSource ( Object object,
Renderer renderer,
const Type  type 
)

Constructor.

Parameters
objectReference to created object in object class
rendererReference to the renderer
typeThe light type
jop::LightSource::~LightSource ( )
override

Destructor.

Member Function Documentation

bool jop::LightSource::castsShadows ( ) const

Check if this light casts shadows.

Returns
True if this light casts shadows
float jop::LightSource::getAttenuation ( const Attenuation  attenuation) const

Get an attenuation value.

Parameters
attenuationThe attenuation type
Returns
The attenuation value
glm::vec3 jop::LightSource::getAttenuation ( ) const

Get the attenuation values as a vector.

x = constant y = linear z = quadratic

Returns
A vector with the attenuation values
const glm::vec2& jop::LightSource::getCutoff ( ) const

Get the cutoff values.

x = inner y = outer

Returns
Vector with the cutoff values
const Color& jop::LightSource::getIntensity ( const Intensity  intensity) const

Get an intensity value.

Parameters
intensityThe intensity type
Returns
The intensity value
const glm::mat4& jop::LightSource::getLightspaceMatrix ( const Cubemap::Face  face = Cubemap::Face::First) const

Get a light space matrix.

Faces other than First are only available with point lights. Trying to get these matrices when the light type is Spot or Directional will result in overstepping the array

Parameters
faceThe face whose matrix to fetch
Returns
Reference to the matrix
static unsigned int jop::LightSource::getMaximumLights ( const Type  type)
static

Get the setting for the maximum number of lights.

Parameters
typeThe light type
Returns
The maximum number of lights
float jop::LightSource::getRange ( ) const

Get the approximate maximum range.

The returned value may deviate from what was possibly previously passed to setAttenuation(). The calculation is a mere approximation but is to usually enough to determine the range in which the light is at all visible.

Returns
The maximum range
uint32 jop::LightSource::getRenderMask ( ) const

Get the render mask.

Returns
The render mask
const Texture* jop::LightSource::getShadowMap ( ) const

Get the shadow map.

Returns
Const reference to the shadow map. nullptr if no shadow map exists
Type jop::LightSource::getType ( ) const

Get the light type.

Returns
The light type
static void jop::LightSource::makeCubemapMatrices ( const glm::mat4 &  projection,
const glm::vec3 &  position,
std::vector< glm::mat4 > &  viewMats 
)
static

Calculate cube map view matrices.

Parameters
projectionThe projection matrix
positionThe view position
viewMatsReference to a vector with the matrices. This must have a size of at least 6
Message::Result jop::LightSource::receiveMessage ( const Message message)
overrideprotectedvirtual

Receive a message.

Override this to handle messages sent to this. Don't forget to call the base class' method as well to ensure that the message gets forwarded correctly.

Parameters
messageThe message
Returns
The message result

Reimplemented from jop::Component.

LightSource& jop::LightSource::setAttenuation ( const Attenuation  attenuation,
const float  value 
)

Set a single attenuation value.

Parameters
attenuationThe attenuation type
valueThe value to set
Returns
Reference to self
LightSource& jop::LightSource::setAttenuation ( const float  constant,
const float  linear,
const float  quadratic 
)

Set the attenuation values.

Parameters
constantThe constant attenuation
linearThe linear attenuation
quadraticThe quadratic attenuation
Returns
Reference to self
This method is exposed as command named setAttenuation
LightSource& jop::LightSource::setAttenuation ( const float  range)

Set the attenuation values using a range.

This roughly estimates the attenuation values for the given range. This aims for realism, which in some cases might mean that the light will become too dark.

Parameters
rangeThe range
Returns
Reference to self
LightSource& jop::LightSource::setCastShadows ( const bool  castShadows,
const glm::uvec2 &  resolution = glm::uvec2(0) 
)

Set shadow casting for this light.

This can be an expensive function, do not call frequently.

Parameters
castShadowsTrue to cast shadows
resolutionThe shadow map resolution, glm::uvec2(0) to use the default
Returns
Reference to self
LightSource& jop::LightSource::setCutoff ( const float  inner,
const float  outer 
)

Set the cutoff.

This only affects spot lights. The inner and outer cutoff control the dimming near the edges of the spot light.

Parameters
innerThe inner cutoff in radians. The light will be at its maximum intensity inside this angle
outerThe outer cutoff in radians
Returns
Reference to self
This method is exposed as command named setCutoff
LightSource& jop::LightSource::setIntensity ( const Intensity  intensity,
const Color color 
)

Set a specific intensity value.

Parameters
intensityThe intensity type
colorThe color value to set
Returns
Reference to self
This method is exposed as command named setIntensity
LightSource& jop::LightSource::setIntensity ( const Color ambient,
const Color diffuse,
const Color specular 
)

Set all intensity values.

Parameters
ambientAmbient intensity
diffuseDiffuse intensity
specularSpecular intensity
Returns
Reference to self
LightSource& jop::LightSource::setIntensity ( const Color intensity)

Set all intensity values.

All the intensity values will be set to the given color value.

Parameters
intensityThe intensity to set
Returns
Reference to self
void jop::LightSource::setRenderMask ( const uint32  mask)

Set the render mask.

Parameters
maskThe new mask to set

Friends And Related Function Documentation

friend class Renderer
friend

Definition at line 54 of file LightSource.hpp.


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