osg源码分析osgViewer/Viewer
osg源码分析osgViewer/Viewer
哈全文 发表于1年前
osg源码分析osgViewer/Viewer
  • 发表于 1年前
  • 阅读 45
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】买域名送云解析+SSL证书+建站!>>>   

摘要: 本系列博客主要按照OSG源码层级结构分析OSG源码,首先贴出OSG源码然后以注释的方式不断完善,作为自己的笔记,同时分享给大家!本系列博文会不定期更新修改,当对类中某个类和方法有了进一步理解会再次添加注释分析,本系列博文中对源码分析有些来自于网络和相关书籍,在这里一并感谢!

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under 
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#ifndef OSGVIEWER_Viewer
#define OSGVIEWER_Viewer 1

#include <osg/ArgumentParser>
#include <osgGA/EventVisitor>
#include <osgUtil/UpdateVisitor>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>


namespace osgViewer {

/** Viewer holds a single view on to a single scene.*/
class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
{
    public:

        Viewer();

        Viewer(osg::ArgumentParser& arguments);

        Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        virtual ~Viewer();

        META_Object(osgViewer,Viewer);

        /** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */
        virtual void take(osg::View& rhs);


        /** Set the Stats object used for collect various frame related timing and scene graph stats.*/
        virtual void setViewerStats(osg::Stats* stats) { setStats(stats); }

        /** Get the Viewers Stats object.*/
        virtual osg::Stats* getViewerStats() { return getStats(); }

        /** Get the Viewers Stats object.*/
        virtual const osg::Stats* getViewerStats() const { return getStats(); }


        /** read the viewer configuration from a configuration file.*/
        virtual bool readConfiguration(const std::string& filename);
       
        /** Get whether at least of one of this viewers windows are realized.*/
        virtual bool isRealized() const;

        /** set up windows and associated threads.*/
        virtual void realize();

        virtual void setStartTick(osg::Timer_t tick);
        void setReferenceTime(double time=0.0);

        /** Set the sene graph data that viewer with view.*/
        virtual void setSceneData(osg::Node* node);


        /** Convenience method for setting up the viewer so it can be used embedded in an external managed window.
          * Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */
        virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height);


        virtual double elapsedTime();

        virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); }

        /** Execute a main frame loop.
          * Equivalent to while (!viewer.done()) viewer.frame();
          * Also calls realize() if the viewer is not already realized,
          * and installs trackball manipulator if one is not already assigned.
          */
        virtual int run();

        /** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
        virtual bool checkNeedToDoFrame();

        virtual void advance(double simulationTime=USE_REFERENCE_TIME);

        virtual void eventTraversal();

        virtual void updateTraversal();

        void setCameraWithFocus(osg::Camera* camera) { _cameraWithFocus = camera; }
        osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
        const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }

        virtual void getCameras(Cameras& cameras, bool onlyActive=true);

        virtual void getContexts(Contexts& contexts, bool onlyValid=true);

        virtual void getAllThreads(Threads& threads, bool onlyActive=true);

        virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);

        virtual void getScenes(Scenes& scenes, bool onlyValid=true);

        virtual void getViews(Views& views, bool onlyValid=true);

        /** Get the keyboard and mouse usage of this viewer.*/
        virtual void getUsage(osg::ApplicationUsage& usage) const;


    protected:
   
        void constructorInit();
       
        virtual void viewerInit() { init(); }

        osg::observer_ptr<osg::Camera>              _cameraWithFocus;
       

};


}

#endif

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 14
博文 89
码字总数 22122
×
哈全文
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: