• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWin

KGLLib::Camera

KGLLib::Camera Class Reference

#include <camera.h>

List of all members.


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::Vector3f KGLLib::Camera::lookAt (  )  const [inline]

Definition at line 140 of file camera.h.

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]

Definition at line 139 of file camera.h.

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]

Definition at line 137 of file camera.h.

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  ) 

Sets the vertical field-of-view angle in degrees to fov.

Definition at line 62 of file camera.cpp.

void KGLLib::Camera::setLookAt ( float  x,
float  y,
float  z 
) [inline]

Definition at line 124 of file camera.h.

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]

Definition at line 118 of file camera.h.

void KGLLib::Camera::setPosition ( const Eigen::Vector3f &  pos  ) 

Sets the camera's positionto pos.

Definition at line 81 of file camera.cpp.

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]

Definition at line 130 of file camera.h.

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 
)

Specifies the current viewport.

Definition at line 104 of file camera.cpp.

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.

Eigen::Vector3f KGLLib::Camera::up (  )  const [inline]

Definition at line 141 of file camera.h.


Member Data Documentation

float KGLLib::Camera::mAspect [protected]

Definition at line 207 of file camera.h.

float KGLLib::Camera::mDepthFar [protected]

Definition at line 207 of file camera.h.

float KGLLib::Camera::mDepthNear [protected]

Definition at line 207 of file camera.h.

float KGLLib::Camera::mFoV [protected]

Definition at line 207 of file camera.h.

Eigen::Vector3f KGLLib::Camera::mLookAt [protected]

Definition at line 205 of file camera.h.

Eigen::MatrixP3f KGLLib::Camera::mModelviewMatrix [protected]

Definition at line 209 of file camera.h.

bool KGLLib::Camera::mModelviewMatrixDirty [protected]

Definition at line 210 of file camera.h.

Eigen::Vector3f KGLLib::Camera::mPosition [protected]

Definition at line 204 of file camera.h.

Eigen::MatrixP3f KGLLib::Camera::mProjectionMatrix [protected]

Definition at line 211 of file camera.h.

bool KGLLib::Camera::mProjectionMatrixDirty [protected]

Definition at line 212 of file camera.h.

Eigen::Vector3f KGLLib::Camera::mUp [protected]

Definition at line 206 of file camera.h.

int KGLLib::Camera::mViewport[4] [protected]

Definition at line 213 of file camera.h.


The documentation for this class was generated from the following files:
  • camera.h
  • camera.cpp

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal