00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _osgVRJ_Application_
00010 #define _osgVRJ_Application_
00011
00012
00013 #include "osgVRJ.h"
00014
00015
00016 #include <vrj/Draw/OGL/GlApp.h>
00017 #include <vrj/Draw/OGL/GlContextData.h>
00018
00019
00020 #include <osg/Referenced>
00021 #include <osg/Matrix>
00022 #include <osgUtil/SceneView>
00023
00024 #include <list>
00025 #include <string>
00026
00027
00028
00029 namespace vrj
00030 {
00031 class Kernel;
00032 class GlDrawManager;
00033 };
00034
00035 namespace osg
00036 {
00037 class FrameStamp;
00038 class MatrixTransform;
00039 class Node;
00040 };
00041
00042 namespace osgUtil
00043 {
00044 };
00045
00046
00047 namespace osgVRJ
00048 {
00049
00050 class OSG_VRJ_EXPORT Application : public vrj::GlApp, public osg::Referenced
00051 {
00052 public:
00053
00054 Application();
00055 Application(vrj::Kernel*);
00056 Application(const std::list<std::string>&);
00057
00058
00059 virtual void contextInit();
00060 virtual void contextPreDraw();
00061 virtual void init();
00062 virtual void preFrame();
00063 virtual void postFrame();
00064 virtual void viewAll (osg::MatrixTransform *mt,osg::Matrix::value_type zScale=2);
00065
00066 void setBackgroundColor(const osg::Vec4& bg) { _background_color = bg; _context_in_sync=false; }
00067 const osg::Vec4& getBackgroundColor() const { return _background_color; }
00068
00069 osgUtil::SceneView* getContextSpecificSceneView();
00070
00071 void setFrameStamp(osg::FrameStamp* fs) { _frame_stamp = fs; _context_in_sync=false; }
00072 osg::FrameStamp* getFrameStamp() { return _frame_stamp.get(); }
00073 const osg::FrameStamp* getFrameStamp() const { return _frame_stamp.get(); }
00074
00075 void setGlobalStateSet(osg::StateSet* gss) { _global_stateset = gss; _context_in_sync=false; }
00076 const osg::StateSet* getGlobalStateSet() const { return _global_stateset.get(); }
00077 osg::StateSet* getGlobalStateSet() { return _global_stateset.get(); }
00078
00079 osg::Node* getSceneData();
00080 void setSceneData(osg::Node*);
00081
00082 void setSceneDecorator(osg::Group*);
00083 const osg::Group* getSceneDecorator() const { return _scene_decorator.get(); }
00084
00085 double getTimeSinceStart();
00086
00087 void setUpdateVisitor(osg::NodeVisitor* uv) { _update_visitor = uv; _context_in_sync=false; }
00088 const osg::NodeVisitor* getUpdateVisitor() const { return _update_visitor.get(); }
00089
00090 void normalize ( bool state );
00091 bool normalize() const;
00092
00093 void quit();
00094 void run();
00095 void update();
00096
00097 protected:
00098
00099 virtual void draw();
00100 virtual void setViewportByDrawManager(osg::Viewport*,vrj::GlDrawManager*);
00101 virtual void setUpSceneViewWithData(osgUtil::SceneView*);
00102 virtual void initGlobalStateSet();
00103
00104 void _construct();
00105
00106 Application(const Application&);
00107 Application& operator = (const Application&);
00108 virtual ~Application();
00109
00110 private:
00111
00112 osg::ref_ptr<osg::Node> _scene_data;
00113 osg::ref_ptr<osg::FrameStamp> _frame_stamp;
00114 osg::ref_ptr<osg::NodeVisitor> _init_visitor;
00115 osg::ref_ptr<osg::NodeVisitor> _update_visitor;
00116 osg::ref_ptr<osg::StateSet> _global_stateset;
00117 osg::ref_ptr<osg::Group> _scene_decorator;
00118 osg::ref_ptr<osg::Viewport> _viewport;
00119
00120 osg::Vec4 _background_color;
00121
00122 bool _context_in_sync;
00123 unsigned int _frameNumber;
00124 double _initial_time;
00125
00126 gadget::PositionInterface _head_tracker;
00127 vrj::GlContextData<osg::ref_ptr<osgUtil::SceneView> > _sceneview;
00128 };
00129
00130 };
00131
00132 #endif