From: Mathias Froehlich Date: Sun, 23 Oct 2011 07:58:51 +0000 (+0200) Subject: Add fixed-near-far camera config parameter. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ad660380c28bb4e302bbc108ffaded1f6096840b;p=flightgear.git Add fixed-near-far camera config parameter. If set to true, the decision about the near and far planes in the viewer are still adapted to not clip away everything before the configured near plane. --- diff --git a/src/Main/CameraGroup.cxx b/src/Main/CameraGroup.cxx index 3e70e9fe1..2a312391b 100644 --- a/src/Main/CameraGroup.cxx +++ b/src/Main/CameraGroup.cxx @@ -1,4 +1,5 @@ // Copyright (C) 2008 Tim Moore +// Copyright (C) 2011 Mathias Froehlich // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -232,6 +233,10 @@ void CameraGroup::update(const osg::Vec3d& position, double left, right, bottom, top, parentNear, parentFar; projectionMatrix.getFrustum(left, right, bottom, top, parentNear, parentFar); + if ((info->flags & FIXED_NEAR_FAR) == 0) { + parentNear = _zNear; + parentFar = _zFar; + } if (parentFar < _nearField || _nearField == 0.0f) { camera->setProjectionMatrix(projectionMatrix); camera->setCullMask(camera->getCullMask() @@ -602,7 +607,7 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) double aspectRatio = projectionNode->getDoubleValue("aspect-ratio", 1.0); double zNear = projectionNode->getDoubleValue("near", 0.0); - double zFar = projectionNode->getDoubleValue("far", 0.0); + double zFar = projectionNode->getDoubleValue("far", zNear + 20000); double offsetX = projectionNode->getDoubleValue("offset-x", 0.0); double offsetY = projectionNode->getDoubleValue("offset-y", 0.0); double tan_fovy = tan(DegreesToRadians(fovy*0.5)); @@ -612,6 +617,8 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) double bottom = -tan_fovy * zNear + offsetY; pOff.makeFrustum(left, right, bottom, top, zNear, zFar); cameraFlags |= PROJECTION_ABSOLUTE; + if (projectionNode->getBoolValue("fixed-near-far", true)) + cameraFlags |= FIXED_NEAR_FAR; } else if ((projectionNode = cameraNode->getNode("frustum")) != 0 || (projectionNode = cameraNode->getNode("ortho")) != 0) { double top = projectionNode->getDoubleValue("top", 0.0); @@ -619,7 +626,7 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) double left = projectionNode->getDoubleValue("left", 0.0); double right = projectionNode->getDoubleValue("right", 0.0); double zNear = projectionNode->getDoubleValue("near", 0.0); - double zFar = projectionNode->getDoubleValue("far", 0.0); + double zFar = projectionNode->getDoubleValue("far", zNear + 20000); if (cameraNode->getNode("frustum")) { pOff.makeFrustum(left, right, bottom, top, zNear, zFar); cameraFlags |= PROJECTION_ABSOLUTE; @@ -627,6 +634,8 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode) pOff.makeOrtho(left, right, bottom, top, zNear, zFar); cameraFlags |= (PROJECTION_ABSOLUTE | ORTHO); } + if (projectionNode->getBoolValue("fixed-near-far", true)) + cameraFlags |= FIXED_NEAR_FAR; } else { // old style shear parameters double shearx = cameraNode->getDoubleValue("shear-x", 0); diff --git a/src/Main/CameraGroup.hxx b/src/Main/CameraGroup.hxx index e0808ce47..9f37ce5d2 100644 --- a/src/Main/CameraGroup.hxx +++ b/src/Main/CameraGroup.hxx @@ -94,8 +94,10 @@ public: PROJECTION_ABSOLUTE = 0x2, /**< The projection is absolute. */ ORTHO = 0x4, /**< The projection is orthographic */ GUI = 0x8, /**< Camera draws the GUI. */ - DO_INTERSECTION_TEST = 0x10 /**< scene intersection tests this + DO_INTERSECTION_TEST = 0x10,/**< scene intersection tests this camera. */ + FIXED_NEAR_FAR = 0x20 /**< take the near far values in the + projection for real. */ }; /** Create a camera group associated with an osgViewer::Viewer. * @param viewer the viewer