diff --git a/AUTHORS.txt b/AUTHORS.txt index b33ffe300..84d8785ac 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -50,6 +50,9 @@ Ben Discoe Marco Jez - osgParticle - IO support for osgText. + +Mike Weiblen + - osgGL2 Randall Hopper - port to FreeBSD. diff --git a/include/osg/Matrix b/include/osg/Matrix index c04d322b9..f1df1a264 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -127,7 +127,7 @@ class SG_EXPORT Matrix double zNear, double zFar); /** Get the frustum setting of a perspective projection matrix. - * Note, if matrix is not an orthographic matrix then invalid values will be returned.*/ + * Note, if matrix is not an perspective matrix then invalid values will be returned.*/ void getFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar); diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index a26658f77..3941d8aa5 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -128,8 +128,28 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced const osg::State* getState() const { return _state.get(); } + /** 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(const osg::Matrix& matrix); + + /** Set to a orthographic projection. See OpenGL glOrtho for documentation further details.*/ + void setProjectionMatrixAsOrtho(double left, double right, + double bottom, double top, + double zNear, double zFar); + + /** Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details.*/ + void setProjectionMatrixAsOrtho2D(double left, double right, + double bottom, double top); + + /** Set to a perspective projection. See OpenGL glFrustum documentation for further details.*/ + void setProjectionMatrixAsFrustum(double left, double right, + double bottom, double top, + double zNear, double zFar); + + /** Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details. + * Aspect ratio is defined as width/height.*/ + void setProjectionMatrixAsPerspective(double fovy,double aspectRatio, + double zNear, double zFar); /** Get the projection matrix.*/ osg::Matrix& getProjectionMatrix() { return *_projectionMatrix; } @@ -137,8 +157,24 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced /** Get the const projection matrix.*/ const osg::Matrix& getProjectionMatrix() const { return *_projectionMatrix; } + /** Get the othorgraphic settings of the orthographic projection matrix. + * Note, if matrix is not an orthographic matrix then invalid values will be returned.*/ + void getProjectionMatrixAsOrtho(double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar); + + /** Get the frustum setting of a perspective projection matrix. + * Note, if matrix is not an perspective matrix then invalid values will be returned.*/ + void getProjectionMatrixAsFrustum(double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar); + /** 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); } + void setViewMatrix(const osg::Matrix& matrix); + + /** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */ + void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up); + /** Get the view matrix. */ osg::Matrix& getViewMatrix() { return *_viewMatrix; } @@ -146,6 +182,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced /** Get the const view matrix. */ const osg::Matrix& getViewMatrix() const { return *_viewMatrix; } + /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ + void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f); + + void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; } osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 17fc64d6a..15c2e330f 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -797,3 +797,86 @@ void SceneView::clearArea(int x,int y,int width,int height,const osg::Vec4& colo glClear( GL_COLOR_BUFFER_BIT); glDisable( GL_SCISSOR_TEST ); } + +void SceneView::setProjectionMatrix(const osg::Matrix& matrix) +{ + if (!_projectionMatrix) _projectionMatrix = new osg::RefMatrix(matrix); + else _projectionMatrix->set(matrix); +} + + +void SceneView::setProjectionMatrixAsOrtho(double left, double right, + double bottom, double top, + double zNear, double zFar) +{ + setProjectionMatrix(osg::Matrix::ortho(left, right, + bottom, top, + zNear, zFar)); +} + +void SceneView::setProjectionMatrixAsOrtho2D(double left, double right, + double bottom, double top) +{ + setProjectionMatrix(osg::Matrix::ortho2D(left, right, + bottom, top)); +} + +void SceneView::setProjectionMatrixAsFrustum(double left, double right, + double bottom, double top, + double zNear, double zFar) +{ + setProjectionMatrix(osg::Matrix::frustum(left, right, + bottom, top, + zNear, zFar)); +} + +void SceneView::setProjectionMatrixAsPerspective(double fovy,double aspectRatio, + double zNear, double zFar) +{ + setProjectionMatrix(osg::Matrix::perspective(fovy,aspectRatio, + zNear, zFar)); +} + +void SceneView::getProjectionMatrixAsOrtho(double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar) +{ + if (_projectionMatrix.valid()) + { + _projectionMatrix->getOrtho(left, right, + bottom, top, + zNear, zFar); + } +} + +void SceneView::getProjectionMatrixAsFrustum(double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar) +{ + if (_projectionMatrix.valid()) + { + _projectionMatrix->getFrustum(left, right, + bottom, top, + zNear, zFar); + } +} + + +void SceneView::setViewMatrix(const osg::Matrix& matrix) +{ + if (!_viewMatrix) _viewMatrix = new osg::RefMatrix(matrix); + else _viewMatrix->set(matrix); +} + +void SceneView::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up) +{ + setViewMatrix(osg::Matrix::lookAt(eye,center,up)); +} + +void SceneView::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance) +{ + if (_viewMatrix.valid()) + { + _viewMatrix->getLookAt(eye,center,up,lookDistance); + } +}