CEDRIC  Revision_backup-2009-02
Classes | Public Types | Signals | Public Member Functions | Protected Member Functions | List of all members
MyCamera Class Reference

Manage modelview and projection, allows switching between ORTHOGRAPHIC and PERSPECTIVE projection. More...

#include <MyCamera.h>

Inheritance diagram for MyCamera:

Classes

struct  Frustum
 Viewing frustum. More...
 

Public Types

enum  Projection { ORTHOGRAPHIC, PERSPECTIVE }
 Supported projection modes. More...
 

Signals

void myCameraChanged ()
 
void myCameraChanged (MyCamera *)
 

Public Member Functions

 MyCamera ()
 Default constructor. More...
 
virtual ~MyCamera ()
 Destructor (does nothing) More...
 
 MyCamera (const MyCamera &other)
 Copy constructor. More...
 
MyCamera & operator= (const MyCamera &other)
 Copy assignment. More...
 
void setLike (const MyCamera &other)
 Copy settings from another MyCamera. More...
 
void setProjection (int proj)
 Set either ORTHOGRAPHIC or PERSPECTIVE projection (default is PERSPECTIVE) More...
 
int getProjection () const
 Get current Projection setting. More...
 
void setFov (float fov)
 Set projection fov. More...
 
void setAspect (float aspect, bool autoComputeAspect=false)
 Set projection aspect ratio. More...
 
void setFovAspect (float fov, float aspect, bool autoComputeAspect=false)
 Set fov and aspect ratio simultaneous. More...
 
void enableAutoComputeAspect ()
 
bool isAutoComputeAspect () const
 
void setLookAt (osg::Vec3 eye, osg::Vec3 center, osg::Vec3 up)
 Set modelview (same syntax as gluLookAt) More...
 
void setDistance (float dist)
 Set distance between eye and center keeping center fix and moving eye along viewing direction ("north") More...
 
void setRotation (osg::Quat q)
 Set rotation (adjusts eye and up to match rotation, center stays fixed) More...
 
void setCenter (osg::Vec3 center)
 Only change center (rarely used, most times you want translate()) More...
 
void translate (osg::Vec3 t)
 Translate center. More...
 
void pan (float dx, float dy)
 Pan center in direction of rotated up and east vector. More...
 
void zoom (int x0, int y0, int x1, int y1)
 
void zoom (const osg::BoundingBox &bbox)
 HACK Under development! More...
 
void apply (osg::Camera *cam) const
 Apply our projection and modelview to a Camera. More...
 
float getFov () const
 Get field of view (in radians) More...
 
float getAspect () const
 Get aspect ratio. More...
 
osg::Quat rotation () const
 Get rotation. More...
 
float distance () const
 Get distance from eye to center. More...
 
osg::Vec3 los () const
 Get line-of-sight = center - eye. More...
 
osg::Vec3 north () const
 Get "north" vector = normalized(center - eye) More...
 
osg::Vec3 east () const
 Get "east" vector = cross product between north and up. More...
 
osg::Vec3 up () const
 Get up vector. More...
 
osg::Vec3 center () const
 Get center. More...
 
void getLookAt (osg::Vec3 &eye, osg::Vec3 &center, osg::Vec3 &up) const
 Get eye, center and up vector. More...
 
void updateView ()
 
void updateProj ()
 
void update ()
 Update modelview and projection of associated camera. More...
 
void associate (osg::Camera *cam)
 Associate single Camera which is updated everytime our modelview or projection changes. More...
 
osg::Camera * getCamera () const
 Get pointer to associated Camera (if any) More...
 
void setLikeCamera (osg::Camera *cam)
 Set projection and modelview like given Camera (NO IMPLEMENTATION YET) More...
 
void link (MyCamera *other)
 
void unlink (MyCamera *other)
 
void unlinkAll ()
 
void setFixedOrientation (bool fixed)
 
bool isFixedOrientation () const
 
osg::Vec3 unproject (int x, int y, osg::Camera *cam=0) const
 Get the world space coordinates (on a screen-parallel plane through center) of a pixel on screen. More...
 
osg::Matrixd getViewMatrix () const
 Provided for convenience use in MatrixManipulator classes (rarely used, OSG calls getInverseMatrix() for setting the modelview) More...
 
osg::Matrixd getInverseViewMatrix () const
 Provided for convenience use in MatrixManipulator classes (OSG uses this one for the modelview) More...
 

Protected Member Functions

