X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2FCameraGroup.cxx;h=954a591e55d0c41ad761b2772d557aec8eda639b;hb=224afcc7e4cb4191be15f3df025164fcd83f5102;hp=4e968fc2d812dcb2435f2a01905a3be46561f857;hpb=68c06775c8c255ce861a2dc5d0810017af66716a;p=flightgear.git diff --git a/src/Main/CameraGroup.cxx b/src/Main/CameraGroup.cxx index 4e968fc2d..954a591e5 100644 --- a/src/Main/CameraGroup.cxx +++ b/src/Main/CameraGroup.cxx @@ -14,6 +14,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#ifdef HAVE_CONFIG_H +# include +#endif + #include "CameraGroup.hxx" #include "globals.hxx" @@ -23,6 +27,7 @@ #include "WindowSystemAdapter.hxx" #include #include +#include #include #include @@ -40,6 +45,7 @@ #include #include +#include namespace flightgear { @@ -100,14 +106,12 @@ void makeNewProjMat(Matrixd& oldProj, double znear, void installCullVisitor(Camera* camera) { -#if 0 // Not yet osgViewer::Renderer* renderer = static_cast(camera->getRenderer()); for (int i = 0; i < 2; ++i) { osgUtil::SceneView* sceneView = renderer->getSceneView(i); sceneView->setCullVisitor(new simgear::EffectCullVisitor); } -#endif } } @@ -134,8 +138,12 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera, Camera* farCamera = 0; if ((flags & (GUI | ORTHO)) == 0) { - farCamera = simgear::clone(camera); + farCamera = new Camera; + farCamera->setAllowEventFocus(camera->getAllowEventFocus()); farCamera->setGraphicsContext(camera->getGraphicsContext()); + farCamera->setCullingMode(camera->getCullingMode()); + farCamera->setInheritanceMask(camera->getInheritanceMask()); + farCamera->setReferenceFrame(Transform::ABSOLUTE_RF); // Each camera's viewport is written when the window is // resized; if the the viewport isn't copied here, it gets updated // twice and ends up with the wrong value. @@ -144,15 +152,15 @@ CameraInfo* CameraGroup::addCamera(unsigned flags, Camera* camera, installCullVisitor(farCamera); info->farCamera = farCamera; info->farSlaveIndex = _viewer->getNumSlaves() - 1; - farCamera->setRenderOrder(Camera::NESTED_RENDER, info->farSlaveIndex); + farCamera->setRenderOrder(Camera::POST_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; info->slaveIndex = _viewer->getNumSlaves() - 1; - camera->setRenderOrder(Camera::NESTED_RENDER, info->slaveIndex); + camera->setRenderOrder(Camera::POST_RENDER, info->slaveIndex); _cameras.push_back(info); return info; } @@ -190,18 +198,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 | GL_STENCIL_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 +223,11 @@ 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); + if (vfov != 0.0f && aspectRatio != 0.0f) + _viewer->getCamera() + ->setProjectionMatrixAsPerspective(vfov, + 1.0f / aspectRatio, + _zNear, _zFar); } } @@ -290,7 +302,6 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) WindowBuilder *wBuild = WindowBuilder::getWindowBuilder(); const SGPropertyNode* windowNode = cameraNode->getNode("window"); GraphicsWindow* window = 0; - static int cameraNum = 0; int cameraFlags = DO_INTERSECTION_TEST; if (windowNode) { // New style window declaration / definition @@ -310,7 +321,11 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) | CullSettings::VIEW_FRUSTUM_CULLING); camera->setInheritanceMask(CullSettings::ALL_VARIABLES & ~(CullSettings::CULL_MASK - | CullSettings::CULLING_MODE)); + | CullSettings::CULLING_MODE +#if defined(HAVE_CULLSETTINGS_CLEAR_MASK) + | CullSettings::CLEAR_MASK +#endif + )); osg::Matrix pOff; osg::Matrix vOff; @@ -392,7 +407,6 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode, const SGPropertyNode* windowNode = (cameraNode ? cameraNode->getNode("window") : 0); - static int cameraNum = 0; if (!window) { if (windowNode) { // New style window declaration / definition @@ -412,7 +426,11 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode, camera->setClearMask(0); camera->setInheritanceMask(CullSettings::ALL_VARIABLES & ~(CullSettings::COMPUTE_NEAR_FAR_MODE - | CullSettings::CULLING_MODE)); + | CullSettings::CULLING_MODE +#if defined(HAVE_CULLSETTINGS_CLEAR_MASK) + | CullSettings::CLEAR_MASK +#endif + )); camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); camera->setCullingMode(osg::CullSettings::NO_CULLING); camera->setProjectionResizePolicy(Camera::FIXED); @@ -444,16 +462,25 @@ CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer, cgroup->buildGUICamera(pNode); } } + bindMemberToNode(gnode, "znear", cgroup, &CameraGroup::_zNear, .1f); + 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 +539,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;