The camera class. More...
#include <VR3Camera.h>
Public Member Functions | |
Constructor | |
VR3Camera () | |
VR3Camera constructor. | |
General Functions | |
GLfloat | GetFovY () |
Gets the field of view value. | |
void | SetFovY (GLfloat fov) |
Sets the field of view value. | |
GLfloat | GetZNear () |
Gets the near clipping plane distance. | |
void | SetZNear (GLfloat znear) |
Sets the near clipping plane distance. | |
GLfloat | GetZFar () |
Gets the far clipping plane distance. | |
void | SetZFar (GLfloat zfar) |
Sets the far clipping plane distance. | |
void | GetPosition (GLfloat *p) |
Gets the camera position through the p out parameter. | |
const GLfloat * | GetPosition () |
Gets the camera position as a float vector. | |
void | SetPosition (GLfloat x, GLfloat y, GLfloat z) |
Sets the camera position using the given coordinates. | |
void | SetPosition (const GLfloat *point) |
Sets the camera position using the given vector. | |
const GLfloat * | GetUpVector () |
Gets the current up vector. | |
void | SetUpVector (GLfloat x, GLfloat y, GLfloat z) |
Sets the current up vector using the given vector coordinates. | |
void | SetUpVector (const GLfloat *up) |
Sets the up vector using the given up vector. | |
void | GetXAxis (GLfloat *a) |
Gets the first row of the rotation matrix (rotation components only) | |
void | GetYAxis (GLfloat *a) |
Gets the second row of the rotation matrix (rotation components only) | |
void | GetZAxis (GLfloat *a) |
Gets the third row of the rotation matrix (rotation components only) | |
void | GetDirection (GLfloat *v) |
Gets the camera direction. | |
int | GetMode () |
Gets the camera current mode. | |
Free Camera Functions | |
void | Free () |
Sets the current camera mode to VR_FREE. | |
void | SetDirection (GLfloat x, GLfloat y, GLfloat z) |
Sets the camera direction using the given vector components. | |
void | SetDirection (const GLfloat *dir) |
Sets the camera direction using the given vector. | |
void | RotateGlobal (GLfloat ang, GLfloat x, GLfloat y, GLfloat z) |
Rotates the camera along the specified axis in global (world) coordinates. | |
void | RotateGlobal (GLfloat a, const GLfloat *d) |
Rotates the camera along the specified axis in global (world) coordinates. | |
void | RotateLocal (GLfloat ang, GLfloat x, GLfloat y, GLfloat z) |
Rotates the camera along the specified axis in local (eye) coordinates. | |
void | RotateLocal (GLfloat a, const GLfloat *d) |
Rotates the camera along the specified axis in local (eye) coordinates. | |
Targeted Camera Functions | |
void | LookAt () |
Sets the current camera mode to VR3CAM_LOOKAT. | |
const GLfloat * | GetTarget () |
Gets the current target. | |
void | SetTarget (GLfloat x, GLfloat y, GLfloat z) |
Sets the current target using its position (world coordinates) | |
void | SetTarget (const GLfloat *t) |
Sets the current target using its position vector (world coordinates) | |
Matrix Extraction | |
void | GetViewMatrix (GLfloat *m) |
Gets the resulting modelview matrix. | |
Private Member Functions | |
VR3Camera (const VR3Camera &) | |
Disable default copy constructor. | |
VR3Camera & | operator= (const VR3Camera &) |
Disable default assignment operator. | |
Utility Functions | |
void | CheckTarget () |
Checks if the target is valid. | |
void | CheckUpVector () |
Checks if the up vector. | |
Private Attributes | |
GLfloat | m_fovy |
Field of view angle, in degrees, in the y direction. | |
GLfloat | m_near |
Distance from the viewer to the near clipping plane (always positive). | |
GLfloat | m_far |
Distance from the viewer to the far clipping plane (always positive). | |
GLfloat | m_pos [3] |
Camera position. | |
GLfloat | m_up [3] |
Camera up vector. | |
int | m_mode |
Camera mode (VR3CAM_FREE or VR3CAM_LOOKAT). | |
union { | |
GLfloat m_target [3] | |
Camera target point. | |
GLfloat m_direction [3] | |
Camera direction vector. | |
} | m_param |
The camera class.
This class allows to manage the camera (i.e. the viewpoint) and its properties. The camera setup affects how the frame image of the scene is produced. The available methods allow to position and rotate the camera, to fix a specific target or orientation. We now explain the behaviour in the two possible camera modes.
At rendering time, depending on the camera mode, different parameters are extracted from this class to compute the modelview matrix:
Definition at line 50 of file VR3Camera.h.
VR3Camera::VR3Camera | ( | const VR3Camera & | ) | [private] |
Disable default copy constructor.
VR3Camera::VR3Camera | ( | ) |
VR3Camera constructor.
This constructor merely initializes all member variables with their default values.
void VR3Camera::CheckTarget | ( | ) | [private] |
Checks if the target is valid.
This function checks if the target position equals the camera position. In that case the target position is slightly altered. This condition is dangerous when we try to set the matrix pointing to the specified target whose location is the same as the camera location (a division by zero is generated).
void VR3Camera::CheckUpVector | ( | ) | [private] |
Checks if the up vector.
This function checks if the up vector is valid with reference to the current camera direction (both targeted or free). If the up vector is parallel to the camera direction, a division by zero is generated when computing the camera transformation matrix. To avoid this situation, when the two vector are parallel, the target position is slightly altered.
void VR3Camera::Free | ( | ) |
Sets the current camera mode to VR_FREE.
Frees the camera from the current target. After calling this method the camera will point in the last direction used, corresponding to the line connecting the last camera position to the last camera target.
void VR3Camera::GetDirection | ( | GLfloat * | v ) |
Gets the camera direction.
Retrieves the current direction vector of the camera. The default direction vector is [0.0, 0.0, -1.0]. The direction may change because of calls to SetTarget, SetDirection, RotateLocal, RotateGlobal.
[out] | v | The camera direction vector |
GLfloat VR3Camera::GetFovY | ( | ) | [inline] |
Gets the field of view value.
Retrieves the angle in the vertical direction of the viewing frustum. The horizontal field of view is computed from the vertical one taking the aspect ratio of the current viewport into account.
Definition at line 130 of file VR3Camera.h.
int VR3Camera::GetMode | ( | ) | [inline] |
Gets the camera current mode.
Gets the current camera mode (either VR3CAM_FREE or VR3CAM_LOOKAT).
Definition at line 261 of file VR3Camera.h.
void VR3Camera::GetPosition | ( | GLfloat * | p ) |
Gets the camera position through the p out parameter.
Retrieves the current world space position of the camera.
[out] | p | The camera position (world coordinates) |
const GLfloat* VR3Camera::GetPosition | ( | ) | [inline] |
Gets the camera position as a float vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 180 of file VR3Camera.h.
const GLfloat* VR3Camera::GetTarget | ( | ) |
Gets the current target.
Retrieves the position of the current target of the active camera. The target must have been previously set by calling SetTarget.
const GLfloat* VR3Camera::GetUpVector | ( | ) | [inline] |
Gets the current up vector.
Retrieves the current up vector of the camera. The up vector is used by targeted cameras, or when the camera direction is set, as in both cases there is an ambiguity about how the camera should be rotated with respect to the target. The default up vector is [0.0, 1.0, 0.0].
Definition at line 203 of file VR3Camera.h.
void VR3Camera::GetViewMatrix | ( | GLfloat * | m ) |
Gets the resulting modelview matrix.
Retrieves the current view matrix of the camera. Please note that this matrix is a 4 by 4 matrix whose translation part is in general not empty. It's worth pointing out that this matrix represents the rototranslation of the world with respect to the camera and not the rototranslation of the camera object with respect to the world; the latter matrix can be obtained by inverting this one. Moreover, please note that elements 12, 13 and 14 do not represent the camera position in world space. Use GetPosition() instead.
[out] | m | The 4x4 rototranslation matrix of the current camera |
void VR3Camera::GetXAxis | ( | GLfloat * | a ) |
Gets the first row of the rotation matrix (rotation components only)
Retrieves a vector representing the X axis of the current camera reference system in world space.
[out] | a | Retrieved axis |
void VR3Camera::GetYAxis | ( | GLfloat * | a ) |
Gets the second row of the rotation matrix (rotation components only)
Retrieves a vector representing the Y axis of the current camera reference system in world space.
[out] | a | Retrieved axis |
void VR3Camera::GetZAxis | ( | GLfloat * | a ) |
Gets the third row of the rotation matrix (rotation components only)
Retrieves a vector representing the Z axis of the current camera reference system in world space.
[out] | a | Retrieved axis |
GLfloat VR3Camera::GetZFar | ( | ) | [inline] |
Gets the far clipping plane distance.
Retrieves the distance from the bottom plane of the viewing frustum.
Definition at line 160 of file VR3Camera.h.
GLfloat VR3Camera::GetZNear | ( | ) | [inline] |
Gets the near clipping plane distance.
Retrieves the distance from the top plane of the viewing frustum.
Definition at line 146 of file VR3Camera.h.
void VR3Camera::LookAt | ( | ) |
Sets the current camera mode to VR3CAM_LOOKAT.
Targets the camera to a target derived from the current direction, note that the target should be set after this call.
Disable default assignment operator.
void VR3Camera::RotateGlobal | ( | GLfloat | ang, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Rotates the camera along the specified axis in global (world) coordinates.
Rotates the active camera of ang degrees around the axis defined by (x,y,z). Please note that the axis is specified in global coordinates, i.e. in world space. The specified rotation is added to previous rotations, allowing the composition of subsequent rotations.
[in] | ang | The rotation angle in degrees |
[in] | x,y,z | The components of the rotation axis |
void VR3Camera::RotateGlobal | ( | GLfloat | a, |
const GLfloat * | d | ||
) | [inline] |
Rotates the camera along the specified axis in global (world) coordinates.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | a | The rotation angle in degrees |
[in] | d | The rotation axis |
Definition at line 307 of file VR3Camera.h.
void VR3Camera::RotateLocal | ( | GLfloat | ang, |
GLfloat | x, | ||
GLfloat | y, | ||
GLfloat | z | ||
) |
Rotates the camera along the specified axis in local (eye) coordinates.
Rotates the active camera of ang degrees around the axis defined by (x,y,z). Please note that the axis is specified in local coordinates, i.e. in eye space. The specified rotation is added to previous rotations, allowing the composition of subsequent rotations.
[in] | ang | The rotation angle in degrees |
[in] | x,y,z | The components of the rotation axis |
void VR3Camera::RotateLocal | ( | GLfloat | a, |
const GLfloat * | d | ||
) | [inline] |
Rotates the camera along the specified axis in local (eye) coordinates.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | a | The rotation angle in degrees |
[in] | d | The rotation axis |
Definition at line 325 of file VR3Camera.h.
void VR3Camera::SetDirection | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the camera direction using the given vector components.
Sets the new world space camera direction. It also frees the camera if it is targeted.
[in] | x,y,z | The components of the direction vector |
void VR3Camera::SetDirection | ( | const GLfloat * | dir ) |
Sets the camera direction using the given vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | dir | The direction vector |
void VR3Camera::SetFovY | ( | GLfloat | fov ) | [inline] |
Sets the field of view value.
Sets the angle in the vertical direction of the viewing frustum. The horizontal field of view is computed from the vertical one taking the aspect ratio of the current viewport into account.
[in] | fov | Vertical field of view |
Definition at line 139 of file VR3Camera.h.
void VR3Camera::SetPosition | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the camera position using the given coordinates.
Sets the new world space position for the camera.
[in] | x,y,z | The components of the new camera position |
void VR3Camera::SetPosition | ( | const GLfloat * | point ) |
Sets the camera position using the given vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | point | The new camera position |
void VR3Camera::SetTarget | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the current target using its position (world coordinates)
Specifies a target point for the camera. This means that, no matter its position, the camera always points towards the target until the Free() method is called. The camera is freed also if the direction is explicitly changed.
[in] | x,y,z | The target coordinates |
void VR3Camera::SetTarget | ( | const GLfloat * | t ) |
Sets the current target using its position vector (world coordinates)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | t | The target position vector |
void VR3Camera::SetUpVector | ( | GLfloat | x, |
GLfloat | y, | ||
GLfloat | z | ||
) |
Sets the current up vector using the given vector coordinates.
Specifies a new up vector of the camera. The up vector is used by targeted cameras, or when the camera direction is set, as in both cases there is an ambiguity about how the camera should be rotated with respect to the target or direction. The default up vector is [0.0, 1.0, 0.0].
[in] | x,y,z | The up vector components |
void VR3Camera::SetUpVector | ( | const GLfloat * | up ) |
Sets the up vector using the given up vector.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | up | The up vector |
void VR3Camera::SetZFar | ( | GLfloat | zfar ) | [inline] |
Sets the far clipping plane distance.
Sets the distance from the bottom plane of the viewing frustum.
[in] | zfar | Distance from the far plane |
Definition at line 167 of file VR3Camera.h.
void VR3Camera::SetZNear | ( | GLfloat | znear ) | [inline] |
Sets the near clipping plane distance.
Sets the distance from the top plane of the viewing frustum.
[in] | znear | Distance from the near plane |
Definition at line 153 of file VR3Camera.h.
GLfloat VR3Camera::m_direction[3] |
Camera direction vector.
Definition at line 69 of file VR3Camera.h.
GLfloat VR3Camera::m_far [private] |
Distance from the viewer to the far clipping plane (always positive).
Definition at line 57 of file VR3Camera.h.
GLfloat VR3Camera::m_fovy [private] |
Field of view angle, in degrees, in the y direction.
Definition at line 53 of file VR3Camera.h.
int VR3Camera::m_mode [private] |
Camera mode (VR3CAM_FREE or VR3CAM_LOOKAT).
Definition at line 63 of file VR3Camera.h.
GLfloat VR3Camera::m_near [private] |
Distance from the viewer to the near clipping plane (always positive).
Definition at line 55 of file VR3Camera.h.
union { ... } VR3Camera::m_param [private] |
GLfloat VR3Camera::m_pos[3] [private] |
Camera position.
Definition at line 59 of file VR3Camera.h.
GLfloat VR3Camera::m_target[3] |
Camera target point.
Definition at line 67 of file VR3Camera.h.
GLfloat VR3Camera::m_up[3] [private] |
Camera up vector.
Definition at line 61 of file VR3Camera.h.