Frustum makeFrustum () const
 Compute screen parallel plane through center matching fov, aspect and distance. More...
 
void disableNextUpdate ()
 

Detailed Description

Manage modelview and projection, allows switching between ORTHOGRAPHIC and PERSPECTIVE projection.

This class is intended as little helper to simplify implementation of MatrixManipulators which must work both in perspective and orthographic projection.

As nice feature a zoom() function is provided which takes screen coordinates as parameters and adjusts modelview and projection to fit selected screen region.

Note
Near/far planes are not handled with care because i allow osg to dynamically calculate near/far. This may be an issue if near/far planes are set by hand!
Author
Max Hermann <mhermann[at]mail.cern.ch>

Member Enumeration Documentation

Supported projection modes.

Enumerator
ORTHOGRAPHIC 

Orhographic projection mode.

PERSPECTIVE 

Perspective projection mode.

Constructor & Destructor Documentation

MyCamera::MyCamera ( )

Default constructor.

Sets default parameters:

  • fov 45 degree
  • aspect ratio 1.0 (1:1)
  • perspective projection
  • eye at (0,0,-1) looking at (0,0,0) with y-axis as up
  • auto.compute aspect enabled

References setLookAt().

virtual MyCamera::~MyCamera ( )
inlinevirtual

Destructor (does nothing)

MyCamera::MyCamera ( const MyCamera &  other)
inline

Copy constructor.

References setLike().

Member Function Documentation

void MyCamera::apply ( osg::Camera *  cam) const
void MyCamera::associate ( osg::Camera *  cam)
inline

Associate single Camera which is updated everytime our modelview or projection changes.

References update().

Referenced by MyCameraWidget::MyCameraWidget().

osg::Vec3 MyCamera::center ( ) const
inline
void MyCamera::disableNextUpdate ( )
inlineprotected
float MyCamera::distance ( ) const
inline
osg::Vec3 MyCamera::east ( ) const
inline

Get "east" vector = cross product between north and up.

References north().

Referenced by EventViewerWidget::adjustDistance(), EventViewerWidget::getRulerProjection(), pan(), and unproject().

void MyCamera::enableAutoComputeAspect ( )
inline

Enable aspect ratio auto computation (set aspect by hand with setAspect() to disable) Just takes the camera's viewport aspect ratio

float MyCamera::getAspect ( ) const
inline

Get aspect ratio.

Referenced by EventViewerWidget::adjustDistance(), and setLike().

osg::Camera* MyCamera::getCamera ( ) const
inline

Get pointer to associated Camera (if any)

Referenced by setLike().

float MyCamera::getFov ( ) const
inline

Get field of view (in radians)

Referenced by EventViewerWidget::adjustDistance(), and setLike().

osg::Matrixd MyCamera::getInverseViewMatrix ( ) const

Provided for convenience use in MatrixManipulator classes (OSG uses this one for the modelview)

References distance().

Referenced by apply(), and MyCameraManipulator::getInverseMatrix().

void MyCamera::getLookAt ( osg::Vec3 &  eye,
osg::Vec3 &  center,
osg::Vec3 &  up 
) const
inline

Get eye, center and up vector.

Parameters
[out]eye
[out]center
[out]up

Referenced by MyCameraManipulator::MyCameraManipulator(), setLike(), and EventViewerWidget::setViewHome().

int MyCamera::getProjection ( ) const
inline

Get current Projection setting.

Referenced by MyCameraWidget::getProjection(), and setLike().

osg::Matrixd MyCamera::getViewMatrix ( ) const

Provided for convenience use in MatrixManipulator classes (rarely used, OSG calls getInverseMatrix() for setting the modelview)

References distance().

Referenced by MyCameraManipulator::getMatrix().

bool MyCamera::isAutoComputeAspect ( ) const
inline

Referenced by setLike().

bool MyCamera::isFixedOrientation ( ) const
inline
void MyCamera::link ( MyCamera *  other)
osg::Vec3 MyCamera::los ( ) const
inline

Get line-of-sight = center - eye.

Referenced by distance().

MyCamera::Frustum MyCamera::makeFrustum ( ) const
protected

Compute screen parallel plane through center matching fov, aspect and distance.

References distance().

Referenced by apply(), and unproject().

void MyCamera::myCameraChanged ( )
signal

Referenced by update().

void MyCamera::myCameraChanged ( MyCamera *  )
signal
osg::Vec3 MyCamera::north ( ) const
inline

Get "north" vector = normalized(center - eye)

Referenced by east(), setDistance(), and zoom().

