|
CEDRIC
Revision_backup-2009-02
|
Manage modelview and projection, allows switching between ORTHOGRAPHIC and PERSPECTIVE projection. More...
#include <MyCamera.h>
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 ¢er, 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 () |
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.
| enum MyCamera::Projection |
| MyCamera::MyCamera | ( | ) |
Default constructor.
Sets default parameters:
References setLookAt().
|
inlinevirtual |
Destructor (does nothing)
| void MyCamera::apply | ( | osg::Camera * | cam | ) | const |
Apply our projection and modelview to a Camera.
References MyCamera::Frustum::bottom, getInverseViewMatrix(), MyCamera::Frustum::left, makeFrustum(), ORTHOGRAPHIC, MyCamera::Frustum::right, and MyCamera::Frustum::top.
Referenced by update().
|
inline |
Associate single Camera which is updated everytime our modelview or projection changes.
References update().
Referenced by MyCameraWidget::MyCameraWidget().
|
inline |
Get center.
Referenced by EventViewerWidget::adjustCenter(), setLookAt(), EventViewerWidget::setViewMode(), and update().
|
inlineprotected |
|
inline |
Get distance from eye to center.
References los().
Referenced by MyCameraManipulator::calcMovement(), getInverseViewMatrix(), getViewMatrix(), makeFrustum(), setRotation(), EventViewerWidget::setViewHome(), and update().
|
inline |
Get "east" vector = cross product between north and up.
References north().
Referenced by EventViewerWidget::adjustDistance(), EventViewerWidget::getRulerProjection(), pan(), and unproject().
|
inline |
Enable aspect ratio auto computation (set aspect by hand with setAspect() to disable) Just takes the camera's viewport aspect ratio
|
inline |
Get aspect ratio.
Referenced by EventViewerWidget::adjustDistance(), and setLike().
|
inline |
Get pointer to associated Camera (if any)
Referenced by setLike().
|
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().
|
inline |
Get eye, center and up vector.
| [out] | eye | |
| [out] | center | |
| [out] | up |
Referenced by MyCameraManipulator::MyCameraManipulator(), setLike(), and EventViewerWidget::setViewHome().
|
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().
|
inline |
Referenced by setLike().
|
inline |
Referenced by EventMultiViewer::setActiveViewer().
| void MyCamera::link | ( | MyCamera * | other | ) |
Referenced by EventViewerWidget::linkTo().
|
inline |
Get line-of-sight = center - eye.
Referenced by distance().
|
protected |
Compute screen parallel plane through center matching fov, aspect and distance.
References distance().
Referenced by apply(), and unproject().
|
signal |
Referenced by update().
|
signal |
|
inline |
Get "north" vector = normalized(center - eye)
Referenced by east(), setDistance(), and zoom().
| 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().
|
inline |
Get rotation.
Referenced by MyCameraManipulator::calcMovement(), MyCameraWidget::myCameraChanged(), and setLike().
|
inline |
Set projection aspect ratio.
References updateProj().
|
inline |
Only change center (rarely used, most times you want translate())
References setLookAt().
|
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().
|
inline |
|
inline |
Set projection fov.
References updateProj().
|
inline |
Set fov and aspect ratio simultaneous.
References updateProj().
|
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)
| 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().
|
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().
|
inline |
Translate center.
References updateView().
Referenced by EventViewerWidget::adjustCenter(), MyCameraManipulator::calcMovement(), pan(), and EventViewerWidget::setViewMode().
| void MyCamera::unlink | ( | MyCamera * | other | ) |
Referenced by EventViewerWidget::unlinkFrom().
|
inline |
Referenced by EventViewerWidget::setLinked().
| 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.
References MyCamera::Frustum::bottom, east(), MyCamera::Frustum::left, makeFrustum(), MyCamera::Frustum::right, and MyCamera::Frustum::top.
Referenced by MyCameraWidget::mouseMoveEvent(), EventViewerWidget::updateRuler(), and zoom().
|
inline |
Get up vector.
Referenced by EventViewerWidget::getRulerProjection(), and update().
| void MyCamera::update | ( | ) |
Update modelview and projection of associated camera.
References apply(), center(), distance(), myCameraChanged(), and up().
Referenced by associate(), MyCameraManipulator::handle(), MyCameraWidget::MyCameraWidget(), setProjection(), setRotation(), EventViewerWidget::setScenegraph(), updateProj(), updateView(), and zoom().
|
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().
|
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.
References north(), unproject(), and update().
Referenced by EventViewerWidget::fitBoundingBox(), and MyCameraWidget::mouseReleaseEvent().
1.8.6