diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index e93a76a5e..a26658f77 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -128,17 +128,23 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced const osg::State* getState() const { return _state.get(); } - /** set a projection matrix. Note, this will override a camera's projection matrix if it is not NULL.*/ + /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ void setProjectionMatrix(const osg::Matrix& matrix) { _projectionMatrix = new osg::RefMatrix(matrix); } - void setProjectionMatrix(osg::RefMatrix* matrix) { _projectionMatrix = matrix; } - osg::RefMatrix* getProjectionMatrix() { return _projectionMatrix.get(); } - const osg::RefMatrix* getProjectionMatrix() const { return _projectionMatrix.get(); } - /** set a modelview matrix. Note, this will override a camera's modelview matrix if it is not NULL.*/ - void setModelViewMatrix(const osg::Matrix& matrix) { _modelviewMatrix = new osg::RefMatrix(matrix); } - void setModelViewMatrix(osg::RefMatrix* matrix) { _modelviewMatrix = matrix; } - osg::RefMatrix* getModelViewMatrix() { return _modelviewMatrix.get(); } - const osg::RefMatrix* getModelViewMatrix() const { return _modelviewMatrix.get(); } + /** Get the projection matrix.*/ + osg::Matrix& getProjectionMatrix() { return *_projectionMatrix; } + + /** Get the const projection matrix.*/ + const osg::Matrix& getProjectionMatrix() const { return *_projectionMatrix; } + + /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ + void setViewMatrix(const osg::Matrix& matrix) { _viewMatrix = new osg::RefMatrix(matrix); } + + /** Get the view matrix. */ + osg::Matrix& getViewMatrix() { return *_viewMatrix; } + + /** Get the const view matrix. */ + const osg::Matrix& getViewMatrix() const { return *_viewMatrix; } void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; } @@ -297,7 +303,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced osg::ref_ptr _localStateSet; osg::ref_ptr _light; osg::ref_ptr _projectionMatrix; - osg::ref_ptr _modelviewMatrix; + osg::ref_ptr _viewMatrix; osg::ref_ptr _displaySettings; osg::ref_ptr _state; diff --git a/src/osgGA/SetSceneViewVisitor.cpp b/src/osgGA/SetSceneViewVisitor.cpp index 7b6187808..fd41240c7 100644 --- a/src/osgGA/SetSceneViewVisitor.cpp +++ b/src/osgGA/SetSceneViewVisitor.cpp @@ -5,10 +5,7 @@ void osgGA::SetSceneViewVisitor::visit(osgGA::MatrixManipulator& cm) { cm.setNode(_sceneView->getSceneData()); - if (_sceneView->getModelViewMatrix()) - { - cm.setByInverseMatrix(*(_sceneView->getModelViewMatrix())); - } + cm.setByInverseMatrix(_sceneView->getViewMatrix()); cm.init(*getGUIEventAdapter(),*getGUIActionAdapter()); cm.home(*getGUIEventAdapter(),*getGUIActionAdapter()); } diff --git a/src/osgProducer/OsgSceneHandler.cpp b/src/osgProducer/OsgSceneHandler.cpp index 502a08f0b..ce6c771e5 100644 --- a/src/osgProducer/OsgSceneHandler.cpp +++ b/src/osgProducer/OsgSceneHandler.cpp @@ -20,8 +20,6 @@ using namespace osgProducer; OsgSceneHandler::OsgSceneHandler( osg::DisplaySettings *ds) : _sceneView(new osgUtil::SceneView(ds)) { - _sceneView->setProjectionMatrix( new osg::RefMatrix ); - _sceneView->setModelViewMatrix( new osg::RefMatrix ); } void OsgSceneHandler::init() @@ -46,8 +44,8 @@ void OsgSceneHandler::clearImplementation(Producer::Camera& /*camera*/) void OsgSceneHandler::cullImplementation(Producer::Camera &cam) { - _sceneView->getProjectionMatrix()->set(cam.getProjectionMatrix()); - _sceneView->getModelViewMatrix()->set(cam.getPositionAndAttitudeMatrix()); + _sceneView->getProjectionMatrix().set(cam.getProjectionMatrix()); + _sceneView->getViewMatrix().set(cam.getPositionAndAttitudeMatrix()); int x, y; unsigned int w, h; diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 33e7d8cf9..de03031dd 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -516,10 +516,10 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil osgProducer::OsgSceneHandler* sh = dynamic_cast(camera->getSceneHandler()); osgUtil::SceneView* sv = sh?sh->getSceneView():0; osg::Matrix vum; - if (sv!=0 && sv->getModelViewMatrix()!=0 && sv->getProjectionMatrix()!=0) + if (sv!=0) { - vum.set((*(sv->getModelViewMatrix())) * - (*(sv->getProjectionMatrix()))); + vum.set(sv->getViewMatrix() * + sv->getProjectionMatrix()); } else { diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 66f905284..d4fecaba6 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -70,9 +70,9 @@ void SceneView::setDefaults() _projectionMatrix = new RefMatrix(); _projectionMatrix->makePerspective(50.0f,1.4f,1.0f,10000.0f); } - if (!_modelviewMatrix) + if (!_viewMatrix) { - _modelviewMatrix = new RefMatrix(); + _viewMatrix = new RefMatrix(); } _globalStateSet = new osg::StateSet; @@ -216,7 +216,7 @@ void SceneView::cull() osg::ref_ptr projection = _projectionMatrix.get(); - osg::ref_ptr modelview = _modelviewMatrix.get(); + osg::ref_ptr modelview = _viewMatrix.get(); if (!projection) projection = new osg::RefMatrix(); if (!modelview) modelview = new osg::RefMatrix(); @@ -761,8 +761,8 @@ const osg::Matrix SceneView::computeMVPW() const { osg::Matrix matrix; - if (_modelviewMatrix.valid()) - matrix = (*_modelviewMatrix); + if (_viewMatrix.valid()) + matrix = (*_viewMatrix); if (_projectionMatrix.valid()) matrix.postMult(*_projectionMatrix);