1
0
Fork 0

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.
This commit is contained in:
Mathias Froehlich 2011-10-23 09:58:51 +02:00
parent 2157164271
commit ad660380c2
2 changed files with 14 additions and 3 deletions

View 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);

View 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