+}
+
+namespace
+{
+using namespace osg;
+
+// Given a projection matrix, return a new one with the same frustum
+// sides and new near / far values.
+
+void makeNewProjMat(Matrixd& oldProj, double znear,
+ double zfar, Matrixd& projection)
+{
+ projection = oldProj;
+ // Slightly inflate the near & far planes to avoid objects at the
+ // extremes being clipped out.
+ znear *= 0.999;
+ zfar *= 1.001;
+
+ // Clamp the projection matrix z values to the range (near, far)
+ double epsilon = 1.0e-6;
+ if (fabs(projection(0,3)) < epsilon &&
+ fabs(projection(1,3)) < epsilon &&
+ fabs(projection(2,3)) < epsilon) {
+ // Projection is Orthographic
+ epsilon = -1.0/(zfar - znear); // Used as a temp variable
+ projection(2,2) = 2.0*epsilon;
+ projection(3,2) = (zfar + znear)*epsilon;
+ } else {
+ // Projection is Perspective
+ double trans_near = (-znear*projection(2,2) + projection(3,2)) /
+ (-znear*projection(2,3) + projection(3,3));
+ double trans_far = (-zfar*projection(2,2) + projection(3,2)) /
+ (-zfar*projection(2,3) + projection(3,3));
+ double ratio = fabs(2.0/(trans_near - trans_far));
+ double center = -0.5*(trans_near + trans_far);
+
+ projection.postMult(osg::Matrixd(1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, ratio, 0.0,
+ 0.0, 0.0, center*ratio, 1.0));
+ }
+}
+
+void installCullVisitor(Camera* camera)
+{
+ osgViewer::Renderer* renderer
+ = static_cast<osgViewer::Renderer*>(camera->getRenderer());
+ for (int i = 0; i < 2; ++i) {
+ osgUtil::SceneView* sceneView = renderer->getSceneView(i);
+ sceneView->setCullVisitor(new simgear::EffectCullVisitor);
+ }
+}
+}
+
+namespace flightgear
+{
+void updateCameras(const CameraInfo* info)
+{
+ if (info->camera.valid())
+ info->camera->getViewport()->setViewport(info->x, info->y,
+ info->width, info->height);
+ if (info->farCamera.valid())
+ info->farCamera->getViewport()->setViewport(info->x, info->y,
+ info->width, info->height);
+}
+