KWin
KGLLib::Camera Class Reference
#include <camera.h>
Detailed Description
Camera class.Camera represents a virtual camera that can be used to view a scene.
Camera's parameters can be specified in two ways: Usually you will use the setPosition, setUp and either setLookAt or setDirection to set up camera position. The perspective transformation is specified using setFoV, setAspect and setDepthRange methods.
Alternatively, you can specify the modelview and projection matrices directly, using setModelviewMatrix and setProjectionMatrix methods.
You can also use one way for the modelview matrix and another way for the projection matrix. You can't mix the two modes though. If you use setModelviewMatrix() and then setPosition() then the setModelviewMatrix() call has no effect and modelview matrix will be calculated using specified position, lookat and up vectors.
Camera also takes care of viewport handling. Instead of calling glViewport() directly, you should use setViewport() and applyViewport() methods.
Finally, Camera has project() and unProject() methods for projecting points from world coordinates to window coordinates and vice versa. Obviously it only works if you don't modify OpenGL matrices or viewport manually but use the methods of this class instead.
Definition at line 61 of file camera.h.
Public Member Functions | |
| virtual void | applyPerspective () |
| virtual void | applyView (bool reset=true) |
| virtual void | applyViewport () |
| Camera () | |
| Eigen::Vector3f | lookAt () const |
| Eigen::MatrixP3f | modelviewMatrix () const |
| Eigen::Vector3f | position () const |
| Eigen::Vector3f | project (const Eigen::Vector3f &v, bool *ok=0) const |
| Eigen::MatrixP3f | projectionMatrix () const |
| void | setAspect (float aspect) |
| void | setDepthRange (float near, float far) |
| void | setDirection (float x, float y, float z) |
| void | setDirection (const Eigen::Vector3f &dir) |
| void | setFoV (float fov) |
| void | setLookAt (float x, float y, float z) |
| void | setLookAt (const Eigen::Vector3f &lookat) |
| void | setModelviewMatrix (const Eigen::MatrixP3f &modelview) |
| void | setPosition (float x, float y, float z) |
| void | setPosition (const Eigen::Vector3f &pos) |
| void | setProjectionMatrix (const Eigen::MatrixP3f &projection) |
| void | setUp (float x, float y, float z) |
| void | setUp (const Eigen::Vector3f &up) |
| void | setViewport (int x, int y, int width, int height) |
| Eigen::Vector3f | unProject (const Eigen::Vector3f &v, bool *ok=0) const |
| Eigen::Vector3f | up () const |
| virtual | ~Camera () |
Protected Member Functions | |
| void | recalculateModelviewMatrix () |
| void | recalculateProjectionMatrix () |
Protected Attributes | |
| float | mAspect |
| float | mDepthFar |
| float | mDepthNear |
| float | mFoV |
| Eigen::Vector3f | mLookAt |
| Eigen::MatrixP3f | mModelviewMatrix |
| bool | mModelviewMatrixDirty |
| Eigen::Vector3f | mPosition |
| Eigen::MatrixP3f | mProjectionMatrix |
| bool | mProjectionMatrixDirty |
| Eigen::Vector3f | mUp |
| int | mViewport [4] |
Constructor & Destructor Documentation
| KGLLib::Camera::Camera | ( | ) |
Definition at line 45 of file camera.cpp.
| KGLLib::Camera::~Camera | ( | ) | [virtual] |
Definition at line 58 of file camera.cpp.
Member Function Documentation
| void KGLLib::Camera::applyPerspective | ( | ) | [virtual] |
Applies the camera's projection matrix.
Any current perspective transformations will be lost.
Definition at line 112 of file camera.cpp.
| void KGLLib::Camera::applyView | ( | bool | reset = true |
) | [virtual] |
Applies the camera's modelview matrix.
- Parameters:
-
reset if true then glLoadIdentity() is called before applying. This ensures that current transformations won't affect the camera.
Definition at line 124 of file camera.cpp.
| void KGLLib::Camera::applyViewport | ( | ) | [virtual] |
Applies the viewport that has been specified using the setViewport method.
Definition at line 136 of file camera.cpp.
| Eigen::MatrixP3f KGLLib::Camera::modelviewMatrix | ( | ) | const |
- Returns:
- current modelview matrix.
Modelview matrix is either set using the setModelviewMatrix method or automatically calculated using position, lookAt and up vectors.
Definition at line 200 of file camera.cpp.
| Eigen::Vector3f KGLLib::Camera::position | ( | ) | const [inline] |
| Eigen::Vector3f KGLLib::Camera::project | ( | const Eigen::Vector3f & | v, | |
| bool * | ok = 0 | |||
| ) | const |
Transforms vector v from world coordinates to window coordinates.
If ok is not null then it will be set to true or false depending on whether the projection was successful or not.
Definition at line 216 of file camera.cpp.
| Eigen::MatrixP3f KGLLib::Camera::projectionMatrix | ( | ) | const |
- Returns:
- current projection matrix.
Projection matrix is either set using the setProjectionMatrix method or automatically calculated using fov, aspect and depth range parameters.
Definition at line 208 of file camera.cpp.
| void KGLLib::Camera::recalculateModelviewMatrix | ( | ) | [protected] |
Definition at line 141 of file camera.cpp.
| void KGLLib::Camera::recalculateProjectionMatrix | ( | ) | [protected] |
Definition at line 166 of file camera.cpp.
| void KGLLib::Camera::setAspect | ( | float | aspect | ) |
Sets the aspect ration to aspect.
Aspect ratio is usually window's width divided by its height.
Definition at line 68 of file camera.cpp.
| void KGLLib::Camera::setDepthRange | ( | float | near, | |
| float | far | |||
| ) |
Sets the depth buffer's range.
near is distance from the camera to the near clipping plane and far is distance to the far clipping plane. Everything that is not between those two planes will be clipped away (not rendered), so you should make sure that all your objects are within that range. At the same time, the depth range should be as small as possible (i.e. near should be as big and far as small as possible) to increase depth buffer precision.
Definition at line 74 of file camera.cpp.
| void KGLLib::Camera::setDirection | ( | float | x, | |
| float | y, | |||
| float | z | |||
| ) | [inline] |
| void KGLLib::Camera::setDirection | ( | const Eigen::Vector3f & | dir | ) |
Sets the viewing direction of the camera to dir.
This method sets lookat point to position() + dir, thus you will need to set camera's position before using this method.
Definition at line 99 of file camera.cpp.
| void KGLLib::Camera::setFoV | ( | float | fov | ) |
| void KGLLib::Camera::setLookAt | ( | float | x, | |
| float | y, | |||
| float | z | |||
| ) | [inline] |
| void KGLLib::Camera::setLookAt | ( | const Eigen::Vector3f & | lookat | ) |
Sets the lookat point to lookat.
LookAt is the point at which the camera is looking at.
Definition at line 87 of file camera.cpp.
| void KGLLib::Camera::setModelviewMatrix | ( | const Eigen::MatrixP3f & | modelview | ) |
Sets the modelview matrix.
If you specify the modelview matrix using this method then parameters specified using setPosition, setLookAt and setUp methods will be ignored.
If you call any of setPosition, setLookAt or setUp after calling this method, then the modelview matrix specified here will be ignored and new modelview matrix will be calculated using specified position, lookat and up vectors.
Definition at line 188 of file camera.cpp.
| void KGLLib::Camera::setPosition | ( | float | x, | |
| float | y, | |||
| float | z | |||
| ) | [inline] |
| void KGLLib::Camera::setPosition | ( | const Eigen::Vector3f & | pos | ) |
| void KGLLib::Camera::setProjectionMatrix | ( | const Eigen::MatrixP3f & | projection | ) |
Sets the projection matrix.
If you specify the projection matrix using this method then parameters specified using setFoV, setAspect and setDepthRange methods will be ignored.
If you call any of setFoV, setAspect or setDepthRange after calling this method, then the projection matrix specified here will be ignored and new projection matrix will be calculated using specified fov, aspect and depth range parameters.
Definition at line 194 of file camera.cpp.
| void KGLLib::Camera::setUp | ( | float | x, | |
| float | y, | |||
| float | z | |||
| ) | [inline] |
| void KGLLib::Camera::setUp | ( | const Eigen::Vector3f & | up | ) |
Sets the up vector to up.
Up vector is the one pointing upwards in the viewport.
Definition at line 93 of file camera.cpp.
| void KGLLib::Camera::setViewport | ( | int | x, | |
| int | y, | |||
| int | width, | |||
| int | height | |||
| ) |
| Eigen::Vector3f KGLLib::Camera::unProject | ( | const Eigen::Vector3f & | v, | |
| bool * | ok = 0 | |||
| ) | const |
Transforms vector v from window coordinates to world coordinates.
If ok is not null then it will be set to true or false depending on whether the projection was successful or not.
Definition at line 233 of file camera.cpp.
Member Data Documentation
float KGLLib::Camera::mAspect [protected] |
float KGLLib::Camera::mDepthFar [protected] |
float KGLLib::Camera::mDepthNear [protected] |
float KGLLib::Camera::mFoV [protected] |
Eigen::Vector3f KGLLib::Camera::mLookAt [protected] |
Eigen::MatrixP3f KGLLib::Camera::mModelviewMatrix [protected] |
bool KGLLib::Camera::mModelviewMatrixDirty [protected] |
Eigen::Vector3f KGLLib::Camera::mPosition [protected] |
Eigen::MatrixP3f KGLLib::Camera::mProjectionMatrix [protected] |
bool KGLLib::Camera::mProjectionMatrixDirty [protected] |
Eigen::Vector3f KGLLib::Camera::mUp [protected] |
int KGLLib::Camera::mViewport[4] [protected] |
The documentation for this class was generated from the following files:
KDE 4.2 API Reference