Visualization LibraryA lightweight C++ OpenGL middleware for 2D/3D graphics |
[Home] [Tutorials] [All Classes] [Grouped Classes] |
Represents a virtual camera defining, among other things, the point of view from which scenes can be rendered. More...
#include <Camera.hpp>
Public Member Functions | |
| virtual const char * | className () |
| Returns the name of the class. | |
| Camera () | |
| Constructs a perspective projecting camera with FOV = 60.0, Near Plane = 0.05, Far Plane = 10000.0. | |
| void | computeNearFarOptimizedProjMatrix (const Sphere &scene_bounding_sphere) |
The near and far clipping planes are adjusted to fit the provided scene_bounding_sphere. | |
| void | computeFrustumPlanes () |
| Computes the Camera's frustum planes in world space. | |
| void | applyModelViewMatrix (const mat4 &model_matrix) const |
| Loads the GL_MODELVIEW matrix with the Camera's view matrix multiplied by the specified model matrix. | |
| void | applyViewMatrix () const |
| Loads the GL_MODELVIEW matrix with the Camera's view matrix. | |
| void | applyProjMatrix () const |
| Loads the GL_PROJECTION matrix with the Camera's projection matrix. | |
| Real | aspectRatio () const |
| Returns the aspect ratio computed as viewport()->width()/viewport()->height(). | |
| void | setFOV (Real fov) |
| The field of view of the camera. | |
| Real | fov () const |
| The field of view of the camera. | |
| void | setNearPlane (Real nearplane) |
| The near clipping plane. | |
| Real | nearPlane () const |
| The near clipping plane. | |
| void | setFarPlane (Real farplane) |
| The far clipping plane. | |
| Real | farPlane () const |
| The far clipping plane. | |
| void | setFrustum (const Frustum &frustum) |
| The view frustum of the camera used to perform frustum culling. | |
| const Frustum & | frustum () const |
| The view frustum of the camera used to perform frustum culling. | |
| Frustum & | frustum () |
| The view frustum of the camera used to perform frustum culling. | |
| void | setViewport (Viewport *viewport) |
| The viewport bound to a camera. | |
| Viewport * | viewport () |
| The viewport bound to a camera. | |
| const Viewport * | viewport () const |
| The viewport bound to a camera. | |
| void | followTransform (Transform *transform) |
| Bind the camera to a Transform. | |
| const Transform * | followedTransform () const |
| Returns the Transform bound to a camera. | |
| Transform * | followedTransform () |
| Returns the Transform bound to a camera. | |
| void | setViewMatrix (const mat4 &mat) |
| Sets the Camera's view matrix. | |
| const mat4 & | viewMatrix () const |
| The Camera's view matrix. | |
| void | setInverseViewMatrix (const mat4 &mat) |
| The camera's reference frame matrix, the inverse of the view matrix. | |
| const mat4 & | inverseViewMatrix () const |
| The camera's reference frame matrix, the inverse of the view matrix. | |
| void | setProjectionMatrix (const mat4 &mat) |
| The camera's projection matrix. | |
| const mat4 & | projectionMatrix () const |
| The camera's projection matrix. | |
| void | setProjectionAsPerspective () |
| Builds a perspective projection matrix for the Camera based on the Camera's and Viewport's settings. | |
| void | setProjectionAsPerspective (Real fov, Real near, Real far) |
| Builds a perspective projection matrix for the Camera based on the Camera's and Viewport's settings. | |
| void | setProjectionAsFrustum (Real left, Real right, Real bottom, Real top, Real near, Real far) |
| Builds a perspective projection matrix for the Camera based on the give frustum. | |
| void | setProjectionAsOrtho (Real offset=-0.5f) |
| Builds an orthographic projection matrix for the Camera based on the Camera's near/far planes and its Viewport's settings. | |
| void | setProjectionAsOrtho2D (Real offset=-0.5f) |
| Builds an orthographic projection matrix for the Camera based on its Viewport's settings. | |
| void | setViewMatrixAsLookAt (const vec3 &eye, const vec3 ¢er, const vec3 &up) |
| Setup the modelview transform of the camera based on look-at parameters. | |
| void | getViewMatrixAsLookAt (vec3 &eye, vec3 &look, vec3 &up, vec3 &right) const |
| Returns the look-at parameters of the modelview transform. | |
| bool | project (const vec4 &in_world, vec4 &out_viewp) const |
| Projects a vector from world coordinates to viewport coordinates. | |
| bool | unproject (const vec3 &in_viewp, vec4 &out_world) const |
| Unprojects a vector from viewport coordinates to world coordinates. | |
| bool | unproject (std::vector< vec3 > &points) const |
| Unprojects a set of points. | |
| Ray | computeRay (int viewp_x, int viewp_y) |
| Computes the ray passing through the point <viewp_x,viewp_y>. | |
| Frustum | computeRayFrustum (int viewp_x, int viewp_y) |
| Computes a 1 pixel wide frustum suitable to cull objects during ray intersection detection. | |
| void | adjustView (const AABB &aabb, const vec3 &dir, const vec3 &up, Real bias=1.0f) |
| Adjusts the camera position so that the given aabb can be properly viewed. | |
Protected Attributes | |
| mat4 | mViewMatrix |
| mat4 | mInverseViewMatrix |
| mat4 | mProjectionMatrix |
| ref< Viewport > | mViewport |
| Frustum | mFrustum |
| ref< Transform > | mFollowTransform |
| Real | mFOV |
| Real | mNearPlane |
| Real | mFarPlane |
Represents a virtual camera defining, among other things, the point of view from which scenes can be rendered.
Definition at line 50 of file Camera.hpp.
| Camera::Camera | ( | ) |
Constructs a perspective projecting camera with FOV = 60.0, Near Plane = 0.05, Far Plane = 10000.0.
Definition at line 46 of file Camera.cpp.
References farPlane(), fov(), vl::Matrix4< GLfloat >::getPerspective(), mFarPlane, mFOV, mFrustum, mNearPlane, mProjectionMatrix, mViewport, nearPlane(), vl::Frustum::planes(), and VL_DEBUG_SET_OBJECT_NAME.
| virtual const char* vl::Camera::className | ( | ) | [inline, virtual] |
Returns the name of the class.
Reimplemented from vl::Object.
Definition at line 53 of file Camera.hpp.
| void Camera::computeNearFarOptimizedProjMatrix | ( | const Sphere & | scene_bounding_sphere ) |
The near and far clipping planes are adjusted to fit the provided scene_bounding_sphere.
Optimizing the near and far clipping planes results in an optimized usage of the z-buffer with the consequence of minimizing possible z-fighting artifacts, thus enhancing the rendering quality.
Definition at line 98 of file Camera.cpp.
References vl::Sphere::center(), vl::Sphere::isNull(), vl::max(), mFarPlane, mNearPlane, vl::Sphere::radius(), setProjectionAsPerspective(), vl::Sphere::transformed(), viewMatrix(), and vl::Vector3< T_Scalar >::z().
Referenced by vl::Rendering::render().
| void Camera::computeFrustumPlanes | ( | ) |
Computes the Camera's frustum planes in world space.
If nearFarClippingPlanesOptimized() == true the near and far culling planes distances are respectively set to nearPlane() and farPlane().
Definition at line 155 of file Camera.cpp.
References vl::extractPlanes(), mFrustum, vl::Frustum::planes(), projectionMatrix(), and viewMatrix().
Referenced by vl::Rendering::render().
| void Camera::applyModelViewMatrix | ( | const mat4 & | model_matrix ) | const |
Loads the GL_MODELVIEW matrix with the Camera's view matrix multiplied by the specified model matrix.
Definition at line 58 of file Camera.cpp.
References vl::Matrix4< T_Scalar >::e(), vl::Matrix4< T_Scalar >::ptr(), viewMatrix(), VL_glLoadMatrix, and VL_glMultMatrix.
Referenced by vl::Light::apply().
| void Camera::applyViewMatrix | ( | ) | const |
Loads the GL_MODELVIEW matrix with the Camera's view matrix.
Definition at line 86 of file Camera.cpp.
References vl::Matrix4< T_Scalar >::e(), vl::Matrix4< T_Scalar >::ptr(), viewMatrix(), and VL_glLoadMatrix.
Referenced by vl::EdgeRenderer::renderLines(), and vl::EdgeRenderer::renderSolids().
| void Camera::applyProjMatrix | ( | ) | const |
Loads the GL_PROJECTION matrix with the Camera's projection matrix.
Definition at line 79 of file Camera.cpp.
References projectionMatrix(), and VL_glLoadMatrix.
Referenced by vl::EdgeRenderer::render().
| Real vl::Camera::aspectRatio | ( | ) | const [inline] |
Returns the aspect ratio computed as viewport()->width()/viewport()->height().
If viewport() == NULL the function returns 0.
Definition at line 83 of file Camera.hpp.
Referenced by setProjectionAsPerspective().
| void vl::Camera::setFOV | ( | Real | fov ) | [inline] |
The field of view of the camera.
Definition at line 93 of file Camera.hpp.
Referenced by setProjectionAsFrustum(), and setProjectionAsPerspective().
| Real vl::Camera::fov | ( | ) | const [inline] |
The field of view of the camera.
Definition at line 96 of file Camera.hpp.
Referenced by Camera(), and setProjectionAsPerspective().
| void vl::Camera::setNearPlane | ( | Real | nearplane ) | [inline] |
The near clipping plane.
Definition at line 100 of file Camera.hpp.
Referenced by setProjectionAsFrustum(), and setProjectionAsPerspective().
| Real vl::Camera::nearPlane | ( | ) | const [inline] |
The near clipping plane.
Definition at line 103 of file Camera.hpp.
Referenced by Camera(), setProjectionAsOrtho(), and setProjectionAsPerspective().
| void vl::Camera::setFarPlane | ( | Real | farplane ) | [inline] |
The far clipping plane.
Definition at line 107 of file Camera.hpp.
Referenced by setProjectionAsFrustum(), and setProjectionAsPerspective().
| Real vl::Camera::farPlane | ( | ) | const [inline] |
The far clipping plane.
Definition at line 110 of file Camera.hpp.
Referenced by Camera(), setProjectionAsOrtho(), and setProjectionAsPerspective().
| void vl::Camera::setFrustum | ( | const Frustum & | frustum ) | [inline] |
The view frustum of the camera used to perform frustum culling.
Definition at line 113 of file Camera.hpp.
| const Frustum& vl::Camera::frustum | ( | ) | const [inline] |
The view frustum of the camera used to perform frustum culling.
Definition at line 116 of file Camera.hpp.
Referenced by adjustView(), computeRayFrustum(), vl::SceneManagerPortals::extractVisibleActors(), vl::ActorTreeAbstract::extractVisibleActors(), and vl::Rendering::render().
| Frustum& vl::Camera::frustum | ( | ) | [inline] |
The view frustum of the camera used to perform frustum culling.
Definition at line 119 of file Camera.hpp.
| void vl::Camera::setViewport | ( | Viewport * | viewport ) | [inline] |
The viewport bound to a camera.
Definition at line 122 of file Camera.hpp.
| Viewport* vl::Camera::viewport | ( | ) | [inline] |
The viewport bound to a camera.
Definition at line 125 of file Camera.hpp.
Referenced by vl::Text::boundingRectTransformed(), vl::TrackballManipulator::computeVector(), vl::GhostCameraManipulator::enableEvent(), vl::PixelLODEvaluator::evaluate(), vl::TrackballManipulator::mouseDownEvent(), vl::TrackballManipulator::mouseMoveEvent(), vl::GhostCameraManipulator::mouseMoveEvent(), vl::Renderer::render(), vl::EdgeRenderer::render(), vl::DrawPixels::render_Implementation(), vl::Clear::render_Implementation(), vl::OcclusionCullRenderer::render_pass2(), vl::Text::renderBackground(), vl::Text::renderBorder(), vl::Text::renderText(), and vl::Applet::resizeEvent().
| const Viewport* vl::Camera::viewport | ( | ) | const [inline] |
The viewport bound to a camera.
Definition at line 128 of file Camera.hpp.
| void vl::Camera::followTransform | ( | Transform * | transform ) | [inline] |
Bind the camera to a Transform.
Definition at line 131 of file Camera.hpp.
| const Transform* vl::Camera::followedTransform | ( | ) | const [inline] |
Returns the Transform bound to a camera.
Definition at line 134 of file Camera.hpp.
| Transform* vl::Camera::followedTransform | ( | ) | [inline] |
Returns the Transform bound to a camera.
Definition at line 137 of file Camera.hpp.
| void vl::Camera::setViewMatrix | ( | const mat4 & | mat ) | [inline] |
Sets the Camera's view matrix.
Definition at line 140 of file Camera.hpp.
References vl::Matrix4< T_Scalar >::invert().
| const mat4& vl::Camera::viewMatrix | ( | ) | const [inline] |
The Camera's view matrix.
This is what you would pass to OpenGL with "glMatrixMode(GL_MODELVIEW);glLoadMatrix(camera.viewMatrix().ptr());"
Definition at line 143 of file Camera.hpp.
Referenced by adjustView(), vl::ClipPlane::apply(), applyModelViewMatrix(), applyViewMatrix(), computeFrustumPlanes(), computeNearFarOptimizedProjMatrix(), vl::PixelLODEvaluator::evaluate(), vl::SlicedVolume::onActorRenderStarted(), vl::EdgeUpdateCallback::onActorRenderStarted(), vl::DepthSortCallback::onActorRenderStarted(), vl::EdgeRenderer::renderLines(), vl::EdgeRenderer::renderSolids(), vl::RenderQueue::sort(), and vl::ProjViewTransfCallback::updateMatrices().
| void vl::Camera::setInverseViewMatrix | ( | const mat4 & | mat ) | [inline] |
The camera's reference frame matrix, the inverse of the view matrix.
Definition at line 146 of file Camera.hpp.
References vl::Matrix4< T_Scalar >::invert().
Referenced by adjustView(), vl::TrackballManipulator::mouseMoveEvent(), vl::Rendering::render(), setViewMatrixAsLookAt(), and vl::GhostCameraManipulator::updateEvent().
| const mat4& vl::Camera::inverseViewMatrix | ( | ) | const [inline] |
The camera's reference frame matrix, the inverse of the view matrix.
Definition at line 149 of file Camera.hpp.
Referenced by adjustView(), vl::TextureMatrix::apply(), computeRay(), vl::SceneManagerPortals::computeStartingSector(), vl::Billboard::computeWorldMatrix(), vl::GhostCameraManipulator::enableEvent(), vl::DistanceLODEvaluator::evaluate(), vl::SceneManagerPortals::extractVisibleActors(), vl::TrackballManipulator::mouseDownEvent(), vl::TrackballManipulator::mouseMoveEvent(), vl::OcclusionCullRenderer::render_pass2(), vl::TrackballManipulator::trackballRotation(), vl::GhostCameraManipulator::updateEvent(), vl::SlicedVolume::updateUniforms(), and vl::RaycastVolume::updateUniforms().
| void vl::Camera::setProjectionMatrix | ( | const mat4 & | mat ) | [inline] |
The camera's projection matrix.
Definition at line 155 of file Camera.hpp.
Referenced by setProjectionAsOrtho(), and setProjectionAsOrtho2D().
| const mat4& vl::Camera::projectionMatrix | ( | ) | const [inline] |
The camera's projection matrix.
Definition at line 158 of file Camera.hpp.
Referenced by adjustView(), applyProjMatrix(), computeFrustumPlanes(), vl::PixelLODEvaluator::evaluate(), and vl::ProjViewTransfCallback::updateMatrices().
| void Camera::setProjectionAsPerspective | ( | ) |
Builds a perspective projection matrix for the Camera based on the Camera's and Viewport's settings.
See also http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml for more information.
Definition at line 180 of file Camera.cpp.
References aspectRatio(), farPlane(), fov(), vl::Matrix4< GLfloat >::getPerspective(), mProjectionMatrix, and nearPlane().
Referenced by computeNearFarOptimizedProjMatrix(), and vl::Applet::resizeEvent().
Builds a perspective projection matrix for the Camera based on the Camera's and Viewport's settings.
See also http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml for more information.
Definition at line 172 of file Camera.cpp.
References aspectRatio(), vl::Matrix4< GLfloat >::getPerspective(), mProjectionMatrix, setFarPlane(), setFOV(), and setNearPlane().
| void Camera::setProjectionAsFrustum | ( | Real | left, |
| Real | right, | ||
| Real | bottom, | ||
| Real | top, | ||
| Real | near, | ||
| Real | far | ||
| ) |
Builds a perspective projection matrix for the Camera based on the give frustum.
See also http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml for more information.
Definition at line 164 of file Camera.cpp.
References vl::Matrix4< GLfloat >::getFrustum(), mProjectionMatrix, setFarPlane(), setFOV(), and setNearPlane().
| void Camera::setProjectionAsOrtho | ( | Real | offset = -0.5f ) |
Builds an orthographic projection matrix for the Camera based on the Camera's near/far planes and its Viewport's settings.
See also http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml for more information. Equivalent to:
setProjectionMatrix( mat4::getOrtho( offset, (Real)mViewport->width() + offset, offset, (Real)mViewport->height() + offset, nearPlane(), farPlane()) );
Definition at line 185 of file Camera.cpp.
References farPlane(), vl::Matrix4< GLfloat >::getOrtho(), mViewport, nearPlane(), and setProjectionMatrix().
| void Camera::setProjectionAsOrtho2D | ( | Real | offset = -0.5f ) |
Builds an orthographic projection matrix for the Camera based on its Viewport's settings.
See also http://www.opengl.org/sdk/docs/man/xhtml/glOrtho2D.xml for more information. Equivalent to:
setProjectionMatrix( mat4::getOrtho( offset, viewport()->width() + offset, offset, viewport()->height() + offset, -1, +1) );
Definition at line 195 of file Camera.cpp.
References vl::Matrix4< GLfloat >::getOrtho(), mViewport, and setProjectionMatrix().
Setup the modelview transform of the camera based on look-at parameters.
| eye | The position of the camera. |
| center | The point the camera is looking at. |
| up | The vector defining the up direction. |
Definition at line 205 of file Camera.cpp.
References vl::Matrix4< GLfloat >::getLookAt(), and setInverseViewMatrix().
Returns the look-at parameters of the modelview transform.
| eye | The position of the camera. |
| look | The direction the camera is looking at. |
| up | The vector defining the Y positive direction of the camera. |
| right | The vector defining the X positive direction of the camera. |
Definition at line 212 of file Camera.cpp.
References vl::Matrix4< T_Scalar >::getAsLookAt(), and mInverseViewMatrix.
Projects a vector from world coordinates to viewport coordinates.
Definition at line 217 of file Camera.cpp.
References mProjectionMatrix, mViewMatrix, mViewport, vl::Vector4< T_Scalar >::w(), vl::Vector4< T_Scalar >::x(), vl::Vector4< T_Scalar >::y(), and vl::Vector4< T_Scalar >::z().
Referenced by vl::Text::boundingRectTransformed(), vl::DrawPixels::render_Implementation(), and vl::Text::renderText().
Unprojects a vector from viewport coordinates to world coordinates.
| in_viewp | The viewport coordinates point to be projected. Note that, in accordance to OpenGL conventions, the viewport coordinates have the Y axis pointing upwards and origin at the bottom left corner of the viewport. |
| out_world | The world coordinates of the projected point. |
z coordinate of in_viewp determines the position of the projected point along the ray passing through in_viewp. If z equals 0 then out_world will lay on the near clipping plane, if z equals 1 then out_world will lay on the far clipping plane. Definition at line 239 of file Camera.cpp.
References mProjectionMatrix, mViewMatrix, mViewport, vl::Vector4< T_Scalar >::w(), vl::Vector3< T_Scalar >::x(), vl::Vector4< T_Scalar >::x(), vl::Vector3< T_Scalar >::y(), vl::Vector4< T_Scalar >::y(), vl::Vector3< T_Scalar >::z(), and vl::Vector4< T_Scalar >::z().
Referenced by computeRay(), and computeRayFrustum().
| bool Camera::unproject | ( | std::vector< vec3 > & | points ) | const |
Unprojects a set of points.
See unproject(const vec3& in_viewp, vec4& out_world) for more information.
Definition at line 269 of file Camera.cpp.
References mProjectionMatrix, mViewMatrix, mViewport, vl::Vector4< T_Scalar >::w(), vl::Vector4< T_Scalar >::x(), vl::Vector4< T_Scalar >::y(), and vl::Vector4< T_Scalar >::z().
| Ray Camera::computeRay | ( | int | viewp_x, |
| int | viewp_y | ||
| ) |
Computes the ray passing through the point <viewp_x,viewp_y>.
| viewp_x | The x position of the point defining the ray |
| viewp_y | The y position of the point defining the ray |
"opengl_y = window_height - coord_y". Definition at line 304 of file Camera.cpp.
References vl::Matrix4< T_Scalar >::getT(), inverseViewMatrix(), vl::normalize(), vl::Ray::setDirection(), vl::Ray::setOrigin(), unproject(), and vl::Vector4< T_Scalar >::xyz().
| Frustum Camera::computeRayFrustum | ( | int | viewp_x, |
| int | viewp_y | ||
| ) |
Computes a 1 pixel wide frustum suitable to cull objects during ray intersection detection.
Definition at line 318 of file Camera.cpp.
References vl::cross(), frustum(), vl::Frustum::planes(), unproject(), and vl::Vector4< T_Scalar >::xyz().
Adjusts the camera position so that the given aabb can be properly viewed.
| aabb | The AABB (in world coords) that should be visible from the newly computed camera position. |
| dir | The direction (in world coords) along which the camera should be displaced to view the given AABB. |
| up | The vector that defines the up direction (in world coords). Used to properly compute the new camera matrix. |
| bias | A bias factor used to adjust the computed camera distance from the given AABB. Values between 0 and 1 make the camera closer to the AABB center, values greater than 1 position the camera further away. |
Definition at line 122 of file Camera.cpp.
References vl::Log::bug(), vl::AABB::center(), vl::dot(), vl::extractPlanes(), frustum(), vl::Matrix4< GLfloat >::getLookAt(), vl::Matrix4< T_Scalar >::getT(), vl::Matrix4< T_Scalar >::getZ(), inverseViewMatrix(), vl::Plane::normal(), vl::Plane::origin(), vl::Frustum::plane(), vl::Frustum::planes(), projectionMatrix(), vl::Sphere::radius(), setInverseViewMatrix(), viewMatrix(), and VL_CHECK.
Referenced by vl::TrackballManipulator::adjustView().
mat4 vl::Camera::mViewMatrix [protected] |
Definition at line 244 of file Camera.hpp.
Referenced by project(), and unproject().
mat4 vl::Camera::mInverseViewMatrix [protected] |
Definition at line 245 of file Camera.hpp.
Referenced by getViewMatrixAsLookAt().
mat4 vl::Camera::mProjectionMatrix [protected] |
Definition at line 246 of file Camera.hpp.
Referenced by Camera(), project(), setProjectionAsFrustum(), setProjectionAsPerspective(), and unproject().
ref<Viewport> vl::Camera::mViewport [protected] |
Definition at line 247 of file Camera.hpp.
Referenced by Camera(), project(), setProjectionAsOrtho(), setProjectionAsOrtho2D(), and unproject().
Frustum vl::Camera::mFrustum [protected] |
Definition at line 248 of file Camera.hpp.
Referenced by Camera(), and computeFrustumPlanes().
ref<Transform> vl::Camera::mFollowTransform [protected] |
Definition at line 249 of file Camera.hpp.
Real vl::Camera::mFOV [protected] |
Definition at line 250 of file Camera.hpp.
Referenced by Camera().
Real vl::Camera::mNearPlane [protected] |
Definition at line 251 of file Camera.hpp.
Referenced by Camera(), and computeNearFarOptimizedProjMatrix().
Real vl::Camera::mFarPlane [protected] |
Definition at line 252 of file Camera.hpp.
Referenced by Camera(), and computeNearFarOptimizedProjMatrix().