#include <CUCamera.h>
|
| Camera () |
|
| ~Camera () |
|
virtual void | dispose () |
|
const Vec3 | getPosition () const |
|
const Vec3 | getDirection () const |
|
const Vec3 | getUp () const |
|
float | getNear () const |
|
void | setNear (float value) |
|
float | getFar () const |
|
void | setFar (float value) |
|
const Rect | getViewport () const |
|
const Mat4 & | getProjection () const |
|
const Mat4 & | getView () const |
|
const Mat4 & | getCombined () const |
|
const Mat4 & | getInverseProjectView () const |
|
virtual void | update ()=0 |
|
void | lookAt (const Vec3 target) |
|
void | lookAt (float x, float y, float z) |
|
void | normalizeUp () |
|
void | rotate (const Quaternion &quat) |
|
void | rotate (const Vec3 axis, float angle) |
|
void | rotateX (float angle) |
|
void | rotateY (float angle) |
|
void | rotateZ (float angle) |
|
void | rotate (float angle) |
|
void | rotate (const Mat4 &transform) |
|
void | rotateAround (const Vec3 point, const Vec3 axis, float angle) |
|
void | translate (const Vec3 vec) |
|
void | translate (const Vec2 vec) |
|
void | translate (float tx, float ty, float tz) |
|
void | translate (float tx, float ty) |
|
void | transform (const Mat4 &transform) |
|
Vec3 | unproject (const Vec3 windowCoords) const |
|
Vec3 | unproject (const Vec3 windowCoords, const Rect viewport) const |
|
Vec3 | screenToWorldCoords (const Vec2 screenCoords) const |
|
Vec3 | project (const Vec3 worldCoords) const |
|
Vec3 | project (const Vec3 worldCoords, const Rect viewport) const |
|
Vec2 | worldToScreenCoords (const Vec3 worldCoords) const |
|
Ray | getPickRay (const Vec3 windowCoords) const |
|
Ray | getPickRay (const Vec3 windowCoords, const Rect viewport) const |
|
Ray | getPickRayFromScreen (const Vec2 screenCoords) const |
|
Vec2 | windowToScreenCoords (const Vec3 windowCoords) const |
|
Vec2 | windowToScreenCoords (const Vec3 windowCoords, const Rect viewport) const |
|
Vec3 | screenToWindowCoords (const Vec2 screenCoords) const |
|
Vec3 | screenToWindowCoords (const Vec2 screenCoords, const Rect viewport) const |
|
This is a base class for a camera.
The actual cameras are OrthographicCamera and PerspectiveCamera. This class hash the shared functionality for transforms and queries in 3d space. In particular, it has several methods that help you to select a 3d object with the mouse.
◆ Camera()
Creates a degenerate camera.
All of the matrices are the identity and the viewport is empty.
◆ ~Camera()
cugl::Camera::~Camera |
( |
| ) |
|
|
inline |
Deletes this camera, disposing all resources.
◆ dispose()
virtual void cugl::Camera::dispose |
( |
| ) |
|
|
virtual |
◆ getCombined()
const Mat4& cugl::Camera::getCombined |
( |
| ) |
const |
|
inline |
Returns the combined projection and view matrix
- Returns
- the combined projection and view matrix
◆ getDirection()
const Vec3 cugl::Camera::getDirection |
( |
| ) |
const |
|
inline |
Returns the unit length direction vector of the camera
- Returns
- the unit length direction vector of the camera
◆ getFar()
float cugl::Camera::getFar |
( |
| ) |
const |
|
inline |
Returns the far clipping plane distance (has to be positive)
- Returns
- the far clipping plane distance (has to be positive)
◆ getInverseProjectView()
const Mat4& cugl::Camera::getInverseProjectView |
( |
| ) |
const |
|
inline |
Returns the combined projection and view matrix
- Returns
- the combined projection and view matrix
◆ getNear()
float cugl::Camera::getNear |
( |
| ) |
const |
|
inline |
Returns the near clipping plane distance (has to be positive)
- Returns
- the near clipping plane distance (has to be positive)
◆ getPickRay() [1/2]
Ray cugl::Camera::getPickRay |
( |
const Vec3 |
windowCoords | ) |
const |
Returns a picking Ray from the coordinates given in window coordinates.
A picking ray is used to select an object in 3d space. It creates a ray into the screen based on a selection in the viewport. You can then use this ray to select an object.
Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while window coordinates still have the origin in the bottom left.
While the viewport is a flat 2d plane, this method still takes a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
windowCoords | The point in window coordinates |
Returns a picking Ray from the coordinates given in window coordinates.
◆ getPickRay() [2/2]
Ray cugl::Camera::getPickRay |
( |
const Vec3 |
windowCoords, |
|
|
const Rect |
viewport |
|
) |
| const |
Returns a picking Ray from the coordinates given in window coordinates.
A picking ray is used to select an object in 3d space. It creates a ray into the screen based on a selection in the viewport. You can then use this ray to select an object.
Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while window coordinates still have the origin in the bottom left.
While the viewport is a flat 2d plane, this method still takes a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
windowCoords | The point in window coordinates |
viewport | The screen viewport |
Returns a picking Ray from the coordinates given in window coordinates.
◆ getPickRayFromScreen()
Ray cugl::Camera::getPickRayFromScreen |
( |
const Vec2 |
screenCoords | ) |
const |
|
inline |
Returns a picking Ray from the coordinates given in screen coordinates.
A picking ray is used to select an object in 3d space. It creates a ray into the screen based on a selection in the viewport. You can then use this ray to select an object.
Screen coords differ from window coordinates, as the the origin is in the top left instad of the bottom left. The SDL event system uses screen space for input events, which is why this method is necessary.
- Parameters
-
screenCoords | The point in screen coordinates |
Returns a picking Ray from the coordinates given in screen coordinates.
◆ getPosition()
const Vec3 cugl::Camera::getPosition |
( |
| ) |
const |
|
inline |
Returns the position of the camera
- Returns
- the position of the camera
◆ getProjection()
const Mat4& cugl::Camera::getProjection |
( |
| ) |
const |
|
inline |
Returns the projection matrix
- Returns
- the projection matrix
◆ getUp()
const Vec3 cugl::Camera::getUp |
( |
| ) |
const |
|
inline |
Returns the unit length up vector of the camera
- Returns
- the unit length up vector of the camera
◆ getView()
const Mat4& cugl::Camera::getView |
( |
| ) |
const |
|
inline |
Returns the view matrix
- Returns
- the view matrix
◆ getViewport()
const Rect cugl::Camera::getViewport |
( |
| ) |
const |
|
inline |
Returns the viewport
The viewport represents the "screen space". However, it is not actually screen space because the origin is still in the bottom left corner. So we call ir Window space instead.
- Returns
- the viewport size
◆ lookAt() [1/2]
void cugl::Camera::lookAt |
( |
const Vec3 |
target | ) |
|
Sets the direction of the camera to look at the given point.
This function assumes the up vector is normalized.
- Parameters
-
target | The point to look at |
◆ lookAt() [2/2]
void cugl::Camera::lookAt |
( |
float |
x, |
|
|
float |
y, |
|
|
float |
z |
|
) |
| |
|
inline |
Sets the direction of the camera to look at the given point.
This function assumes the up vector is normalized.
- Parameters
-
x | The x-coordinate of the point to look at |
y | The y-coordinate of the point to look at |
z | The z-coordinate of the point to look at |
◆ normalizeUp()
void cugl::Camera::normalizeUp |
( |
| ) |
|
|
inline |
Normalizes the up vector to be orthogonal to direction.
This method first calculats the right vector via a cross product between direction and up. Then it recalculates the up vector via a cross product between right and direction.
◆ project() [1/2]
Vec3 cugl::Camera::project |
( |
const Vec3 |
worldCoords | ) |
const |
Returns the window space equivalent of a point in world coordinates.
This is the same as GLU gluProject. Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while
While the viewport is a flat 2d plane, this method still returns a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
worldCoords | The point in wprld coordinates |
- Returns
- the window space equivalent of a point in world coordinates.
◆ project() [2/2]
Vec3 cugl::Camera::project |
( |
const Vec3 |
worldCoords, |
|
|
const Rect |
viewport |
|
) |
| const |
Returns the window space equivalent of a point in world coordinates.
This is the same as GLU gluProject. Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while
While the viewport is a flat 2d plane, this method still returns a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
worldCoords | The point in world coordinates |
viewport | The screen viewport |
- Returns
- the window space equivalent of a point in world coordinates.
◆ rotate() [1/4]
void cugl::Camera::rotate |
( |
const Mat4 & |
transform | ) |
|
|
inline |
Rotates the direction and up vector of this camera by the given matrix.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
The translational and scaling components of the matrix will be ignored.
- Parameters
-
transform | The rotation matrix |
◆ rotate() [2/4]
void cugl::Camera::rotate |
( |
const Quaternion & |
quat | ) |
|
|
inline |
Rotates the direction and up vector by the given Quaternion
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
quat | The rotation quaternion. |
◆ rotate() [3/4]
void cugl::Camera::rotate |
( |
const Vec3 |
axis, |
|
|
float |
angle |
|
) |
| |
|
inline |
Rotates the direction and up vector by the given angle around the given axis.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
axis | The axis to rotate about. |
angle | The angle (in radians). |
◆ rotate() [4/4]
void cugl::Camera::rotate |
( |
float |
angle | ) |
|
|
inline |
Rotates the camera by the given angle around the direction vector.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
angle | The angle (in radians). |
◆ rotateAround()
void cugl::Camera::rotateAround |
( |
const Vec3 |
point, |
|
|
const Vec3 |
axis, |
|
|
float |
angle |
|
) |
| |
Rotates the direction and up vector by the given angle around the given axis.
This version of the method assumes the axis is attached to the given point.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
point | The point to attach the axis to |
axis | The axis to rotate about. |
angle | The angle (in radians). |
◆ rotateX()
void cugl::Camera::rotateX |
( |
float |
angle | ) |
|
|
inline |
Rotates the direction and up vectod by the given angle around the x-axis.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
angle | The angle (in radians). |
◆ rotateY()
void cugl::Camera::rotateY |
( |
float |
angle | ) |
|
|
inline |
Rotates the direction and up vectod by the given angle around the z-axis.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
angle | The angle (in radians). |
◆ rotateZ()
void cugl::Camera::rotateZ |
( |
float |
angle | ) |
|
|
inline |
Rotates the direction and up vectod by the given angle around the z-axis.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
angle | The angle (in radians). |
◆ screenToWindowCoords() [1/2]
Vec3 cugl::Camera::screenToWindowCoords |
( |
const Vec2 |
screenCoords | ) |
const |
Returns the screen space equivalent of a point in window coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
We need this conversion because events (such as mouse clicks) register in screen space, while drawing happens in window space.
While the viewport is a flat 2d plane, this method still takes a 3d point. The z-coordinate corresponds to the near position, closest to the screen.
- Parameters
-
screenCoords | The point in screen coordinates |
◆ screenToWindowCoords() [2/2]
Vec3 cugl::Camera::screenToWindowCoords |
( |
const Vec2 |
screenCoords, |
|
|
const Rect |
viewport |
|
) |
| const |
Returns the screen space equivalent of a point in window coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
We need this conversion because events (such as mouse clicks) register in screen space, while drawing happens in window space.
While the viewport is a flat 2d plane, this method still takes a 3d point. The z-coordinate corresponds to the near position, closest to the screen.
- Parameters
-
screenCoords | The point in screen coordinates |
viewport | The screen viewport |
◆ screenToWorldCoords()
Vec3 cugl::Camera::screenToWorldCoords |
( |
const Vec2 |
screenCoords | ) |
const |
|
inline |
Returns the world space equivalent of a point in screen coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
In computing the world space coordinates, this method assumes that the z-value of the original vector is the same as near, which is the closest it can be the screen.
This method is important for converting event coordinates (such as a mouse click) to world coordinates.
- Parameters
-
screenCoords | The point in screen coordinates |
- Returns
- the world space equivalent of a point in screen coordinates.
◆ setFar()
void cugl::Camera::setFar |
( |
float |
value | ) |
|
|
inline |
Sets the far clipping plane distance (has to be positive)
Changing this value will have no effect on the underlying matrices until you call the update() method.
- Parameters
-
value | The far clipping plane distance (has to be positive) |
◆ setNear()
void cugl::Camera::setNear |
( |
float |
value | ) |
|
|
inline |
Sets the near clipping plane distance (has to be positive)
Changing this value will have no effect on the underlying matrices until you call the update() method.
- Parameters
-
value | The near clipping plane distance (has to be positive) |
◆ transform()
void cugl::Camera::transform |
( |
const Mat4 & |
transform | ) |
|
|
inline |
Transforms the position, direction and up vector by the given matrix
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
transform | The transform matrix |
◆ translate() [1/4]
void cugl::Camera::translate |
( |
const Vec2 |
vec | ) |
|
|
inline |
Moves the camera by the given vector.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
vec | The displacement vector |
◆ translate() [2/4]
void cugl::Camera::translate |
( |
const Vec3 |
vec | ) |
|
|
inline |
Moves the camera by the given vector.
- Parameters
-
vec | The displacement vector |
◆ translate() [3/4]
void cugl::Camera::translate |
( |
float |
tx, |
|
|
float |
ty |
|
) |
| |
|
inline |
Moves the camera by the given vector.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
tx | The displacement on the x-axis |
ty | The displacement on the y-axis |
◆ translate() [4/4]
void cugl::Camera::translate |
( |
float |
tx, |
|
|
float |
ty, |
|
|
float |
tz |
|
) |
| |
|
inline |
Moves the camera by the given vector.
You must call update() for the view matrix to be updated. The direction and up vector will not be orthogonalized until you call update().
- Parameters
-
tx | The displacement on the x-axis |
ty | The displacement on the y-axis |
tz | The displacement on the z-axis |
◆ unproject() [1/2]
Vec3 cugl::Camera::unproject |
( |
const Vec3 |
windowCoords | ) |
const |
Returns the world space equivalent of a point in window coordinates.
This is the same as GLU gluUnProject, but does not rely on OpenGL. Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while Window coordinates still have the origin in the bottom left.
While the viewport is a flat 2d plane, this method still requires a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
windowCoords | The point in window coordinates |
- Returns
- the world space equivalent of a point in window coordinates.
◆ unproject() [2/2]
Vec3 cugl::Camera::unproject |
( |
const Vec3 |
windowCoords, |
|
|
const Rect |
viewport |
|
) |
| const |
Returns the world space equivalent of a point in window coordinates.
This is the same as GLU gluUnProject, but does not rely on OpenGL. Window coords are the location of the point in the viewport. Ideally, the viewport should be the same size as the screen, but these are not screen coordinates. The screen has the origin in the top left, while Window coordinates still have the origin in the bottom left.
While the viewport is a flat 2d plane, this method still requires a 3d point. The z-coordinate corresponds to the position of the point in the z-buffer.
- Parameters
-
windowCoords | The point in window coordinates |
viewport | The screen viewport |
- Returns
- the world space equivalent of a point in window coordinates.
◆ update()
virtual void cugl::Camera::update |
( |
| ) |
|
|
pure virtual |
◆ windowToScreenCoords() [1/2]
Vec2 cugl::Camera::windowToScreenCoords |
( |
const Vec3 |
windowCoords | ) |
const |
Returns the window space equivalent of a point in screen coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
We need this conversion because events (such as mouse clicks) register in screen space, while drawing happens in window space.
- Parameters
-
windowCoords | The point in window coordinates |
◆ windowToScreenCoords() [2/2]
Vec2 cugl::Camera::windowToScreenCoords |
( |
const Vec3 |
windowCoords, |
|
|
const Rect |
viewport |
|
) |
| const |
Returns the window space equivalent of a point in screen coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
We need this conversion because events (such as mouse clicks) register in screen space, while drawing happens in window space.
- Parameters
-
windowCoords | The point in window coordinates |
viewport | The screen viewport |
◆ worldToScreenCoords()
Vec2 cugl::Camera::worldToScreenCoords |
( |
const Vec3 |
worldCoords | ) |
const |
|
inline |
Returns the screen space equivalent of a point in world coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
This method is important for converting world coordinates to event coordinates (such as a mouse click).
- Parameters
-
worldCoords | The point in wprld coordinates |
- Returns
- the screen space equivalent of a point in world coordinates.
◆ _combined
Mat4 cugl::Camera::_combined |
|
protected |
The combined projection and view matrix
◆ _direction
Vec3 cugl::Camera::_direction |
|
protected |
The unit length direction vector of the camera
◆ _far
The far clipping plane distance, has to be positive
◆ _inverse
Mat4 cugl::Camera::_inverse |
|
protected |
The inverse of the combined projection and view matrix
◆ _modelview
Mat4 cugl::Camera::_modelview |
|
protected |
◆ _near
float cugl::Camera::_near |
|
protected |
The near clipping plane distance, has to be positive
◆ _position
Vec3 cugl::Camera::_position |
|
protected |
The position of the camera
◆ _projection
Mat4 cugl::Camera::_projection |
|
protected |
◆ _upwards
Vec3 cugl::Camera::_upwards |
|
protected |
The unit length up vector of the camera
◆ _viewport
Rect cugl::Camera::_viewport |
|
protected |
The documentation for this class was generated from the following file: