cCamera Class Reference
[Scenegraph]

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:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 cCamera (cWorld *iParent)
 Constructor of cCamera.
virtual ~cCamera ()
 Destructor of cCamera.
cWorldgetParentWorld ()
 Get pointer to parent world.
virtual bool select (const int a_windowPosX, const int a_windowPosY, const int a_windowWidth, const int a_windowHeight, cCollisionRecorder &a_collisionRecorder, cCollisionSettings &a_collisionSettings)
 Query whether the specified position is 'pointing at' any objects in the world.
virtual bool set (const cVector3d &a_localPosition, const cVector3d &a_localLookAt, const cVector3d &a_localUp)
 Set the position and orientation of the camera.
cVector3d getLookVector () const
 Get the camera "look at" position vector for this camera.
cVector3d getUpVector () const
 Get the "up" vector for this camera.
cVector3d getRightVector () const
 Get the "right direction" vector for this camera.
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)...
void copyImageData (cImageLoader *a_image)
 Copy output image data to image structure.
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

double m_projectionMatrix [16]
 It's useful to store the last projection matrix, for gluProject'ing things.
cGenericObject m_front_2Dscene
 Front plane scenegraph which can be used to attach widgets.
cGenericObject m_back_2Dscene
 Black plane scenegraph which can be used to attach widgets.

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

cWorldm_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
 Some apps may have the camera as a child of the world, which would cause recursion when resetting the display.
unsigned int m_lastDisplayWidth
 last width size of the window.
unsigned int m_lastDisplayHeight
 last height size of the window.

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

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::copyImageData ( cImageLoader a_image  ) 

Copy output image data to image structure.

Copies the opengl image buffer to a cImageLoader class structure.

Parameters:
a_image Destination image

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::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

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,
cCollisionRecorder a_collisionRecorder,
cCollisionSettings a_collisionSettings 
) [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_collisionRecorder Recorder used to store all collisions between mouse and objects
a_collisionSettings Settings related to collision detection
Returns:
Returns true if an object has been hit, else false

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::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::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.

int cCamera::setStereoFocalLength ( double  a_stereoFocalLength  ) 

Set stereo focal length.

Set stereo focal length

Parameters:
a_stereoFocalLength Focal length.


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


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