]> git.mxchange.org Git - flightgear.git/commitdiff
Add fixed-near-far camera config parameter.
authorMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 23 Oct 2011 07:58:51 +0000 (09:58 +0200)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Sun, 23 Oct 2011 14:40:13 +0000 (16:40 +0200)
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.

src/Main/CameraGroup.cxx
src/Main/CameraGroup.hxx

index 3e70e9fe1c042f8461dedd08e89bbd7c3e304c4d..2a312391b353ad6403f067589e4d6052177bf946 100644 (file)
@@ -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);
index e0808ce47b03861ed6541b61ec21e5955c982bfa..9f37ce5d273bfa9ea6c36b43292c94984abef904 100644 (file)
@@ -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