]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/CameraGroup.hxx
commradio: improvements for atis speech
[flightgear.git] / src / Viewer / CameraGroup.hxx
index 3966bcfe65d2b132b98edfd84e8dc1520724a651..4b53359b1fe7d3fa6c532b906e30fdf55abc665d 100644 (file)
@@ -20,6 +20,7 @@
 #include <map>
 #include <string>
 #include <vector>
+#include <memory>
 
 #include <osg/Matrix>
 #include <osg/ref_ptr>
@@ -48,24 +49,16 @@ namespace flightgear
 {
 
 class GraphicsWindow;
-
+class CameraViewportListener;
+class CameraGroupListener;
+    
 struct RenderBufferInfo {
-    enum Kind {
-        REAL_DEPTH_BUFFER, // Only used if depth buffer is a color texture
-        DEPTH_BUFFER,
-        NORMAL_BUFFER,
-        DIFFUSE_BUFFER,
-        SPEC_EMIS_BUFFER,
-        LIGHTING_BUFFER,
-        SHADOW_BUFFER
-    };
-
     RenderBufferInfo(osg::Texture2D* t = 0, float s = 1.0 ) : texture(t), scaleFactor(s) {}
     osg::ref_ptr<osg::Texture2D> texture;
     float scaleFactor;
 };
-typedef std::map<RenderBufferInfo::Kind,RenderBufferInfo> RenderBufferMap;
-typedef std::map<osg::Camera::BufferComponent,size_t> AttachmentMap;
+typedef std::map<std::string,RenderBufferInfo> RenderBufferMap;
+typedef std::map<osg::Camera::BufferComponent,std::string> AttachmentMap;
 
 struct RenderStageInfo {
     RenderStageInfo(osg::Camera* camera_ = 0, int si = -1, bool fs = false)
@@ -82,20 +75,14 @@ struct RenderStageInfo {
     bool resizable;
 };
 
-enum CameraKind {
-    MAIN_CAMERA,
-    FAR_CAMERA,
-    GEOMETRY_CAMERA,
-    SHADOW_CAMERA,
-    BLOOM_CAMERA_1,
-    BLOOM_CAMERA_2,
-    AO_CAMERA_1,
-    AO_CAMERA_2,
-    AO_CAMERA_3,
-    LIGHTING_CAMERA,
-    DISPLAY_CAMERA
-};
-typedef std::map<CameraKind,RenderStageInfo> CameraMap;
+extern const char* MAIN_CAMERA;
+extern const char* FAR_CAMERA;
+extern const char* GEOMETRY_CAMERA;
+extern const char* SHADOW_CAMERA;
+extern const char* LIGHTING_CAMERA;
+extern const char* DISPLAY_CAMERA;
+
+typedef std::map<std::string,RenderStageInfo> CameraMap;
 
 /** A wrapper around osg::Camera that contains some extra information.
  */
@@ -111,15 +98,25 @@ struct CameraInfo : public osg::Referenced
           projInverse( new osg::Uniform( "fg_ProjectionMatrixInverse", osg::Matrixf() ) ),
           viewInverse( new osg::Uniform( "fg_ViewMatrixInverse",osg::Matrixf() ) ),
           view( new osg::Uniform( "fg_ViewMatrix",osg::Matrixf() ) ),
+          worldPosCart( new osg::Uniform( "fg_CameraPositionCart", osg::Vec3f() ) ),
+          worldPosGeod( new osg::Uniform( "fg_CameraPositionGeod", osg::Vec3f() ) ),
           du( new osg::Uniform( "fg_du",osg::Vec4() ) ),
-          dv( new osg::Uniform( "fg_dv",osg::Vec4() ) )
+          dv( new osg::Uniform( "fg_dv",osg::Vec4() ) ),
+          viewportListener(NULL)
     {
+        shadowMatrix[0] = new osg::Uniform("fg_ShadowMatrix_0", osg::Matrixf());
+        shadowMatrix[1] = new osg::Uniform("fg_ShadowMatrix_1", osg::Matrixf());
+        shadowMatrix[2] = new osg::Uniform("fg_ShadowMatrix_2", osg::Matrixf());
+        shadowMatrix[3] = new osg::Uniform("fg_ShadowMatrix_3", osg::Matrixf());
     }
 
+    ~CameraInfo();
+    
     /** Update and resize cameras
      */
     void updateCameras();
     void resized(double w, double h);
+        
     /** The name as given in the config file.
      */
     std::string name;
@@ -148,29 +145,31 @@ struct CameraInfo : public osg::Referenced
     /** the camera objects
      */
     CameraMap cameras;
-    void addCamera( CameraKind k, osg::Camera* c, int si = -1, bool fs = false ) { cameras[k].camera = c; cameras[k].slaveIndex = si; cameras[k].fullscreen = fs; }
-    void addCamera( CameraKind k, osg::Camera* c, bool fs ) { cameras[k].camera = c; cameras[k].fullscreen = fs; }
-    void addCamera( CameraKind k, osg::Camera* c, float s ) { cameras[k].camera = c; cameras[k].scaleFactor = s; }
-    osg::Camera* getCamera(CameraKind k) const;
+    void addCamera( const std::string& k, osg::Camera* c, int si = -1, bool fs = false ) { cameras[k].camera = c; cameras[k].slaveIndex = si; cameras[k].fullscreen = fs; }
+    void addCamera( const std::string& k, osg::Camera* c, bool fs ) { cameras[k].camera = c; cameras[k].fullscreen = fs; }
+    void addCamera( const std::string& k, osg::Camera* c, float s, bool fs = false ) { cameras[k].camera = c; cameras[k].scaleFactor = s; cameras[k].fullscreen = fs; }
+    osg::Camera* getCamera(const std::string& k) const;
     int getMainSlaveIndex() const;
-    RenderStageInfo& getRenderStageInfo( CameraKind k ) { return cameras[k]; }
+    RenderStageInfo& getRenderStageInfo( const std::string& k ) { return cameras[k]; }
 
     /** the buffer objects
      */
     RenderBufferMap buffers;
-    void addBuffer(RenderBufferInfo::Kind k, osg::Texture2D* tex, float scale = 1.0 ) { buffers[k] = RenderBufferInfo(tex,scale); }
-    osg::Texture2D* getBuffer(RenderBufferInfo::Kind k) const;
-
-    osg::ref_ptr<osg::TexGen> shadowTexGen[4];
+    void addBuffer(const std::string& k, osg::Texture2D* tex, float scale = 1.0 ) { buffers[k] = RenderBufferInfo(tex,scale); }
+    osg::Texture2D* getBuffer(const std::string& k) const;
 
     osg::ref_ptr<osg::Uniform> bufferSize;
-    //osg::ref_ptr<osg::Uniform> bloomOffset[2];
     osg::ref_ptr<osg::Uniform> projInverse;
     osg::ref_ptr<osg::Uniform> viewInverse;
     osg::ref_ptr<osg::Uniform> view;
+    osg::ref_ptr<osg::Uniform> worldPosCart;
+    osg::ref_ptr<osg::Uniform> worldPosGeod;
     osg::ref_ptr<osg::Uniform> du;
     osg::ref_ptr<osg::Uniform> dv;
+    osg::ref_ptr<osg::Uniform> shadowMatrix[4];
 
+    CameraViewportListener* viewportListener;
+    
     void setMatrices( osg::Camera* c );
 
     osgUtil::RenderBin::RenderBinList savedTransparentBins;
@@ -182,10 +181,6 @@ struct CameraInfo : public osg::Referenced
     osg::Vec2d thisReference[2];
 };
 
-/** Update the OSG cameras from the camera info.
- */
-void updateCameras(const CameraInfo* info);
-
 class CameraGroup : public osg::Referenced
 {
 public:
@@ -208,6 +203,9 @@ public:
      * @param viewer the viewer
      */
     CameraGroup(osgViewer::Viewer* viewer);
+    
+    ~CameraGroup();
+    
     /** Get the camera group's Viewer.
      * @return the viewer
      */
@@ -246,11 +244,15 @@ public:
      * matters at this time.
      * @param group the group to set.
      */
+   
+    static void buildDefaultGroup(osgViewer::Viewer* viewer);
+    
     static void setDefault(CameraGroup* group) { _defaultGroup = group; }
     /** Get the default CameraGroup.
      * @return the default camera group.
      */
     static CameraGroup* getDefault() { return _defaultGroup.get(); }
+    
     typedef std::vector<osg::ref_ptr<CameraInfo> > CameraList;
     typedef CameraList::iterator CameraIterator;
     typedef CameraList::const_iterator ConstCameraIterator;
@@ -263,12 +265,6 @@ public:
     ConstCameraIterator camerasBegin() const { return _cameras.begin(); }
     ConstCameraIterator camerasEnd() const { return _cameras.end(); }
     void addCamera(CameraInfo* info) { _cameras.push_back(info); }
-    /** Build a complete CameraGroup from a property node.
-     * @param viewer the viewer associated with this camera group.
-     * @param the camera group property node.
-     */
-    static CameraGroup* buildCameraGroup(osgViewer::Viewer* viewer,
-                                         SGPropertyNode* node);
     /** Set the cull mask on all non-GUI cameras
      */
     void setCameraCullMasks(osg::Node::NodeMask nm);
@@ -288,25 +284,34 @@ public:
      * find the GUI camera if one is defined 
      */
     const CameraInfo* getGUICamera() const;
+    
+    void setZNear(float f) { _zNear = f; }
+    void setZFar(float f) { _zFar = f; }
+    void setNearField(float f) { _nearField = f; }
 protected:
     CameraList _cameras;
     osg::ref_ptr<osgViewer::Viewer> _viewer;
     static osg::ref_ptr<CameraGroup> _defaultGroup;
+    std::auto_ptr<CameraGroupListener> _listener;
+    
     // Near, far for the master camera if used.
     float _zNear;
     float _zFar;
     float _nearField;
+    
     typedef std::map<std::string, osg::ref_ptr<osg::TextureRectangle> > TextureMap;
     TextureMap _textureTargets;
+    
+    /** Build a complete CameraGroup from a property node.
+     * @param viewer the viewer associated with this camera group.
+     * @param the camera group property node.
+     */
+    static CameraGroup* buildCameraGroup(osgViewer::Viewer* viewer,
+                                         SGPropertyNode* node);
 };
 
 }
 
-namespace osgGA
-{
-class GUIEventAdapter;
-}
-
 namespace flightgear
 {
 /** Get the osg::Camera that draws the GUI, if any, from a camera
@@ -325,7 +330,7 @@ osg::Camera* getGUICamera(CameraGroup* cgroup);
  * @return true if any intersections are found
  */
 bool computeIntersections(const CameraGroup* cgroup,
-                          const osgGA::GUIEventAdapter* ea,
+                          const osg::Vec2d& windowPos,
                           osgUtil::LineSegmentIntersector::Intersections&
                           intersections);
 /** Warp the pointer to coordinates in the GUI camera of a camera group.