- Main Page
- Classes
- Files
- Directories

- Class List
- Class Hierarchy
- Class Members

# cCamera Class Reference

cCamera describes a virtual Camera located inside the world. Its job in life is to set up the OpenGL projection matrix for the current OpenGL rendering context. The default camera looks down the negative x-axis. OpenGL folks may wonder why we chose the negative x-axis... it turns out that's a better representation of the standard conventions used in general robotics. More...

`#include <CCamera.h>`

Inheritance diagram for cCamera:

List of all members.

## Public Member Functions
| cCamera (cWorld *iParent)
| Constructor of cCamera.
virtual | ~cCamera ()
| Destructor of cCamera.
cVector3d | getLookVector () const
| Get the look/up/right vectors for this camera according to the CHAI conventions.
virtual bool | set (const cVector3d &a_localPosition, const cVector3d &a_localLookAt, const cVector3d &a_localUp)
| Set the position and orientation of the camera.
cWorld * | getParentWorld ()
| Get pointer to parent world.
void | setClippingPlanes (const double a_distanceNear, const double a_distanceFar)
| Set near and far clipping planes.
double | getNearClippingPlane ()
| Get near clipping plane.
double | getFarClippingPlane ()
| Get far clipping plane.
void | adjustClippingPlanes ()
| Automatically adjust back and front clipping planes.
void | enableClipPlane (const unsigned int &index, const int &enable, const double *peqn=0)
| Enable or disable one of the (six) arbitrary clipping planes.
void | setFieldViewAngle (double a_fieldViewAngle)
| Set field of view angle (in degrees).
double | getFieldViewAngle ()
| Read field of view angle (in degrees).
int | setStereoFocalLength (double a_stereoFocalLength)
| Set stereo focal length.
double | getStereoFocalLength ()
| Get stereo focal length.
int | setStereoEyeSeparation (double a_stereoEyeSeparation)
| Set stereo eye separation.
double | getStereoEyeSeparation ()
| Get stereo eye separation.
virtual void | renderView (const int a_windowWidth, const int a_windowHeight, const int a_imageIndex=CHAI_MONO)
| Render the camera in OpenGL (i.e. set up the projection matrix)...
virtual bool | select (const int a_windowPosX, const int a_windowPosY, const int a_windowWidth, const int a_windowHeight, cGenericObject *&a_selectedObject, cTriangle *&a_selectedTriangle, cVector3d &a_selectedPoint, double a_selectedDistance, const bool a_visibleObjectsOnly)
| Query whether the specified position is 'pointing at' any objects in the world.
virtual void | enableMultipassTransparency (bool enable)
| Enable or disable additional rendering passes for transparency (see full comment).
virtual void | onDisplayReset (const bool a_affectChildren=true)
| Resets textures and displays for the world associated with this camera.
## Public Attributes
cGenericObject | m_front_2Dscene
double | m_projectionMatrix [16]
| It's useful to store the last projection matrix, for gluProject'ing things.
## Protected Member Functions
void | render2dSceneGraph (cGenericObject *a_graph, int a_width, int a_height)
| Render a 2d scene within this camera's view.
## Protected Attributes
cWorld * | m_parentWorld
| Parent world.
double | m_distanceNear
| Distance to near clipping plane.
double | m_distanceFar
| Distance to far clipping plane.
cClippingPlane | m_clipPlanes [CHAI_MAX_CLIP_PLANES]
| Other clipping planes.
double | m_fieldViewAngle
| Field of view angle in degrees.
double | m_stereoFocalLength
| Focal length.
double | m_stereoEyeSeparation
| Eye separation.
bool | m_useMultipassTransparency
| If true, three rendering passes are performed to approximate back-front sorting (see long comment).
bool | m_performingDisplayReset
## Friends
class | cWorld

## Detailed Description

cCamera describes a virtual Camera located inside the world. Its job in life is to set up the OpenGL projection matrix for the current OpenGL rendering context. The default camera looks down the negative x-axis. OpenGL folks may wonder why we chose the negative x-axis... it turns out that's a better representation of the standard conventions used in general robotics.

## Constructor & Destructor Documentation

cCamera::cCamera | ( | cWorld * | a_parentWorld | ) |

Constructor of cCamera.

Create a camera by passing the parent world as a parameter.

Parameters:

  | a_parentWorld | Parent world camera.

## Member Function Documentation

bool cCamera::set | ( | const cVector3d & | a_localPosition,
|  | const cVector3d & | a_localLookAt,
|  | const cVector3d & | a_localUp |
| ) |  |  | `[virtual]`

Set the position and orientation of the camera.

Set the position and orientation of the camera. Three vectors are required:

[iPosition] which describes the position in local coordinates of the camera

[iLookAt] which describes a point at which the camera is looking

[iUp] to orient the camera around its rolling axis. [iUp] always points to the top of the image.

These vectors are used in the usual gluLookAt sense.

Parameters:

  | a_localPosition | The position of the camera in local coordinates
  | a_localLookAt | The Point in local space at which the camera looks
  | a_localUp | A vector giving the rolling orientation (points toward the top of the image)

void cCamera::setClippingPlanes | ( | const double | a_distanceNear,
|  | const double | a_distanceFar |
| ) |  |  |

Set near and far clipping planes.

Set the positions of the near and far clip planes

Parameters:

  | a_distanceNear | Distance to near clipping plane
  | a_distanceFar | Distance to far clipping plane

void cCamera::adjustClippingPlanes | ( |  | ) |

Automatically adjust back and front clipping planes.

This call automatically adjusts the front and back clipping planes to optimize usage of the z-buffer.

