]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/CameraGroup.cxx
Prepare and implement reinit methods for instruments
[flightgear.git] / src / Viewer / CameraGroup.cxx
index 8de78d1aae66e30f5f300be9aabebdf6ff44e9c8..3d84717e5b8316e85c737c33e30afe337c8c6b97 100644 (file)
@@ -32,7 +32,6 @@
 #include <simgear/structure/OSGVersion.hxx>
 #include <simgear/scene/material/EffectCullVisitor.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
-#include <simgear/scene/tgdb/userdata.hxx>
 
 #include <algorithm>
 #include <cstring>
 #include <osgViewer/Renderer>
 
 namespace flightgear {
-const char* MAIN_CAMERA = "MAIN_CAMERA";
-const char* FAR_CAMERA = "FAR_CAMERA";
-const char* GEOMETRY_CAMERA = "GEOMETRY_CAMERA";
-const char* SHADOW_CAMERA = "SHADOW_CAMERA";
-const char* LIGHTING_CAMERA = "LIGHTING_CAMERA";
-const char* DISPLAY_CAMERA = "DISPLAY_CAMERA";
+const char* MAIN_CAMERA = "main";
+const char* FAR_CAMERA = "far";
+const char* GEOMETRY_CAMERA = "geometry";
+const char* SHADOW_CAMERA = "shadow";
+const char* LIGHTING_CAMERA = "lighting";
+const char* DISPLAY_CAMERA = "display";
 }
 
 static osg::Matrix
@@ -197,7 +196,11 @@ void CameraInfo::updateCameras()
     for (CameraMap::iterator ii = cameras.begin(); ii != cameras.end(); ++ii ) {
         float f = ii->second.scaleFactor;
         if ( f == 0.0f ) continue;
-        ii->second.camera->getViewport()->setViewport(x*f, y*f, width*f, height*f);
+
+        if (ii->second.camera->getRenderTargetImplementation() == osg::Camera::FRAME_BUFFER_OBJECT)
+            ii->second.camera->getViewport()->setViewport(0, 0, width*f, height*f);
+        else
+            ii->second.camera->getViewport()->setViewport(x*f, y*f, width*f, height*f);
     }
 
     for (RenderBufferMap::iterator ii = buffers.begin(); ii != buffers.end(); ++ii ) {
@@ -213,6 +216,9 @@ void CameraInfo::updateCameras()
 
 void CameraInfo::resized(double w, double h)
 {
+    if (w == 1.0 && h == 1.0)
+        return;
+
     bufferSize->set( osg::Vec2f( w, h ) );
 
     for (RenderBufferMap::iterator ii = buffers.begin(); ii != buffers.end(); ++ii) {
@@ -275,8 +281,13 @@ int CameraInfo::getMainSlaveIndex() const
 void CameraInfo::setMatrices(osg::Camera* c)
 {
     view->set( c->getViewMatrix() );
-    viewInverse->set( osg::Matrix::inverse( c->getViewMatrix() ) );
+    osg::Matrixd vi = c->getInverseViewMatrix();
+    viewInverse->set( vi );
     projInverse->set( osg::Matrix::inverse( c->getProjectionMatrix() ) );
+    osg::Vec4d pos = osg::Vec4d(0., 0., 0., 1.) * vi;
+    worldPosCart->set( osg::Vec3f( pos.x(), pos.y(), pos.z() ) );
+    SGGeod pos2 = SGGeod::fromCart( SGVec3d( pos.x(), pos.y(), pos.z() ) );
+    worldPosGeod->set( osg::Vec3f( pos2.getLongitudeRad(), pos2.getLatitudeRad(), pos2.getElevationM() ) );
 }
 
 void CameraGroup::update(const osg::Vec3d& position,
@@ -751,9 +762,7 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode)
     camera->setInheritanceMask(CullSettings::ALL_VARIABLES
                                & ~(CullSettings::CULL_MASK
                                    | CullSettings::CULLING_MODE
-#if defined(HAVE_CULLSETTINGS_CLEAR_MASK)
                                    | CullSettings::CLEAR_MASK
-#endif
                                    ));
 
     osg::Matrix vOff;
@@ -1000,9 +1009,7 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
     camera->setInheritanceMask(CullSettings::ALL_VARIABLES
                                & ~(CullSettings::COMPUTE_NEAR_FAR_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);
@@ -1036,8 +1043,6 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
 CameraGroup* CameraGroup::buildCameraGroup(osgViewer::Viewer* viewer,
                                            SGPropertyNode* gnode)
 {
-    sgUserDataInit( globals->get_props() );
-
     CameraGroup* cgroup = new CameraGroup(viewer);
     for (int i = 0; i < gnode->nChildren(); ++i) {
         SGPropertyNode* pNode = gnode->getChild(i);
@@ -1082,6 +1087,18 @@ void CameraGroup::setCameraCullMasks(Node::NodeMask nm)
             camera = info->getCamera( GEOMETRY_CAMERA );
             if (camera == 0) continue;
             camera->setCullMask( nm & ~simgear::MODELLIGHT_BIT );
+
+            camera = info->getCamera( LIGHTING_CAMERA );
+            if (camera == 0) continue;
+            osg::Switch* sw = camera->getChild(0)->asSwitch();
+            for (unsigned int i = 0; i < sw->getNumChildren(); ++i) {
+                osg::Camera* lc = dynamic_cast<osg::Camera*>(sw->getChild(i));
+                if (lc == 0) continue;
+                string name = lc->getName();
+                if (name == "LightCamera") {
+                    lc->setCullMask( (nm & simgear::LIGHTS_BITS) | (lc->getCullMask() & ~simgear::LIGHTS_BITS) );
+                }
+            }
         }
     }
 }