Added setProjectionMatrix*(), setViewMatrix*() and get*() methods to osgUtil::SceneView.

This commit is contained in:
Robert Osfield 2003-07-16 22:15:28 +00:00
parent a4b29996fd
commit 2a142c096a
4 changed files with 129 additions and 3 deletions

View File

@ -50,6 +50,9 @@ Ben Discoe <ben@vterrain.org>
Marco Jez <marco.jez@arsenal.it>
- osgParticle
- IO support for osgText.
Mike Weiblen <mike.weiblen@3dlabs.com>
- osgGL2
Randall Hopper <aa8vb@yahoo.com>
- port to FreeBSD.

View File

@ -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);

View File

@ -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(); }

View File

@ -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);
}
}