# cWorld Class Reference
[Scenegraph]

cWorld defines the typical root of the CHAI scene graph. It stores lights, allocates textures, and serves as the root for scene-wide collision detection. More...

`#include <CWorld.h>`

Inheritance diagram for cWorld:

[legend]

List of all members.

## Public Member Functions
| cWorld ()
| Constructor of cWorld.
virtual | ~cWorld ()
| Destructor of cWorld.
void | setBackgroundColor (const GLfloat a_red, const GLfloat a_green, const GLfloat a_blue)
| Set the background color used when rendering.
void | setBackgroundColor (const cColorf &a_color)
| Set the background color used when rendering.
cColorf | getBackgroundColor () const
| Get the background color used when rendering.
void | enableLightSourceRendering (bool enable)
| Enable or disable the rendering of this world's light sources.
cTexture2D * | newTexture ()
| Create a new bitmap texture.
cTexture2D * | getTexture (unsigned int a_index)
| Get a pointer to a texture by passing an index into my texture list.
void | addTexture (cTexture2D *a_texture)
| Add a texture to my texture list.
bool | removeTexture (cTexture2D *a_texture)
| Remove a texture from my texture list.
bool | deleteTexture (cTexture2D *a_texture)
| Delete a texture.
void | deleteAllTextures ()
| Delete all textures.
virtual bool | computeCollisionDetection (cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings)
| Compute collision detection between a ray segment and all objects in this world.
virtual void | render (const int a_renderMode=0)
| Render OpenGL lights.
virtual cLight * | getLightSource (int index)
| Get access to a particular light source (between 0 and MAXIMUM_OPENGL_LIGHT_COUNT-1).
virtual void | onDisplayReset (const bool a_affectChildren=true)
| Resets textures and displays for the world.
## Public Attributes
double | m_worldModelView [16]
| It's useful to store the world's modelview matrix, for rendering stuff in "global" coordinates.
## Protected Member Functions
bool | addLightSource (cLight *a_light)
| Add a light source to this world.
bool | removeLightSource (cLight *a_light)
| Remove a light source from this world.
## Protected Attributes
cColorf | m_backgroundColor
| Background color. Default color is black.
vector< cTexture2D * > | m_textures
| List of textures.
vector< cLight * > | m_lights
| List of light sources.
bool | m_renderLightSources
| Should I render my light sources, or just use the current OpenGL light state?
bool | m_performingDisplayReset
| Some apps may have multiple cameras, which would cause recursion when resetting the display.
## Friends
class | cLight

## Detailed Description

cWorld defines the typical root of the CHAI scene graph. It stores lights, allocates textures, and serves as the root for scene-wide collision detection.

## Constructor & Destructor Documentation

cWorld::~cWorld | ( |  | ) | `[virtual]`

Destructor of cWorld.

Destructor of cWorld. Deletes the world, all his children, and all his textures.

## Member Function Documentation

bool cWorld::addLightSource | ( | cLight * | a_light | ) | `[protected]`

Add a light source to this world.

Add an OpenGL light source to the world. A maximum of eight light sources can be registered. For each registered light source, an OpenGL lightID number is defined

Parameters:

  | a_light | light source to register.

Returns:
  return true if light source was registered, otherwise return false.

void cWorld::addTexture | ( | cTexture2D * | a_texture | ) |

Add a texture to my texture list.

Add texture to texture list.

Parameters:

  | a_texture | Texture to be added to the textures list.

bool cWorld::computeCollisionDetection | ( | cVector3d & | a_segmentPointA,
|  | cVector3d & | a_segmentPointB,
|  | cCollisionRecorder & | a_recorder,
|  | cCollisionSettings & | a_settings |
| ) |  |  | `[virtual]`

Compute collision detection between a ray segment and all objects in this world.

Determine whether the given segment intersects a triangle in this world. The segment is described by a start point /e a_segmentPointA and end point /e a_segmentPointB. Collision detection functions of all children of the world are called, which recursively call the collision detection functions for all objects in this world. If there is more than one collision, the one closest to a_segmentPointA is the one returned.

Parameters:

  | a_segmentPointA | Start point of segment. Value may be changed if returned collision is with a moving object.
  | a_segmentPointB | End point of segment.
  | a_recorder | Stores all collision events
  | a_settings | Contains collision settings information.

Reimplemented from cGenericObject.

void cWorld::deleteAllTextures | ( |  | ) |

Delete all textures.

Delete all texture from memory.

bool cWorld::deleteTexture | ( | cTexture2D * | a_texture | ) |

Delete a texture.

Delete texture from textures list and erase it from memory.

Parameters:

  | a_texture | Texture to be deleted.

Returns:
  Return true if operation succeeded

cLight * cWorld::getLightSource | ( | int | index | ) | `[virtual]`

Get access to a particular light source (between 0 and MAXIMUM_OPENGL_LIGHT_COUNT-1).

Get access to a particular light source (between 0 and MAXIMUM_OPENGL_LIGHT_COUNT-1). Returns a pointer to the requested light, or zero if it's not available.

Parameters:

  | index | Specifies the light (0 -> 7) that should be accessed

Returns:
  return A pointer to a valid light or 0 if that light doesn't exist

cTexture2D * cWorld::newTexture | ( |  | ) |

Create a new bitmap texture.

Create new texture and add it to textures list.

Returns:
  Return pointer to new texture entity.

void cWorld::onDisplayReset | ( | const bool | a_affectChildren = `true` | ) | `[virtual]`

Resets textures and displays for the world.

Called by the user or by the viewport when the world needs to have textures and display lists reset (e.g. after a switch to or from fullscreen).

Parameters:

  | a_affectChildren | Should I pass this on to my children?

Reimplemented from cGenericObject.

bool cWorld::removeLightSource | ( | cLight * | a_light | ) | `[protected]`

Remove a light source from this world.

Remove a light source from world.

Parameters:

  | a_light | light source to be removed.

Returns:
  return true if light source was removed, otherwise return false.

bool cWorld::removeTexture | ( | cTexture2D * | a_texture | ) |

Remove a texture from my texture list.

Remove texture from textures list. Texture is not deleted from memory.

Parameters:

  | a_texture | Texture to be removed from textures list.

Returns:
  Return true if operation succeeded

void cWorld::render | ( | const int | a_renderMode = `0` | ) | `[virtual]`

Render OpenGL lights.

Render the world in OpenGL.

Parameters:

  | a_renderMode | Rendering Mode.

Reimplemented from cGenericObject.

void cWorld::setBackgroundColor | ( | const cColorf & | a_color | ) |

Set the background color used when rendering.

Set the background color used when rendering. This really belongs in cCamera or cViewport; it's a historical artifact that it lives here.

Parameters:

  | a_color | new background color.

void cWorld::setBackgroundColor | ( | const GLfloat | a_red,
|  | const GLfloat | a_green,
|  | const GLfloat | a_blue |
| ) |  |  |

Set the background color used when rendering.

Set the background color used when rendering. This really belongs in cCamera or cViewport; it's a historical artifact that it lives here.

Parameters:

  | a_red | Red component.
  | a_green | Green component.
  | a_blue | Blue component.

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

- D:/CHAI3D/build-2-0-0/2.0.0/win32/src/scenegraph/CWorld.h
- D:/CHAI3D/build-2-0-0/2.0.0/win32/src/scenegraph/CWorld.cpp

CHAI3D 2.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2009 - CHAI 3D
All Rights Reserved.