void cCamera::enableClipPlane | ( | const unsigned int & | index,
|  | const int & | enable,
|  | const double * | peqn = `0` |
| ) |  |  |

Enable or disable one of the (six) arbitrary clipping planes.

Enable or disable one of the (six) arbitrary clipping planes.

Parameters:

  | index | Which clip plane (0 -> CHAI_MAX_CLIP_PLANES-1) does this refer to?
  | enable | Should I turn this clip plane on or off, or should I leave it alone? 0 : disabled 1 : enabled -1 : don't touch
  | peqn | What is the plane equation for this clipping plane?

void cCamera::setFieldViewAngle | ( | double | a_fieldViewAngle | ) |

Set field of view angle (in degrees).

Set the field of view angle in degrees

Parameters:

  | a_fieldViewAngle | Field of view angle in degrees (should be between 0 and 180)

int cCamera::setStereoFocalLength | ( | double | a_stereoFocalLength | ) |

Set stereo focal length.

Set stereo focal length

Parameters:

  | a_stereoFocalLength | Focal length.

int cCamera::setStereoEyeSeparation | ( | double | a_stereoEyeSeparation | ) |

Set stereo eye separation.

Set stereo eye separation

Parameters:

  | a_stereoEyeSeparation | Distance between the left and right eyes.

Note that the stereo pair can be reversed by supplying a negative eye separation.

void cCamera::renderView | ( | const int | a_windowWidth,
|  | const int | a_windowHeight,
|  | const int | a_imageIndex = `CHAI_MONO` |
| ) |  |  | `[virtual]`

Render the camera in OpenGL (i.e. set up the projection matrix)...

Set up the OpenGL perspective projection matrix, and nukes the contents of the GL buffers. This function assumes the caller (typically cViewport) has set the appropriate buffer to be current.

Parameters:

  | a_windowWidth | Width of viewport.
  | a_windowHeight | Height of viewport.
  | a_imageIndex | One of the following constants, identifying the frame to be rendered:

CHAI_MONO, CHAI_STEREO_LEFT, CHAI_STEREO_RIGHT

Note that CHAI_STEREO_DEFAULT doesn't really make sense for the camera; this is a constant to be sent to a _viewport_, which will then decide which frame(s) to ask the camera to render.

bool cCamera::select | ( | const int | a_windowPosX,
|  | const int | a_windowPosY,
|  | const int | a_windowWidth,
|  | const int | a_windowHeight,
|  | cGenericObject *& | a_selectedObject,
|  | cTriangle *& | a_selectedTriangle,
|  | cVector3d & | a_selectedPoint,
|  | double | a_selectedDistance,
|  | const bool | a_visibleObjectsOnly |
| ) |  |  | `[virtual]`

Query whether the specified position is 'pointing at' any objects in the world.

Check for collision detection between an x-y position (typically a mouse click) and an object in the scene

Parameters:

  | a_windowPosX | X coordinate position of mouse click.
  | a_windowPosY | Y coordinate position of mouse click.
  | a_windowWidth | Width of window display (pixels)
  | a_windowHeight | Height of window display (pixels)
  | a_selectedObject | Returns a pointer to the selected object (if any)
  | a_selectedTriangle | Returns a pointer to selected triangle (if any)
  | a_selectedPoint | Returns the point is space where a collision was found (if any)
  | a_selectedDistance | Returns the distance between the camera and the collision point (if any)
  | a_visibleObjectsOnly | Should we ignore invisible objects?

Returns:
  Returns true if an object has been hit, else false

void cCamera::enableMultipassTransparency | ( | bool | enable | ) | `[virtual]`

Enable or disable additional rendering passes for transparency (see full comment).

Enable or disable multipass transparency... when this option is enabled (it's disabled by default), each time the camera is asked to render the scene, it will perform three rendering passes: a pass for non-transparent items, a pass for the backfaces of transparent items, and a pass for the frontfaces of transparent items.

Objects being rendered are told which pass is current via the parameter supplied to the render() function.

Note that if you turn this option on, you need to make sure that your objects don't unnecessarily draw themselves three times... that is, if you have an object that doesn't care about multipass transparency, start your render() function with:

if (a_renderMode != CHAI_RENDER_MODE_RENDER_ALL && a_renderMode != CHAI_RENDER_MODE_TRANSPARENT_FRONT_ONLY) return;

We will hopefully find a cleaner way to do this in the future, but for now be careful when you enable this feature...

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

Resets textures and displays for the world associated with this camera.

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.

void cCamera::render2dSceneGraph | ( | cGenericObject * | a_graph,
|  | int | a_width,
|  | int | a_height |
| ) |  |  | `[protected]`

Render a 2d scene within this camera's view.

Render a 2d scene within the viewport.

Parameters:

  | a_graph | The root of the 2d scenegraph to be rendered.
  | a_width | The size of the rendering window
  | a_height | The size of the rendering window

## Member Data Documentation

cGenericObject cCamera::m_front_2Dscene

These are special 'children' of the camera that are rendered independently of all other objects, intended to contain 2d objects only. The 'back' scene is rendered before the 3d objects; the 'front' scene is rendered after the 3d object. These are made public variables to allow convenient access to the scenegraph management functions.

These objects are rendered through an orthographic projection matrix, so the positive z axis faces the camera. Depth is currently not used. Lighting is disabled during rendering.

bool cCamera::m_performingDisplayReset`[protected]`

Some apps may have the camera as a child of the world, which would cause recursion when resetting the display

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

- chai3d/src/scenegraph/CCamera.h
- chai3d/src/scenegraph/CCamera.cpp