MyCamera& MyCamera::operator= ( const MyCamera &  other)
inline

Copy assignment.

void MyCamera::pan ( float  dx,
float  dy 
)

Pan center in direction of rotated up and east vector.

References east(), and translate().

Referenced by MyCameraManipulator::calcMovement().

osg::Quat MyCamera::rotation ( ) const
inline
void MyCamera::setAspect ( float  aspect,
bool  autoComputeAspect = false 
)
inline

Set projection aspect ratio.

References updateProj().

void MyCamera::setCenter ( osg::Vec3  center)
inline

Only change center (rarely used, most times you want translate())

References setLookAt().

void MyCamera::setDistance ( float  dist)
inline

Set distance between eye and center keeping center fix and moving eye along viewing direction ("north")

References north(), and updateView().

Referenced by EventViewerWidget::adjustDistance(), MyCameraManipulator::calcMovement(), and EventViewerWidget::setViewHome().

void MyCamera::setFixedOrientation ( bool  fixed)
inline
void MyCamera::setFov ( float  fov)
inline

Set projection fov.

References updateProj().

void MyCamera::setFovAspect ( float  fov,
float  aspect,
bool  autoComputeAspect = false 
)
inline

Set fov and aspect ratio simultaneous.

References updateProj().

void MyCamera::setLike ( const MyCamera &  other)
inline

Copy settings from another MyCamera.

References getAspect(), getCamera(), getFov(), getLookAt(), getProjection(), isAutoComputeAspect(), and rotation().

Referenced by MyCamera().

void MyCamera::setLikeCamera ( osg::Camera *  cam)

Set projection and modelview like given Camera (NO IMPLEMENTATION YET)

Todo:
Implementation
void MyCamera::setLookAt ( osg::Vec3  eye,
osg::Vec3  center,
osg::Vec3  up 
)

Set modelview (same syntax as gluLookAt)

References center(), and updateView().

Referenced by MyCamera(), setCenter(), and EventViewerWidget::setViewHome().

void MyCamera::setProjection ( int  proj)
inline

Set either ORTHOGRAPHIC or PERSPECTIVE projection (default is PERSPECTIVE)

References ORTHOGRAPHIC, PERSPECTIVE, and update().

Referenced by MyCameraWidget::setProjection().

void MyCamera::setRotation ( osg::Quat  q)

Set rotation (adjusts eye and up to match rotation, center stays fixed)

References distance(), and update().

Referenced by MyCameraManipulator::calcMovement().

void MyCamera::translate ( osg::Vec3  t)
inline
void MyCamera::unlink ( MyCamera *  other)
void MyCamera::unlinkAll ( )
inline
osg::Vec3 MyCamera::unproject ( int  x,
int  y,
osg::Camera *  cam = 0 
) const

Get the world space coordinates (on a screen-parallel plane through center) of a pixel on screen.

This function needs information about the current. If there isn't an associated Camera you can supply a pointer to one as last parameter.

Note
Parameter y mustn't be inverted.

References MyCamera::Frustum::bottom, east(), MyCamera::Frustum::left, makeFrustum(), MyCamera::Frustum::right, and MyCamera::Frustum::top.

Referenced by MyCameraWidget::mouseMoveEvent(), EventViewerWidget::updateRuler(), and zoom().

osg::Vec3 MyCamera::up ( ) const
inline

Get up vector.

Referenced by EventViewerWidget::getRulerProjection(), and update().

void MyCamera::update ( )
void MyCamera::updateProj ( )
inline

Update projection of associated camera Intended to do only needed update modelview OR projection. not implemented yet but calls just calls update() internally.

References update().

Referenced by setAspect(), setFov(), and setFovAspect().

void MyCamera::updateView ( )
inline

Update modelview of associated camera Intended to do only needed update modelview OR projection. not implemented yet but calls just calls update() internally.

References update().

Referenced by setDistance(), setLookAt(), and translate().

void MyCamera::zoom ( int  x0,
int  y0,
int  x1,
int  y1 
)

Zoom to screen region (keeps aspect ratio) Unprojects coordinates to screen parallel plane through center (see unproject()) and adjusts distance and center to fit selected region.

Note
Needs associated Camera for unproject() call.

References north(), unproject(), and update().

Referenced by EventViewerWidget::fitBoundingBox(), and MyCameraWidget::mouseReleaseEvent().

void MyCamera::zoom ( const osg::BoundingBox &  bbox)

HACK Under development!

References north(), and update().