Introduced osg::Camera::resize(..) method and associated enum thus:

enum ResizeMask
        {
            RESIZE_VIEWPORT=1,
            RESIZE_ATTACHMENTS=2,
            RESIZE_PROJECTIONMATRIX=4,
            RESIZE_DEFAULT=RESIZE_VIEWPORT|RESIZE_ATTACHMENTS
        };

        /** Resize, to the specified width and height, the viewport, attachments and projection matrix according to the resizeMask provided.
          * Note, the adjustment of the projection matrix is done if the RESIZE_PROJECTIONMATRIX mask to set and according to the rules specified in the ProjectionResizePolicy. */
        void resize(int width, int height, int resizeMask=RESIZE_DEFAULT);



git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14811 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2015-03-31 16:23:43 +00:00
parent 99f7bfab3b
commit a7ba138dc7
3 changed files with 56 additions and 12 deletions

View File

@ -108,13 +108,6 @@ public:
{
}
void resizeRTTCamera(osg::Camera* camera,unsigned int width, unsigned int height)
{
camera->setViewport(0, 0, width, height);
camera->resizeAttachments(width, height);
}
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv)
{
osg::Camera* camera = dynamic_cast<osg::Camera*>(object);
@ -130,11 +123,8 @@ public:
OSG_NOTICE<<" WindowWidth="<<ea.getWindowWidth()<<std::endl;
OSG_NOTICE<<" WindowHeight="<<ea.getWindowHeight()<<std::endl;
// reset the Camera and associated Texture's to make sure it tracks the new window size.
int width = ea.getWindowWidth();
int height = ea.getWindowHeight();
resizeRTTCamera(camera, width, height);
// reset the Camera viewpoer and associated Texture's to make sure it tracks the new window size.
camera->resize(ea.getWindowWidth(), ea.getWindowHeight());
}
return false;
}

View File

@ -430,6 +430,19 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
void resizeAttachments(int width, int height);
enum ResizeMask
{
RESIZE_VIEWPORT=1,
RESIZE_ATTACHMENTS=2,
RESIZE_PROJECTIONMATRIX=4,
RESIZE_DEFAULT=RESIZE_VIEWPORT|RESIZE_ATTACHMENTS
};
/** Resize, to the specified width and height, the viewport, attachments and projection matrix according to the resizeMask provided.
* Note, the adjustment of the projection matrix is done if the RESIZE_PROJECTIONMATRIX mask to set and according to the rules specified in the ProjectionResizePolicy. */
void resize(int width, int height, int resizeMask=RESIZE_DEFAULT);
/** Explicit control over implicit allocation of buffers when using FBO.
Implicit buffers are automatically substituted when user have not attached such buffer.

View File

@ -481,6 +481,47 @@ void Camera::resizeAttachments(int width, int height)
}
}
void Camera::resize(int width, int height, int resizeMask)
{
if (getViewport())
{
double previousWidth = getViewport()->width();
double previousHeight = getViewport()->height();
double newWidth = width;
double newHeight = height;
if ((previousWidth!=newWidth) || (previousHeight!=newHeight))
{
if ((resizeMask&RESIZE_PROJECTIONMATRIX)!=0 && (getProjectionResizePolicy()!=FIXED))
{
double widthChangeRatio = newWidth / previousWidth;
double heigtChangeRatio = newHeight / previousHeight;
double aspectRatioChange = widthChangeRatio / heigtChangeRatio;
if (aspectRatioChange!=1.0)
{
switch(getProjectionResizePolicy())
{
case(HORIZONTAL): getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); break;
case(VERTICAL): getProjectionMatrix() *= osg::Matrix::scale(1.0, aspectRatioChange,1.0); break;
case(FIXED): break;
}
}
}
if ((resizeMask&RESIZE_VIEWPORT)!=0)
{
setViewport(0,0,width, height);
}
}
}
if ((resizeMask&RESIZE_ATTACHMENTS)!=0)
{
resizeAttachments(width, height);
}
}
void Camera::createCameraThread()
{
if (!_cameraThread)