OpenGLPrakt --> cObject --> cVisibleObject --> cInteractiveObject --> cLight

class cLight
    extends cInteractiveObject as public

A class for managing OpenGL lights.

Lights are very special since there might be only a limited amount of them active at once. We need to check that before turning a light on (that's what the static variables are for).

It's a special object since it does not draw itself, but only is glEnabled() during SetUpForDrawing and glDisabled() during CleanUpAfterDrawing() (of course, the light needs to be turned on).

It might (and actually is) derived from this class, e.g. for providing a directional and a spot light.

Note that cLights are treatened like all other cObjects as far as they might have siblings and take part in the normal scene hierarchy.

The inherited mRotation quaternion is not used.

Source:
../src/cLight.hh:55

Constructors Index

cLight
[public] default constructor
cLight
[public] constructor with initialization of position and name
cLight
[public] constructor with initialization of position, state and name
cLight
[public] constructor with initialization of position, color, state and name
~cLight
[public] destructor


Enums Index

teLightState
[public] an extra type for the light status


Variables Index

mgActiveLights
[protected] keep track of how many lights are currently active
mgLightSlots
[protected] keep track of status of OpenGL lights
mLightColor
[protected] ambient color component of light
mLightSlot
[protected] actually used light slot (-1 = no slot used)
mQuadric
[protected] only used if the light source is to be drawn
mState
[protected] current status of light (LIGHT_ON or LIGHT_OFF)


Methods Index

Activate
[protected] set up for drawing (overloaded from cVisibleObject)
ActivateLight
[protected] this one performs the actual set up of the light
AllocateLightSlot
[protected] aquire a light slot (stored in mLightSlot)
Deactivate
[protected] clean up after drawing (overloaded from cVisibleObject)
DeactivateLight
[protected] perform steps neccessary before freeing the light slot (e.g. disabling the light)
DrawThisObject
[protected] A light is a visible object therefore it needs a drawing function
FreeLightSlot
[protected] free the light slot
GetDefaultName
[protected] identify an instance of this class if it's got no name
IsOn
[public] query light status
MoveBy
[public] overload cVisibleObject::MoveBy since we want to ignore mRotation while moving (it's used to determine direction only)
MoveTo
[public] overload cVisibleObject::MoveTo since we want to ignore mRotation while moving (it's used to determine direction only)
ReceiveEvent
[public] event receiver - we listen for switchon/switchoff events
SetAmbientColor
[public] set ambient color
SetDiffuseColor
[public] set diffuse color
SetSpecularColor
[public] set specular color
SetState
[public] enable the light
SubscribeToActiveEvents
[protected] we want to get switchon/switchoff events if we're selected
Transform
[protected] suppress transformation
UnsubscribeFromActiveEvents
[protected] unsubscribe from switchon/switchoff if we get deselected


Constructors

cLight

public cLight ( cEventDispatcher * disp ,
                const char * name = NULL ) ;

default constructor

cLight

public cLight ( cEventDispatcher * disp ,
                const cVertex & pos ,
                const char * name = NULL ) ;

constructor with initialization of position and name

Parameters:
pos initial position of light source
state initial state of light source (default: on)
name name of light source (optional)

cLight

public cLight ( cEventDispatcher * disp ,
                const cVertex & pos ,
                const teLightState state = LIGHT_ON ,
                const char * name = NULL ) ;

constructor with initialization of position, state and name

Parameters:
pos initial position of light source
state initial state of light source (default: on)
name name of light source (optional)

cLight

public cLight ( cEventDispatcher * disp ,
                const cVertex & pos ,
                const cADSEColor & col ,
                const teLightState state = LIGHT_ON ,
                const char * name = NULL ) ;

constructor with initialization of position, color, state and name

Parameters:
pos initial position of light source
col color of the light source (cADSEColor object) (emissive color component is not used)
state initial state of light source (default: on)
name name of light source (optional)

cLight

public virtual ~ cLight ( ) ;

destructor


Enums

teLightState

public enum teLightState { LIGHT_OFF ,
                           LIGHT_ON } ;

an extra type for the light status


Variables

mState

protected teLightState mState

current status of light (LIGHT_ON or LIGHT_OFF)

mLightColor

protected cADSEColor mLightColor

ambient color component of light

mgLightSlots

protected static teLightState mgLightSlots [ 8 ]

keep track of status of OpenGL lights

As OpenGL allows 8 lights at once, we need to keep track of which lights are currently in use and which are not.

At runtime, to enable a light, we look for a free "slot" and use it for our light source.

mgActiveLights

protected static int mgActiveLights

keep track of how many lights are currently active

mLightSlot

protected int mLightSlot

actually used light slot (-1 = no slot used)

mQuadric

protected GLUquadricObj * mQuadric

only used if the light source is to be drawn


Methods

SetState

public void SetState ( teLightState state ) ;

enable the light

Parameters:
state teLightState - LIGHT_ON or LIGHT_OFF

IsOn

public bool IsOn ( ) const ;

query light status

Return:
bool stating whether the light is on or off

SetAmbientColor

public virtual void SetAmbientColor ( const cColor & c ) ;

set ambient color

Parameters:
c new ambient color of light

SetDiffuseColor

public virtual void SetDiffuseColor ( const cColor & c ) ;

set diffuse color

Parameters:
c new diffuse color of light

SetSpecularColor

public virtual void SetSpecularColor ( const cColor & c ) ;

set specular color

Parameters:
c new specular color of light

ReceiveEvent

public virtual int ReceiveEvent ( const cEvent & event ) ;

event receiver - we listen for switchon/switchoff events

Return:
0 - event accepted, -1 - event not accepted

MoveTo

public virtual void MoveTo ( const cVertex & v ) ;

overload cVisibleObject::MoveTo since we want to ignore mRotation while moving (it's used to determine direction only)

MoveBy

public virtual void MoveBy ( const cVertex & v ) ;

overload cVisibleObject::MoveBy since we want to ignore mRotation while moving (it's used to determine direction only)

Activate

protected virtual void Activate ( ) ;

set up for drawing (overloaded from cVisibleObject)

Lights should follow the following behaviour: 1. If you change a standard parameter for a light, undo it in Deactivate() 2. Position and {Ambient,Diffuse,Specular}Color do not count for 1.

ActivateLight

protected virtual void ActivateLight ( ) ;

this one performs the actual set up of the light

(called by Activate()); separeted to simplify cDirectionLight

Transform

protected virtual void Transform ( ) ;

suppress transformation

DrawThisObject

protected virtual void DrawThisObject ( ) ;

A light is a visible object therefore it needs a drawing function

It is used when the light is shown.

Deactivate

protected virtual void Deactivate ( ) ;

clean up after drawing (overloaded from cVisibleObject)

DeactivateLight

protected virtual void DeactivateLight ( ) ;

perform steps neccessary before freeing the light slot (e.g. disabling the light)

AllocateLightSlot

protected virtual int AllocateLightSlot ( ) ;

aquire a light slot (stored in mLightSlot)

Return:
-1 on error (no free slot), 0 on success

FreeLightSlot

protected virtual int FreeLightSlot ( ) ;

free the light slot

Return:
-1 on error (slot was not allocated), 0 on success

SubscribeToActiveEvents

protected virtual void SubscribeToActiveEvents ( ) ;

we want to get switchon/switchoff events if we're selected

UnsubscribeFromActiveEvents

protected virtual void UnsubscribeFromActiveEvents ( ) ;

unsubscribe from switchon/switchoff if we get deselected

GetDefaultName

protected virtual const char * GetDefaultName ( ) const ;

identify an instance of this class if it's got no name


This documentation was generated automatically by the ccdoc tool (version 0.7a).
Click here to submit a bug report or feature request.

Click here to return to the top of the page.