OpenGLPrakt --> cObject --> cVisibleObject --> cInteractiveObject --> cLight
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.
public cLight ( cEventDispatcher * disp , const char * name = NULL ) ;
default constructor
public cLight ( cEventDispatcher * disp , const cVertex & pos , const char * name = NULL ) ;
constructor with initialization of position and name
pos | initial position of light source |
state | initial state of light source (default: on) |
name | name of light source (optional) |
public cLight ( cEventDispatcher * disp , const cVertex & pos , const teLightState state = LIGHT_ON , const char * name = NULL ) ;
constructor with initialization of position, state and name
pos | initial position of light source |
state | initial state of light source (default: on) |
name | name of light source (optional) |
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
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) |
public virtual ~ cLight ( ) ;
destructor
public enum teLightState { LIGHT_OFF , LIGHT_ON } ;
an extra type for the light status
protected teLightState mState
current status of light (LIGHT_ON or LIGHT_OFF)
protected cADSEColor mLightColor
ambient color component of light
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.
protected static int mgActiveLights
keep track of how many lights are currently active
protected int mLightSlot
actually used light slot (-1 = no slot used)
protected GLUquadricObj * mQuadric
only used if the light source is to be drawn
public void SetState ( teLightState state ) ;
enable the light
state | teLightState - LIGHT_ON or LIGHT_OFF |
public bool IsOn ( ) const ;
query light status
public virtual void SetAmbientColor ( const cColor & c ) ;
set ambient color
c | new ambient color of light |
public virtual void SetDiffuseColor ( const cColor & c ) ;
set diffuse color
c | new diffuse color of light |
public virtual void SetSpecularColor ( const cColor & c ) ;
set specular color
c | new specular color of light |
public virtual int ReceiveEvent ( const cEvent & event ) ;
event receiver - we listen for switchon/switchoff events
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)
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)
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.
protected virtual void ActivateLight ( ) ;
this one performs the actual set up of the light
(called by Activate()); separeted to simplify cDirectionLight
protected virtual void Transform ( ) ;
suppress transformation
protected virtual void DrawThisObject ( ) ;
A light is a visible object therefore it needs a drawing function
It is used when the light is shown.
protected virtual void Deactivate ( ) ;
clean up after drawing (overloaded from cVisibleObject)
protected virtual void DeactivateLight ( ) ;
perform steps neccessary before freeing the light slot (e.g. disabling the light)
protected virtual int AllocateLightSlot ( ) ;
aquire a light slot (stored in mLightSlot)
protected virtual int FreeLightSlot ( ) ;
free the light slot
protected virtual void SubscribeToActiveEvents ( ) ;
we want to get switchon/switchoff events if we're selected
protected virtual void UnsubscribeFromActiveEvents ( ) ;
unsubscribe from switchon/switchoff if we get deselected
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.