1
0
Fork 0

Expose the CameraGroup near, far, and near/far boundry as properties

The near/far boundary, called "near-field", can be set to 0 which
disables the far camera and renders the whole scene using only one
camera. I'm hoping that this may be useful in resolving some
system-specific rendering bugs.

Various fixes were made to correctly render the scene using only the
near camera.
This commit is contained in:
timoore 2008-12-27 14:35:33 +00:00 committed by Tim Moore
parent ed1369bd8a
commit d43e0b83f7
3 changed files with 34 additions and 16 deletions

View file

@ -146,8 +146,8 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera,
info->farSlaveIndex = _viewer->getNumSlaves() - 1;
farCamera->setRenderOrder(Camera::NESTED_RENDER, info->farSlaveIndex);
camera->setCullMask(camera->getCullMask() & ~simgear::BACKGROUND_BIT);
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
}
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
_viewer->addSlave(camera, view, projection, useMasterSceneData);
installCullVisitor(camera);
info->camera = camera;
@ -190,18 +190,22 @@ void CameraGroup::update(const osg::Vec3d& position,
double left, right, bottom, top, parentNear, parentFar;
projectionMatrix.getFrustum(left, right, bottom, top,
parentNear, parentFar);
if (parentFar < 100.0) {
if (parentFar < _nearField || _nearField == 0.0f) {
camera->setProjectionMatrix(projectionMatrix);
camera->setCullMask(camera->getCullMask()
| simgear::BACKGROUND_BIT);
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
farCamera->setNodeMask(0);
} else {
Matrix nearProj, farProj;
makeNewProjMat(projectionMatrix, parentNear, 100.0, nearProj);
makeNewProjMat(projectionMatrix, 100.0, parentFar, farProj);
makeNewProjMat(projectionMatrix, parentNear, _nearField,
nearProj);
makeNewProjMat(projectionMatrix, _nearField, parentFar,
farProj);
camera->setProjectionMatrix(nearProj);
camera->setCullMask(camera->getCullMask()
& ~simgear::BACKGROUND_BIT);
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
farCamera->setProjectionMatrix(farProj);
farCamera->setNodeMask(camera->getNodeMask());
}
@ -211,11 +215,9 @@ void CameraGroup::update(const osg::Vec3d& position,
void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
{
const float zNear = .1f;
const float zFar = 120000.0f;
_viewer->getCamera()->setProjectionMatrixAsPerspective(vfov,
1.0f / aspectRatio,
zNear, zFar);
_zNear, _zFar);
}
}
@ -444,16 +446,25 @@ CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer,
cgroup->buildGUICamera(pNode);
}
}
bindMemberToNode(gnode, "znear", cgroup, &CameraGroup::_zNear, .4f);
bindMemberToNode(gnode, "zfar", cgroup, &CameraGroup::_zFar, 120000.0f);
bindMemberToNode(gnode, "near-field", cgroup, &CameraGroup::_nearField,
100.0f);
return cgroup;
}
void CameraGroup::setCameraCullMasks(Node::NodeMask nm)
{
for (CameraIterator i = camerasBegin(), e = camerasEnd(); i != e; ++i) {
if ((*i)->flags & GUI)
CameraInfo* info = i->get();
if (info->flags & GUI)
continue;
(*i)->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
(*i)->farCamera->setCullMask(nm);
if (info->farCamera.valid() && info->farCamera->getNodeMask() != 0) {
info->camera->setCullMask(nm & ~simgear::BACKGROUND_BIT);
info->farCamera->setCullMask(nm);
} else {
info->camera->setCullMask(nm);
}
}
}
@ -512,9 +523,12 @@ bool computeIntersections(const CameraGroup* cgroup,
Matrix windowMat = viewport->computeWindowMatrix();
Matrix startPtMat = Matrix::inverse(camera->getProjectionMatrix()
* windowMat);
Matrix endPtMat
= Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
* windowMat);
Matrix endPtMat;
if (!cinfo->farCamera.valid() || cinfo->farCamera->getNodeMask() == 0)
endPtMat = startPtMat;
else
endPtMat = Matrix::inverse(cinfo->farCamera->getProjectionMatrix()
* windowMat);
start = start * startPtMat;
start /= start.w();
end = end * endPtMat;

View file

@ -182,6 +182,10 @@ protected:
CameraList _cameras;
osg::ref_ptr<osgViewer::Viewer> _viewer;
static osg::ref_ptr<CameraGroup> _defaultGroup;
// Near, far for the master camera if used.
float _zNear;
float _zFar;
float _nearField;
};
}

View file

@ -103,9 +103,9 @@ void fgOSOpenWindow(bool stencil)
// Look for windows, camera groups, and the old syntax of
// top-level cameras
SGPropertyNode* renderingNode = fgGetNode("/sim/rendering");
SGPropertyNode* cgroupNode = renderingNode->getChild("camera-group");
if (!cgroupNode) {
cgroupNode = renderingNode->getNode("camera-group", true);
SGPropertyNode* cgroupNode = renderingNode->getNode("camera-group", true);
bool oldSyntax = !cgroupNode->hasChild("camera");
if (oldSyntax) {
for (int i = 0; i < renderingNode->nChildren(); ++i) {
SGPropertyNode* propNode = renderingNode->getChild(i);
const char* propName = propNode->getName();