|
KGLLib
|
#include <camera.h>
Public Member Functions | |
| virtual void | applyPerspective () |
| virtual void | applyView (bool reset=true) |
| virtual void | applyViewport () |
| void | setViewport (int x, int y, int width, int height) |
| void | setFoV (float fov) |
| void | setAspect (float aspect) |
| void | setDepthRange (float near, float far) |
| void | setPosition (const Eigen::Vector3f &pos) |
| void | setPosition (float x, float y, float z) |
| void | setLookAt (const Eigen::Vector3f &lookat) |
| void | setLookAt (float x, float y, float z) |
| void | setUp (const Eigen::Vector3f &up) |
| void | setUp (float x, float y, float z) |
| void | setDirection (const Eigen::Vector3f &dir) |
| void | setDirection (float x, float y, float z) |
| Eigen::Vector3f | position () const |
| Eigen::Vector3f | lookAt () const |
| Eigen::Vector3f | up () const |
| void | setModelviewMatrix (const Eigen::Transform3f &modelview) |
| void | setProjectionMatrix (const Eigen::Transform3f &projection) |
| Eigen::Transform3f | modelviewMatrix () const |
| Eigen::Transform3f | projectionMatrix () const |
| Eigen::Vector3f | project (const Eigen::Vector3f &v, bool *ok=0) const |
| Eigen::Vector3f | unProject (const Eigen::Vector3f &v, bool *ok=0) const |
Protected Member Functions | |
| void | recalculateModelviewMatrix () |
| void | recalculateProjectionMatrix () |
Protected Attributes | |
| Eigen::Vector3f | mPosition |
| Eigen::Vector3f | mLookAt |
| Eigen::Vector3f | mUp |
| float | mFoV |
| float | mAspect |
| float | mDepthNear |
| float | mDepthFar |
| Eigen::Transform3f | mModelviewMatrix |
| bool | mModelviewMatrixDirty |
| Eigen::Transform3f | mProjectionMatrix |
| bool | mProjectionMatrixDirty |
| int | mViewport [4] |
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.
| void KGLLib::Camera::applyPerspective | ( | ) | [virtual] |
Applies the camera's projection matrix.
Any current perspective transformations will be lost.
Referenced by KGLLib::GLWidget::resizeGL().
| void KGLLib::Camera::applyView | ( | bool | reset = true | ) | [virtual] |
Applies the camera's modelview matrix.
| reset | if true then glLoadIdentity() is called before applying. This ensures that current transformations won't affect the camera. |
Referenced by KGLLib::GLWidget::paintGL().
| void KGLLib::Camera::applyViewport | ( | ) | [virtual] |
Applies the viewport that has been specified using the setViewport method.
Referenced by KGLLib::GLWidget::resizeGL().
| Eigen::Transform3f KGLLib::Camera::modelviewMatrix | ( | ) | const |
| 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.
| Eigen::Transform3f KGLLib::Camera::projectionMatrix | ( | ) | const |
| void KGLLib::Camera::setAspect | ( | float | aspect | ) |
Sets the aspect ration to aspect. Aspect ratio is usually window's width divided by its height.
Referenced by KGLLib::GLWidget::resizeGL().
| 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.
Referenced by KGLLib::GLWidget::initializeGL().
| 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.
| void KGLLib::Camera::setFoV | ( | float | fov | ) |
Sets the vertical field-of-view angle in degrees to fov.
| 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.
Referenced by KGLLib::GLWidget::initializeGL().
| void KGLLib::Camera::setModelviewMatrix | ( | const Eigen::Transform3f & | 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.
| void KGLLib::Camera::setPosition | ( | const Eigen::Vector3f & | pos | ) |
Sets the camera's positionto pos.
Referenced by KGLLib::GLWidget::initializeGL().
| void KGLLib::Camera::setProjectionMatrix | ( | const Eigen::Transform3f & | 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.
| void KGLLib::Camera::setUp | ( | const Eigen::Vector3f & | up | ) |
Sets the up vector to up. Up vector is the one pointing upwards in the viewport.
Referenced by KGLLib::GLWidget::initializeGL().
| void KGLLib::Camera::setViewport | ( | int | x, |
| int | y, | ||
| int | width, | ||
| int | height | ||
| ) |
Specifies the current viewport.
Referenced by KGLLib::GLWidget::resizeGL().
| 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.
1.7.4