From 8aa72d85cf08d4bcf3cf3551ddb227aec899ab39 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 Dec 2001 16:35:38 +0000 Subject: [PATCH] Updates to the camera code related to stereo, adding fusion distance. --- include/osg/Camera | 38 +++++++++++++++++++------ src/osg/Camera.cpp | 42 +++++++++++++++++----------- src/osgUtil/RenderStage.cpp | 5 ++-- src/osgUtil/SceneView.cpp | 9 ------ src/osgUtil/TrackballManipulator.cpp | 8 ++++-- 5 files changed, 61 insertions(+), 41 deletions(-) diff --git a/include/osg/Camera b/include/osg/Camera index 941f05a3c..5fca849ff 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -122,9 +122,20 @@ class SG_EXPORT Camera: public osg::Referenced /** Calculate and return the projection aspect ratio. * Aspect ratio is defined as width/height.*/ const double calc_aspectRatio() const; - + const Matrix& getProjectionMatrix() const; + + /** set the fusion distance, the distance in model coords, when viewing stereo, that the + * left and right eye images converge. This value is dual of the screen distance, + * which is distance between viewers eyes and display device, while the fusion distance is + * this equivilant distance but in the virtual world (model coords.)*/ + inline const double setFusionDistance() const { return _fusionDistance; } + + /** get fusion distance.*/ + inline const double getFusionDistance() const { return _fusionDistance; } + + enum LookAtType { USE_HOME_POSITON, @@ -184,8 +195,6 @@ class SG_EXPORT Camera: public osg::Referenced /** calculate side vector.*/ const Vec3 getSideVector() const; - /** get focal distance.*/ - inline const double getFocalLength() const { return _focalLength; } enum TransformMode @@ -237,10 +246,19 @@ class SG_EXPORT Camera: public osg::Referenced const Matrix& getModelViewMatrix() const; + /** Switch on/off the use of the near clipping plane which creating the + * getClippingVolume(), uses the camera _znear value for the position of the + * near clipping plane. By default this value is off.*/ void setUseNearClippingPlane(const bool use); + /** get whether the ClippingVolume uses a near clipping plane.*/ const bool getUseNearClippingPlane() const { return _useNearClippingPlane; } + + /** Switch on/off the use of the far clipping plane which creating the + * getClippingVolume(), uses the camera _zfar value for the position + * of the far clipping plane. By default this value is off.*/ void setUseFarClippingPlane(const bool use); + /** Get whether the ClippingVolume uses a far clipping plane.*/ const bool getUseFarClippingPlane() const { return _useFarClippingPlane; } /** get the view frustum clipping in model coordinates */ @@ -262,6 +280,9 @@ class SG_EXPORT Camera: public osg::Referenced * specialize the camera for each eye view.*/ void adjustEyeOffsetForStereo(const osg::Vec3& offset,float screenDistance); + /** Set up the OpenGL projection and model view matrices.*/ + virtual void apply(State& state); + protected: void copy(const Camera&); @@ -291,7 +312,7 @@ class SG_EXPORT Camera: public osg::Referenced Vec3 _center; Vec3 _up; - double _focalLength; + double _fusionDistance; TransformMode _attachedTransformMode; ref_ptr _eyeToModelTransform; @@ -311,12 +332,11 @@ class SG_EXPORT Camera: public osg::Referenced mutable ref_ptr _inversemp; void calculateMatricesAndClippingVolume() const; - - // values to offset - bool _useEyeOffset; - osg::Vec3 _eyeOffset; - float _screenDistance; + // used for offsetting camera to ajust for left and right stereo views. + bool _useEyeOffset; + osg::Vec3 _eyeOffset; + float _screenDistance; }; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index c6230b305..a044bf8ff 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace osg; @@ -23,7 +24,7 @@ Camera::Camera() _center.set(0.0f,0.0f,-1.0f); _up.set(0.0f,1.0f,0.0f); - _focalLength = 1.0f; + _fusionDistance = 1.0f; _useNearClippingPlane = false; _useFarClippingPlane = false; @@ -73,7 +74,7 @@ void Camera::copy(const Camera& camera) _center = camera._center; _up = camera._up; - _focalLength = camera._focalLength; + _fusionDistance = camera._fusionDistance; _attachedTransformMode = camera._attachedTransformMode; _eyeToModelTransform = camera._eyeToModelTransform; @@ -218,11 +219,11 @@ void Camera::setNearFar(const double zNear, const double zFar) * Typicall used after resizeing a window.*/ void Camera::adjustAspectRatio(const double newAspectRatio, const AdjustAspectRatioMode aa) { - if (newAspectRatio<0.01f || newAspectRatio>100.0f) - { - notify(NOTICE)<<"Warning: aspect ratio out of range (0.01..100) in Camera::adjustAspectRatio("<100.0f) + { + notify(NOTICE)<<"Warning: aspect ratio out of range (0.01..100) in Camera::adjustAspectRatio("<getProjectionMatrix(); glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glMultMatrixf(projectionMat.ptr()); + glLoadMatrixf(projectionMat.ptr()); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); @@ -117,7 +116,7 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous) // set up camera modelview. const Matrix& modelView = _camera->getModelViewMatrix(); - glMultMatrixf(modelView.ptr()); + glLoadMatrixf(modelView.ptr()); if (getLightingMode()==RenderStageLighting::SKY_LIGHT && light) diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 498783972..6415ef858 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -331,15 +331,6 @@ void SceneView::draw() left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f),screenDistance); right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f),screenDistance); - - osg::ColorMatrix* cm = new osg::ColorMatrix; - cm->setMatrix(osg::Matrix(0.3f,0.3f,0.3f,0.0f, - 0.6f,0.6f,0.6f,0.0f, - 0.1f,0.1f,0.1f,0.0f, - 0.0f,0.0f,0.0f,1.0f)); - - _globalState->setAttribute(cm); - osg::ColorMask* red = new osg::ColorMask; osg::ColorMask* green = new osg::ColorMask; diff --git a/src/osgUtil/TrackballManipulator.cpp b/src/osgUtil/TrackballManipulator.cpp index 7d29a34ea..95769701f 100644 --- a/src/osgUtil/TrackballManipulator.cpp +++ b/src/osgUtil/TrackballManipulator.cpp @@ -184,6 +184,7 @@ bool TrackballManipulator::calcMovement() // return if there is no movement. if (dx==0 && dy==0) return false; + float focalLength = (_camera->getCenterPoint()-_camera->getEyePoint()).length(); unsigned int buttonMask = _ga_t1->getButtonMask(); if (buttonMask==GUIEventAdapter::LEFT_BUTTON) { @@ -229,8 +230,9 @@ bool TrackballManipulator::calcMovement() { // pan model. + - float scale = 0.0015f*_camera->getFocalLength(); + float scale = 0.0015f*focalLength; osg::Vec3 uv = _camera->getUpVector(); osg::Vec3 sv = _camera->getSideVector(); @@ -240,7 +242,7 @@ bool TrackballManipulator::calcMovement() mat.makeTranslate(dv.x(),dv.y(),dv.z()); _camera->transformLookAt(mat); - + return true; } @@ -249,7 +251,7 @@ bool TrackballManipulator::calcMovement() // zoom model. - float fd = _camera->getFocalLength(); + float fd = focalLength; float scale = 1.0f-dy*0.001f; if (fd*scale>_modelScale*_minimumZoomScale) {