Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglLight Class Reference

#include <sglLight.hpp>

Inheritance diagram for sglLight::

sglNode sglObject sglDirectionalLight sglPositionalLight sglSpotLight List of all members.

Public Methods

 sglLight ()
virtual ~sglLight ()
void setOn (bool on)
bool getOn () const
void setAmbient (const sglVec4f &color)
void setAmbient (float r, float g, float b, float a)
const sglVec4f& getAmbient () const
void setDiffuse (const sglVec4f &color)
void setDiffuse (float r, float g, float b, float a)
const sglVec4f& getDiffuse () const
void setSpecular (const sglVec4f &color)
void setSpecular (float r, float g, float b, float a)
const sglVec4f& getSpecular () const
virtual void setup (GLenum gl_light_number) const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Protected Methods

virtual void cull (sglCull< float > &trav_state, unsigned int cull_flags) const
virtual void cull (sglCull< double > &trav_state, unsigned int cull_flags) const
void copyTo (sglLight *dst, unsigned int mode) const

Protected Attributes

bool m_on_flag
sglVec4f m_ambient
sglVec4f m_diffuse
sglVec4f m_specular

Detailed Description

sglLight is the abstract base class for all scene graph lights. Derived from sglNode, it is a leaf node of the scene graph. Every light will have associated with it a bounding sphere, the size of which is determined by the subclasses. When that bounding sphere intersects the view frustum during cull, that light will be placed on the list of lights to enable before the draw() function is called. The static variable sgl::s_max_lights is set during sgl::initialize() to the maximum number of lights supported by OpenGL. The sglLightProcessor class is used is determine which lights will be used if more than sgl::s_max_lights are collected during cull.

When constructed the light will be enabled by default, and will have no ambient component (black), and white diffuse and specular components. The user can disable the light by calling the member function, sglLight::setOn(false). The various components of light can be set with calls to setAmbient, setDiffuse, and setSpecular member functions.

Some global OpenGL lighting concepts such as global ambient, local light model, and two-sided lighting have not been implmented in SGL yet (the user must currently call these OpenGL commands directly). They might be implemented as static functions in this class.

Todo:
Implement functions to set global ambient.

Implement toggle for local light model.

Implement toggle for two sided lighting.

Definition at line 65 of file sglLight.hpp.


Constructor & Destructor Documentation

sglLight::sglLight ( )
 

default constructor.

sglLight::~sglLight ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglLight::setOn ( bool on )
 

Enable/disable the light.

Parameters:
on   False to disable the light (default is true/on).

bool sglLight::getOn ( ) const [inline]
 

Get the current state (on or off) of this light.

Returns:
True if light is enabled, otherwise false.

Definition at line 81 of file sglLight.hpp.

void sglLight::setAmbient ( const sglVec4f & color ) [inline]
 

Set the ambient color component of the light.

Parameters:
color   Four component color vector. Default is (0, 0, 0, 1)

Definition at line 86 of file sglLight.hpp.

void sglLight::setAmbient ( float r,
float g,
float b,
float a ) [inline]
 

Set the ambient color component of the light. Default is (0, 0, 0, 1)

Parameters:
r   Red component (valid values are from 0 to 1)
g   Green component (valid values are from 0 to 1)
b   Blue component (valid values are from 0 to 1)
a   Alpha component (valid values are from 0 to 1)

Definition at line 94 of file sglLight.hpp.

const sglVec4f & sglLight::getAmbient ( ) const [inline]
 

Get the current ambient component.

Returns:
Reference to the 4 component color vector.

Definition at line 100 of file sglLight.hpp.

void sglLight::setDiffuse ( const sglVec4f & color ) [inline]
 

Set the diffuse color component of the light.

Parameters:
color   Four component color vector. Default is (1, 1, 1, 1)

Definition at line 105 of file sglLight.hpp.

void sglLight::setDiffuse ( float r,
float g,
float b,
float a ) [inline]
 

Set the diffuse color component of the light. Default is (1, 1, 1, 1)

Parameters:
r   Red component (valid values are from 0 to 1)
g   Green component (valid values are from 0 to 1)
b   Blue component (valid values are from 0 to 1)
a   Alpha component (valid values are from 0 to 1)

Definition at line 113 of file sglLight.hpp.

const sglVec4f & sglLight::getDiffuse ( ) const [inline]
 

Get the current diffuse component.

Returns:
Reference to the 4 component color vector.

Definition at line 119 of file sglLight.hpp.

void sglLight::setSpecular ( const sglVec4f & color ) [inline]
 

Set the specular color component of the light.

Parameters:
color   Four component color vector. Default is (1, 1, 1, 1)

Definition at line 124 of file sglLight.hpp.

void sglLight::setSpecular ( float r,
float g,
float b,
float a ) [inline]
 

Set the specular color component of the light. Default is (1, 1, 1, 1)

Parameters:
r   Red component (valid values are from 0 to 1)
g   Green component (valid values are from 0 to 1)
b   Blue component (valid values are from 0 to 1)
a   Alpha component (valid values are from 0 to 1)

Definition at line 132 of file sglLight.hpp.

const sglVec4f & sglLight::getSpecular ( ) const [inline]
 

Get the current specular component.

Returns:
Reference to the 4 component color vector.

Definition at line 138 of file sglLight.hpp.

void sglLight::setup ( GLenum gl_light_number ) const [virtual]
 

This function is called during sglCull::draw() function to issue the OpenGL light commands needed to activate this light before rendering.

Parameters:
gl_light_number   One of GL_LIGHT0 .. GL_LIGHT<sgl::s_max_lights-1>

Reimplemented in sglDirectionalLight, sglPositionalLight, and sglSpotLight.

virtual void sglLight::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglNode.

Reimplemented in sglDirectionalLight, sglPositionalLight, and sglSpotLight.

virtual void sglLight::cull ( sglCull< float > & trav_state,
unsigned int cull_flags ) const [protected, virtual]
 

The single precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglNode.

virtual void sglLight::cull ( sglCull< double > & trav_state,
unsigned int cull_flags ) const [protected, virtual]
 

The double precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglNode.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:08 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001