Update osg::Camera's viewport when it is created.
This fixes a problem where /sim/startup/[xy]size were not set properly because the GUI camera's viewport was not correct at startup.
This commit is contained in:
parent
12cf1c41ad
commit
8afab2045b
2 changed files with 17 additions and 4 deletions
|
@ -112,6 +112,16 @@ void installCullVisitor(Camera* camera)
|
||||||
|
|
||||||
namespace flightgear
|
namespace flightgear
|
||||||
{
|
{
|
||||||
|
void updateCameras(const CameraInfo* info)
|
||||||
|
{
|
||||||
|
if (info->camera.valid())
|
||||||
|
info->camera->getViewport()->setViewport(info->x, info->y,
|
||||||
|
info->width, info->height);
|
||||||
|
if (info->farCamera.valid())
|
||||||
|
info->farCamera->getViewport()->setViewport(info->x, info->y,
|
||||||
|
info->width, info->height);
|
||||||
|
}
|
||||||
|
|
||||||
CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
|
CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
|
||||||
const Matrix& view,
|
const Matrix& view,
|
||||||
const Matrix& projection,
|
const Matrix& projection,
|
||||||
|
@ -156,9 +166,9 @@ void CameraGroup::update(const osg::Vec3d& position,
|
||||||
for (CameraList::iterator i = _cameras.begin(); i != _cameras.end(); ++i) {
|
for (CameraList::iterator i = _cameras.begin(); i != _cameras.end(); ++i) {
|
||||||
const CameraInfo* info = i->get();
|
const CameraInfo* info = i->get();
|
||||||
const View::Slave& slave = _viewer->getSlave(info->slaveIndex);
|
const View::Slave& slave = _viewer->getSlave(info->slaveIndex);
|
||||||
|
// refreshes camera viewports (for now)
|
||||||
|
updateCameras(info);
|
||||||
Camera* camera = info->camera.get();
|
Camera* camera = info->camera.get();
|
||||||
camera->getViewport()->setViewport(info->x, info->y, info->width,
|
|
||||||
info->height);
|
|
||||||
Matrix viewMatrix;
|
Matrix viewMatrix;
|
||||||
if ((info->flags & VIEW_ABSOLUTE) != 0)
|
if ((info->flags & VIEW_ABSOLUTE) != 0)
|
||||||
viewMatrix = slave._viewOffset;
|
viewMatrix = slave._viewOffset;
|
||||||
|
@ -175,8 +185,6 @@ void CameraGroup::update(const osg::Vec3d& position,
|
||||||
camera->setProjectionMatrix(projectionMatrix);
|
camera->setProjectionMatrix(projectionMatrix);
|
||||||
} else {
|
} else {
|
||||||
Camera* farCamera = info->farCamera.get();
|
Camera* farCamera = info->farCamera.get();
|
||||||
farCamera->getViewport()->setViewport(info->x, info->y, info->width,
|
|
||||||
info->height);
|
|
||||||
farCamera->setViewMatrix(viewMatrix);
|
farCamera->setViewMatrix(viewMatrix);
|
||||||
double left, right, bottom, top, parentNear, parentFar;
|
double left, right, bottom, top, parentNear, parentFar;
|
||||||
projectionMatrix.getFrustum(left, right, bottom, top,
|
projectionMatrix.getFrustum(left, right, bottom, top,
|
||||||
|
@ -415,6 +423,7 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
|
||||||
|
|
||||||
// Disable statistics for the GUI camera.
|
// Disable statistics for the GUI camera.
|
||||||
result->camera->setStats(0);
|
result->camera->setStats(0);
|
||||||
|
updateCameras(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,10 @@ struct CameraInfo : public osg::Referenced
|
||||||
double height;
|
double height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Update the OSG cameras from the camera info.
|
||||||
|
*/
|
||||||
|
void updateCameras(const CameraInfo* info);
|
||||||
|
|
||||||
class CameraGroup : public osg::Referenced
|
class CameraGroup : public osg::Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue