From d91b848a63655ada3987a918d1f9522aef8d4340 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 9 Jun 2002 13:10:09 +0000 Subject: [PATCH] Checked in migration from osgUtil based GUIAdapter code to Neil Salter's osgGA (Gui Abstraction). This may break users code, but all it should require to fix the builds should be a change from osgUtil::CameraManipulator (etc) to osgGA::CameraManipulator and include +#include #include namespace osgGLUT{ -/** Class for adapting GLUT events so that they can be used as input to osgUtil::CameraManipulators.*/ -class OSGGLUT_EXPORT GLUTEventAdapter : public osgUtil::GUIEventAdapter +/** Class for adapting GLUT events so that they can be used as input to osgGA::CameraManipulators.*/ +class OSGGLUT_EXPORT GLUTEventAdapter : public osgGA::GUIEventAdapter { public: diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index b71d1791f..f037516a5 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -11,8 +11,9 @@ #include #include -#include -#include +#include +#include + #include #include @@ -28,7 +29,7 @@ namespace osgGLUT * but shouldn't be viewed as the be all and end of osg viewer classes. * Someone please rewrite it :-) */ -class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter +class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter { public: @@ -75,12 +76,12 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter void help(std::ostream& fout); // handle multiple camera. - unsigned int registerCameraManipulator(osgUtil::CameraManipulator* cm, + unsigned int registerCameraManipulator(osgGA::CameraManipulator* cm, unsigned int viewport = 0); void selectCameraManipulator(unsigned int pos, unsigned int viewport = 0); - // derived from osgUtil::GUIActionAdapter + // derived from osgGA::GUIActionAdapter virtual void requestRedraw() {} // redraw always by idle callback done. virtual void requestContinuousUpdate(bool /*needed*/) {} // continuous update always virtual void requestWarpPointer(int x,int y); @@ -92,7 +93,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); } const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); } - typedef std::vector > CameraManipList; + typedef std::vector > CameraManipList; protected: @@ -112,13 +113,14 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter static Viewer* s_theViewer; + typedef std::vector > CameraManipList; struct ViewportDef { osg::ref_ptr sceneView; float viewport[4]; // Win-size-relative [0,1] - osg::ref_ptr _cameraManipulator; + osg::ref_ptr _cameraManipulator; CameraManipList _cameraManipList; }; @@ -144,7 +146,6 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter } times[3]; // store up to 3 frames worth of times bool _useDisplayLists; - osg::Timer _timer; osg::Timer_t _tickRatePerSecond; osg::Timer_t _initialTick; diff --git a/include/osgUtil/CameraManipulator b/include/osgUtil/CameraManipulator deleted file mode 100644 index d98322e7f..000000000 --- a/include/osgUtil/CameraManipulator +++ /dev/null @@ -1,76 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_CAMERAMANIPULATOR -#define OSGUTIL_CAMERAMANIPULATOR 1 - -#include -#include - -#include -#include -#include -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT CameraManipulator : public GUIEventHandler -{ - public: - - CameraManipulator(); - virtual ~CameraManipulator(); - - /** attach a camera to the manipulator to be used for specifying view.*/ - virtual void setCamera(osg::Camera*); - - /** get the attached a camera.*/ - virtual const osg::Camera * getCamera() const; - - /** Attach a node to the manipulator. - Automatically detaches previously attached node. - setNode(NULL) detaches previously nodes. - Is ignored by manipulators which do not require a reference model.*/ - virtual void setNode(osg::Node*) {} - - /** Return node if attached.*/ - virtual const osg::Node* getNode() const { return NULL; } - - - void setHomeToUseNode() { _homeToUseNode=true; } - void setHome(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up) - { - _eyeHome = eye; - _centerHome = center; - _upHome = up; - _homeToUseNode = false; - } - - /** Move the camera to the default position. - May be ignored by manipulators if home functionality is not appropriate.*/ - virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {} - - /** Start/restart the manipulator.*/ - virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {} - - /** Handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - - protected: - - // Reference pointer to a camera - osg::ref_ptr _camera; - - bool _homeToUseNode; - osg::Vec3 _eyeHome; - osg::Vec3 _centerHome; - osg::Vec3 _upHome; - -}; - -} - -#endif - diff --git a/include/osgUtil/DriveManipulator b/include/osgUtil/DriveManipulator deleted file mode 100644 index 7617a005d..000000000 --- a/include/osgUtil/DriveManipulator +++ /dev/null @@ -1,72 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_DRIVEMANIPULATOR -#define OSGUTIL_DRIVEMANIPULATOR 1 - -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT DriveManipulator : public CameraManipulator -{ - public: - - DriveManipulator(); - virtual ~DriveManipulator(); - - /** Attach a node to the manipulator. - Automatically detaches previously attached node. - setNode(NULL) detaches previously nodes. - Is ignored by manipulators which do not require a reference model.*/ - virtual void setNode(osg::Node*); - - /** Return node if attached.*/ - virtual const osg::Node* getNode() const; - - /** Move the camera to the default position. - May be ignored by manipulators if home functionality is not appropriate.*/ - virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us); - - /** Start/restart the manipulator.*/ - virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us); - - /** handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - private: - - /** Reset the internal GUIEvent stack.*/ - void flushMouseEventStack(); - /** Add the current mouse GUIEvent to internal stack.*/ - void addMouseEvent(const GUIEventAdapter& ea); - - /** For the give mouse movement calculate the movement of the camera. - Return true is camera has moved and a redraw is required.*/ - bool calcMovement(); - - // Internal event stack comprising last three mouse events. - osg::ref_ptr _ga_t1; - osg::ref_ptr _ga_t0; - - osg::ref_ptr _node; - - float _modelScale; - float _velocity; - float _height; - float _buffer; - - enum SpeedControlMode { - USE_MOUSE_Y_FOR_SPEED, - USE_MOUSE_BUTTONS_FOR_SPEED - }; - - SpeedControlMode _speedMode; - -}; - -} - -#endif - diff --git a/include/osgUtil/FlightManipulator b/include/osgUtil/FlightManipulator deleted file mode 100644 index 593b485c6..000000000 --- a/include/osgUtil/FlightManipulator +++ /dev/null @@ -1,73 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_FLIGHTMANIPULATOR -#define OSGUTIL_FLIGHTMANIPULATOR 1 - -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT FlightManipulator : public CameraManipulator -{ - public: - - FlightManipulator(); - virtual ~FlightManipulator(); - - /** Attach a node to the manipulator. - Automatically detaches previously attached node. - setNode(NULL) detaches previously nodes. - Is ignored by manipulators which do not require a reference model.*/ - virtual void setNode(osg::Node*); - - /** Return node if attached.*/ - virtual const osg::Node* getNode() const; - - /** Move the camera to the default position. - May be ignored by manipulators if home functionality is not appropriate.*/ - virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us); - - /** Start/restart the manipulator.*/ - virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us); - - /** handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - enum YawControlMode { - YAW_AUTOMATICALLY_WHEN_BANKED, - NO_AUTOMATIC_YAW - }; - - /** Set the yaw control between no yaw and yawing when banked.*/ - void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; } - - private: - - /** Reset the internal GUIEvent stack.*/ - void flushMouseEventStack(); - /** Add the current mouse GUIEvent to internal stack.*/ - void addMouseEvent(const GUIEventAdapter& ea); - - /** For the give mouse movement calculate the movement of the camera. - Return true is camera has moved and a redraw is required.*/ - bool calcMovement(); - - // Internal event stack comprising last three mouse events. - osg::ref_ptr _ga_t1; - osg::ref_ptr _ga_t0; - - osg::ref_ptr _node; - - float _modelScale; - float _velocity; - - YawControlMode _yawMode; - -}; - -} - -#endif - diff --git a/include/osgUtil/GUIActionAdapter b/include/osgUtil/GUIActionAdapter deleted file mode 100644 index 5ca434047..000000000 --- a/include/osgUtil/GUIActionAdapter +++ /dev/null @@ -1,55 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_GUIACTIONADAPTER -#define OSGUTIL_GUIACTIONADAPTER 1 - -#include - -namespace osgUtil{ - - -/** Pure virtual base class for adapting the GUI actions requested by CameraManipulators - * into actions which are handled by the GUI toolkit of the users application. - * - * There are several was of using the ActionAdapter either inheriting it as - * done with osgGLUT::Viewer class or passing a simple struct to the camera - * manipulator then unpacking the results and working out what to do to respond - * to the requests. - * - * Also there are several ways to run your app and handle the updating of - * the window. osgGLUT::Viewer always has a idle callback registered which does a - * redraw all the time. osgGLUT::Viewer can safely ignore both requestRedraw() and - * requestContinousUpdate() as these are happening all the time anyway. - * - * Other apps will probably want to respond to the requestRedraw() and - * requestContinousUpdate(bool) and again there is more than one way to handle it. - * You can override requestRedraw() and implement to call your own window - * redraw straight away. Or you can implement so that a flag is set and - * then you then respond the flag being set in your own leisure. - * - * requestContinousUpdate(bool) is for enabling a throw or idle - * callback to be requested by the camera manipulator. Again you can respond - * to this immediately by registering a idle callback or a timed callback, or - * you can delay setting the callback and do at you own leisure. - * - * requestWarpPointer(int,int) is requesting a respositioning of a mouse pointer - * to a specified x,y location on the window. Used by some camera manipulators - * to initialize the mouse pointer when mouse position relative to a controls - * neutral mouse position is required, i.e when mimicking a aircrafts joystick. - */ -class GUIActionAdapter -{ - public: - - virtual void requestRedraw() = 0; - virtual void requestContinuousUpdate(bool needed=true) = 0; - virtual void requestWarpPointer(int x,int y) = 0; - -}; - -} - -#endif - diff --git a/include/osgUtil/GUIEventAdapter b/include/osgUtil/GUIEventAdapter deleted file mode 100644 index f0c998599..000000000 --- a/include/osgUtil/GUIEventAdapter +++ /dev/null @@ -1,89 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_GUIEVENTADAPTER -#define OSGUTIL_GUIEVENTADAPTER 1 - -#include -#include - -namespace osgUtil{ - - -/** Pure virtual base class for adapting platform specific events into - * generic keyboard and mouse events. - * - * Used as GUI toolkit independent input into the osgUtil::CameraManipualor's. - * For an example of how GUIEventAdapter is specialised for a particular GUI - * Toolkit see osgGLUT::GLUTEventAdapter. - */ -class GUIEventAdapter : public osg::Referenced -{ - public: - - GUIEventAdapter() {} - - - enum MouseButtonMask { - LEFT_MOUSE_BUTTON=1, - MIDDLE_MOUSE_BUTTON=2, - RIGHT_MOUSE_BUTTON=4 - }; - - enum EventType { - PUSH, - RELEASE, - DRAG, - MOVE, - KEYBOARD, - FRAME, - RESIZE, - NONE - }; - - /** Get the EventType of the GUI event.*/ - virtual EventType getEventType() const = 0; - - /** key pressed, return -1 if inappropriate for this event. */ - virtual int getKey() const = 0; - - /** button pressed/released, return -1 if inappropriate for this event.*/ - virtual int getButton() const = 0; - - /** window minimum x. */ - virtual int getXmin() const = 0; - - /** window maximum x. */ - virtual int getXmax() const = 0; - - /** window minimum y. */ - virtual int getYmin() const = 0; - - /** window maximum y. */ - virtual int getYmax() const = 0; - - /** current mouse x position.*/ - virtual int getX() const = 0; - - /** current mouse y position.*/ - virtual int getY() const = 0; - - /** current mouse button state */ - virtual unsigned int getButtonMask() const = 0; - - /** time in seconds of event. */ - virtual double time() const = 0; - - - protected: - - /** Force users to create on heap, so that multiple referencing is safe.*/ - virtual ~GUIEventAdapter() {} - -}; - -} - -#endif - diff --git a/include/osgUtil/GUIEventHandler b/include/osgUtil/GUIEventHandler deleted file mode 100644 index f7cd0701c..000000000 --- a/include/osgUtil/GUIEventHandler +++ /dev/null @@ -1,27 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_GUIEVENTHANDLER -#define OSGUTIL_GUIEVENTHANDLER 1 - -#include - -#include -#include -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT GUIEventHandler : public osg::Referenced -{ - public: - - /** Handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us)=0; - -}; - -} - -#endif diff --git a/include/osgUtil/SceneViewManipulator b/include/osgUtil/SceneViewManipulator deleted file mode 100644 index 198dcc207..000000000 --- a/include/osgUtil/SceneViewManipulator +++ /dev/null @@ -1,66 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_SceneViewManipulator -#define OSGUTIL_SceneViewManipulator 1 - -#include -#include -#include -#include -#include -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT SceneViewManipulator : public GUIEventHandler -{ - public: - - SceneViewManipulator(); - virtual ~SceneViewManipulator(); - - /** attach a scene view to the manipulator. */ - virtual void setSceneView(SceneView*); - - /** get the attached a scene view.*/ - virtual SceneView * getSceneView(); - - /** get the attached a const scene view.*/ - virtual const SceneView * getSceneView() const; - - /** Set the camera manipulator on the object.*/ - virtual void setCameraManipulator(CameraManipulator *cm) {_cm=cm;} - - /** Get the camera manipulator on the object */ - virtual CameraManipulator *getCameraManipulator() {return _cm.get();} - - /** Get the const camera manipulator on the object */ - virtual const CameraManipulator *getCameraManipulator() const {return _cm.get();} - - /** Set the geostate manipulator on the object.*/ - virtual void setStateSetManipulator(StateSetManipulator *cm) {_gm=cm;} - - /** Get the geostate manipulator on the object */ - virtual StateSetManipulator *getStateSetManipulator() { return _gm.get();} - - /** Get the geostate manipulator on the object */ - virtual const StateSetManipulator *getStateSetManipulator() const {return _gm.get();} - - /** Handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - protected: - - // Reference pointer to our scene view - osg::ref_ptr _sv; - - osg::ref_ptr _cm; - osg::ref_ptr _gm; - -}; - -} - -#endif diff --git a/include/osgUtil/StateSetManipulator b/include/osgUtil/StateSetManipulator deleted file mode 100644 index a49514f8e..000000000 --- a/include/osgUtil/StateSetManipulator +++ /dev/null @@ -1,48 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_GEOSTATE_MANIPULATOR -#define OSGUTIL_GEOSTATE_MANIPULATOR 1 - -#include - -#include -#include -#include -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT StateSetManipulator : public GUIEventHandler -{ - public: - - StateSetManipulator(); - virtual ~StateSetManipulator(); - - /** attach a geostate to the manipulator to be used for specifying view.*/ - virtual void setStateSet(osg::StateSet*); - - /** get the attached a geostate.*/ - virtual osg::StateSet * getStateSet(); - - /** get the attached a geostate.*/ - virtual const osg::StateSet * getStateSet() const; - - /** Handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - protected: - - // Reference pointer to a geostate - osg::ref_ptr _drawState; - - bool _backface; - bool _lighting; - bool _texture; -}; - -} - -#endif diff --git a/include/osgUtil/TrackballManipulator b/include/osgUtil/TrackballManipulator deleted file mode 100644 index 38df6d270..000000000 --- a/include/osgUtil/TrackballManipulator +++ /dev/null @@ -1,74 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSGUTIL_TRACKBALLMANIPULATOR -#define OSGUTIL_TRACKBALLMANIPULATOR 1 - -#include - -namespace osgUtil{ - -class OSGUTIL_EXPORT TrackballManipulator : public CameraManipulator -{ - public: - - TrackballManipulator(); - virtual ~TrackballManipulator(); - - /** Attach a node to the manipulator. - Automatically detaches previously attached node. - setNode(NULL) detaches previously nodes. - Is ignored by manipulators which do not require a reference model.*/ - virtual void setNode(osg::Node*); - - /** Return node if attached.*/ - virtual const osg::Node* getNode() const; - - /** Move the camera to the default position. - May be ignored by manipulators if home functionality is not appropriate.*/ - virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us); - - /** Start/restart the manipulator.*/ - virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us); - - - /** handle events, return true if handled, false otherwise.*/ - virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); - - private: - - /** Reset the internal GUIEvent stack.*/ - void flushMouseEventStack(); - /** Add the current mouse GUIEvent to internal stack.*/ - void addMouseEvent(const GUIEventAdapter& ea); - - /** For the give mouse movement calculate the movement of the camera. - Return true is camera has moved and a redraw is required.*/ - bool calcMovement(); - - void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y); - float tb_project_to_sphere(float r, float x, float y); - - - /** Check the speed at which the mouse is moving. - If speed is below a threshold then return false, otherwise return true.*/ - bool isMouseMoving(); - - // Internal event stack comprising last three mouse events. - osg::ref_ptr _ga_t1; - osg::ref_ptr _ga_t0; - - osg::ref_ptr _node; - - float _modelScale; - float _minimumZoomScale; - - bool _thrown; - -}; - -} - -#endif - diff --git a/src/Demos/hangglide/GliderManipulator.cpp b/src/Demos/hangglide/GliderManipulator.cpp index 92aeda757..3cd3470ce 100644 --- a/src/Demos/hangglide/GliderManipulator.cpp +++ b/src/Demos/hangglide/GliderManipulator.cpp @@ -4,7 +4,7 @@ #include using namespace osg; -using namespace osgUtil; +using namespace osgGA; GliderManipulator::GliderManipulator() { diff --git a/src/Demos/hangglide/GliderManipulator.h b/src/Demos/hangglide/GliderManipulator.h index c3fa4cc48..03d232dd2 100644 --- a/src/Demos/hangglide/GliderManipulator.h +++ b/src/Demos/hangglide/GliderManipulator.h @@ -1,9 +1,9 @@ #ifndef HANGGLIDE_GLIDERMANIPULATOR #define HANGGLIDE_GLIDERMANIPULATOR 1 -#include +#include -class GliderManipulator : public osgUtil::CameraManipulator +class GliderManipulator : public osgGA::CameraManipulator { public: @@ -21,13 +21,13 @@ class GliderManipulator : public osgUtil::CameraManipulator /** Move the camera to the default position. May be ignored by manipulators if home functionality is not appropriate.*/ - virtual void home(const osgUtil::GUIEventAdapter& ea,osgUtil::GUIActionAdapter& us); + virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); /** Start/restart the manipulator.*/ - virtual void init(const osgUtil::GUIEventAdapter& ea,osgUtil::GUIActionAdapter& us); + virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); /** handle events, return true if handled, false otherwise.*/ - virtual bool handle(const osgUtil::GUIEventAdapter& ea,osgUtil::GUIActionAdapter& us); + virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); enum YawControlMode { YAW_AUTOMATICALLY_WHEN_BANKED, @@ -42,15 +42,15 @@ class GliderManipulator : public osgUtil::CameraManipulator /** Reset the internal GUIEvent stack.*/ void flushMouseEventStack(); /** Add the current mouse GUIEvent to internal stack.*/ - void addMouseEvent(const osgUtil::GUIEventAdapter& ea); + void addMouseEvent(const osgGA::GUIEventAdapter& ea); /** For the give mouse movement calculate the movement of the camera. Return true is camera has moved and a redraw is required.*/ bool calcMovement(); // Internal event stack comprising last three mouse events. - osg::ref_ptr _ga_t1; - osg::ref_ptr _ga_t0; + osg::ref_ptr _ga_t1; + osg::ref_ptr _ga_t0; osg::ref_ptr _node; diff --git a/src/Demos/osgbillboard/osgbillboard.cpp b/src/Demos/osgbillboard/osgbillboard.cpp index 134ba6fb6..74e090cec 100644 --- a/src/Demos/osgbillboard/osgbillboard.cpp +++ b/src/Demos/osgbillboard/osgbillboard.cpp @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -411,9 +411,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootNode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(osgNew osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(osgNew osgUtil::FlightManipulator); - viewer.registerCameraManipulator(osgNew osgUtil::DriveManipulator); + viewer.registerCameraManipulator(osgNew osgGA::TrackballManipulator); + viewer.registerCameraManipulator(osgNew osgGA::FlightManipulator); + viewer.registerCameraManipulator(osgNew osgGA::DriveManipulator); viewer.open(); diff --git a/src/Demos/osgcallback/osgcallback.cpp b/src/Demos/osgcallback/osgcallback.cpp index 31b62a156..73e01dd7d 100644 --- a/src/Demos/osgcallback/osgcallback.cpp +++ b/src/Demos/osgcallback/osgcallback.cpp @@ -12,9 +12,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include @@ -237,9 +237,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgclip/osgclip.cpp b/src/Demos/osgclip/osgclip.cpp index 642432bf9..14694db16 100644 --- a/src/Demos/osgclip/osgclip.cpp +++ b/src/Demos/osgclip/osgclip.cpp @@ -12,9 +12,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -175,9 +175,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgcluster/osgcluster.cpp b/src/Demos/osgcluster/osgcluster.cpp index 0b1685cfc..a80b2a9e5 100644 --- a/src/Demos/osgcluster/osgcluster.cpp +++ b/src/Demos/osgcluster/osgcluster.cpp @@ -8,9 +8,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -385,9 +385,9 @@ int main( int argc, char **argv ) viewer.addViewport( mySceneView.get() ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); viewer.open(); viewer.run(); diff --git a/src/Demos/osgcopy/osgcopy.cpp b/src/Demos/osgcopy/osgcopy.cpp index 44fd7578c..051c98ece 100644 --- a/src/Demos/osgcopy/osgcopy.cpp +++ b/src/Demos/osgcopy/osgcopy.cpp @@ -9,9 +9,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -263,9 +263,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index d7bddd265..aa664ad78 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -210,7 +210,7 @@ int main( int argc, char **argv ) viewer.addViewport( myTransform ); // register trackball maniupulators. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); viewer.open(); diff --git a/src/Demos/osghud/osghud.cpp b/src/Demos/osghud/osghud.cpp index de4f3331f..df079c322 100644 --- a/src/Demos/osghud/osghud.cpp +++ b/src/Demos/osghud/osghud.cpp @@ -15,9 +15,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include @@ -350,9 +350,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgimpostor/osgimpostor.cpp b/src/Demos/osgimpostor/osgimpostor.cpp index 90654b907..b0af8ec0b 100644 --- a/src/Demos/osgimpostor/osgimpostor.cpp +++ b/src/Demos/osgimpostor/osgimpostor.cpp @@ -4,9 +4,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -142,9 +142,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); viewer.open(); viewer.run(); diff --git a/src/Demos/osgoccluder/osgoccluder.cpp b/src/Demos/osgoccluder/osgoccluder.cpp index e34086ff2..facd8fa51 100644 --- a/src/Demos/osgoccluder/osgoccluder.cpp +++ b/src/Demos/osgoccluder/osgoccluder.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include @@ -167,9 +167,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgparticle/osgparticle.cpp b/src/Demos/osgparticle/osgparticle.cpp index 79194b794..ab546c6ec 100644 --- a/src/Demos/osgparticle/osgparticle.cpp +++ b/src/Demos/osgparticle/osgparticle.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include // ---------------------------------------------------------------------------------- @@ -106,9 +106,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index 6fca0ec93..be8bd7480 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -9,9 +9,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -372,9 +372,9 @@ int main( int argc, char **argv ) loadedModelTransform->setAppCallback(nc); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); viewer.open(); diff --git a/src/Demos/osgscribe/osgscribe.cpp b/src/Demos/osgscribe/osgscribe.cpp index 5aaed1a17..71ddf00c1 100644 --- a/src/Demos/osgscribe/osgscribe.cpp +++ b/src/Demos/osgscribe/osgscribe.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -138,9 +138,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/Demos/osgstereoimage/osgstereoimage.cpp b/src/Demos/osgstereoimage/osgstereoimage.cpp index 93f8422a4..45c98f22a 100644 --- a/src/Demos/osgstereoimage/osgstereoimage.cpp +++ b/src/Demos/osgstereoimage/osgstereoimage.cpp @@ -4,9 +4,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -124,7 +124,7 @@ int main( int argc, char **argv ) viewer.addViewport( sceneview ); // register trackball. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); viewer.open(); diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 9c2b658a7..b843f8ad5 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -604,9 +604,9 @@ int main( int argc, char **argv ) viewer.addHUD(scene2d); // register trackball, flight and drive. - viewer.registerCameraManipulator(osgNew osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(osgNew osgUtil::FlightManipulator); - viewer.registerCameraManipulator(osgNew osgUtil::DriveManipulator); + viewer.registerCameraManipulator(osgNew osgGA::TrackballManipulator); + viewer.registerCameraManipulator(osgNew osgGA::FlightManipulator); + viewer.registerCameraManipulator(osgNew osgGA::DriveManipulator); viewer.open(); viewer.run(); diff --git a/src/Demos/osgtexture/osgtexture.cpp b/src/Demos/osgtexture/osgtexture.cpp index 510b06b8f..969406e81 100644 --- a/src/Demos/osgtexture/osgtexture.cpp +++ b/src/Demos/osgtexture/osgtexture.cpp @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -467,9 +467,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootNode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); viewer.open(); diff --git a/src/Demos/osgviews/osgviews.cpp b/src/Demos/osgviews/osgviews.cpp index 053b2ebd9..57ead3374 100644 --- a/src/Demos/osgviews/osgviews.cpp +++ b/src/Demos/osgviews/osgviews.cpp @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -89,9 +89,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode,0.0,0.5,1.0,0.5); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); viewer.open(); viewer.run(); diff --git a/src/Demos/sgv/sgv.cpp b/src/Demos/sgv/sgv.cpp index 46e69de32..3d781a54b 100644 --- a/src/Demos/sgv/sgv.cpp +++ b/src/Demos/sgv/sgv.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include @@ -95,9 +95,9 @@ int main( int argc, char **argv ) viewer.addViewport( rootnode ); // register trackball, flight and drive. - viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); - viewer.registerCameraManipulator(new osgUtil::FlightManipulator); - viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + viewer.registerCameraManipulator(new osgGA::TrackballManipulator); + viewer.registerCameraManipulator(new osgGA::FlightManipulator); + viewer.registerCameraManipulator(new osgGA::DriveManipulator); // open the viewer window. viewer.open(); diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index d015c7b2c..fd0b67d2b 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -65,7 +65,7 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) bool cameraSet = false; - osg::ref_ptr segDown = new osg::LineSegment; + osg::ref_ptr segDown = osgNew osg::LineSegment; segDown->set(ep,bp); iv.addLineSegment(segDown.get()); @@ -104,7 +104,7 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) bp = ep; bp.z() += _modelScale; - osg::ref_ptr segUp = new osg::LineSegment; + osg::ref_ptr segUp = osgNew osg::LineSegment; segUp->set(ep,bp); iv.addLineSegment(segUp.get()); @@ -180,7 +180,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) bool cameraSet = false; - osg::ref_ptr segDown = new osg::LineSegment; + osg::ref_ptr segDown = osgNew osg::LineSegment; segDown->set(ep,bp); iv.addLineSegment(segDown.get()); @@ -219,7 +219,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) bp = ep; bp.z() += _modelScale; - osg::ref_ptr segUp = new osg::LineSegment; + osg::ref_ptr segUp = osgNew osg::LineSegment; segUp->set(ep,bp); iv.addLineSegment(segUp.get()); @@ -375,7 +375,7 @@ bool DriveManipulator::calcMovement() // return if less then two events have been added. if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - float dt = _ga_t0->time()-_ga_t1->time(); + double dt = _ga_t0->time()-_ga_t1->time(); if (dt<0.0f) { @@ -457,7 +457,7 @@ bool DriveManipulator::calcMovement() // check to see if any obstruction in front. osgUtil::IntersectVisitor iv; - osg::ref_ptr segForward = new osg::LineSegment; + osg::ref_ptr segForward = osgNew osg::LineSegment; segForward->set(ep,ep+lv*(signedBuffer+distanceToMove)); iv.addLineSegment(segForward.get()); @@ -482,7 +482,7 @@ bool DriveManipulator::calcMovement() iv.reset(); - osg::ref_ptr segNormal = new osg::LineSegment; + osg::ref_ptr segNormal = osgNew osg::LineSegment; segNormal->set(fp,lfp); iv.addLineSegment(segNormal.get()); @@ -520,7 +520,7 @@ bool DriveManipulator::calcMovement() iv.reset(); - osg::ref_ptr segFall = new osg::LineSegment; + osg::ref_ptr segFall = osgNew osg::LineSegment; segFall->set(lfp,dp); iv.addLineSegment(segFall.get()); diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index ca34b4570..3a83c67b1 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -181,7 +181,7 @@ bool FlightManipulator::calcMovement() if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - float dt = _ga_t0->time()-_ga_t1->time(); + double dt = _ga_t0->time()-_ga_t1->time(); if (dt<0.0f) { diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 28fdaeb60..7a1077f57 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -149,6 +149,13 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f); return true; } +// this is quick hack to test out othographic projection. +// else if (ea.getKey()=='O') +// { +// float dist = _camera->getLookDistance(); +// _camera->setOrtho(-dist,dist,-dist,dist,-dist,dist); +// return true; +// } return false; case(GUIEventAdapter::FRAME): _camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE); diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 65e603efc..5d465cb8e 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -41,9 +41,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -75,6 +75,7 @@ int writePrims( const int ypos, osg::Statistics& stats); using namespace osg; using namespace osgUtil; using namespace osgGLUT; +using namespace osgGA; using namespace std; @@ -166,9 +167,9 @@ bool Viewer::open() { osg::notify(osg::INFO)<<"osgGLUT::Viewer::open() called without any camara manipulators registered for a viewport,"<< std::endl; osg::notify(osg::INFO)<<"automatically registering trackball,flight and drive manipulators."<< std::endl; - registerCameraManipulator(osgNew osgUtil::TrackballManipulator, index); - registerCameraManipulator(osgNew osgUtil::FlightManipulator, index); - registerCameraManipulator(osgNew osgUtil::DriveManipulator, index); + registerCameraManipulator(new osgGA::TrackballManipulator, index); + registerCameraManipulator(new osgGA::FlightManipulator, index); + registerCameraManipulator(new osgGA::DriveManipulator, index); } if (!itr->_cameraManipulator.valid()) @@ -279,7 +280,7 @@ bool Viewer::open() -unsigned int Viewer::registerCameraManipulator(osgUtil::CameraManipulator* cm, +unsigned int Viewer::registerCameraManipulator(osgGA::CameraManipulator* cm, unsigned int viewport) { ViewportDef &viewp = _viewportList[viewport]; @@ -750,9 +751,9 @@ void Viewer::mouse(int button, int state, int x, int y) // Switch viewport focus if button is pressed, and it is the only one unsigned mask = ea->getButtonMask(); if (state == GLUT_DOWN && - (mask == osgUtil::GUIEventAdapter::LEFT_MOUSE_BUTTON || - mask == osgUtil::GUIEventAdapter::MIDDLE_MOUSE_BUTTON || - mask == osgUtil::GUIEventAdapter::RIGHT_MOUSE_BUTTON)) + (mask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON || + mask == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON || + mask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)) { int focus = mapWindowXYToSceneView(x,y); if (focus >= 0 && focus != int(_focusedViewport)) diff --git a/src/osgUtil/CameraManipulator.cpp b/src/osgUtil/CameraManipulator.cpp deleted file mode 100644 index e763b1042..000000000 --- a/src/osgUtil/CameraManipulator.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include - -using namespace osg; -using namespace osgUtil; - -CameraManipulator::CameraManipulator(): _camera(NULL) -{ - _homeToUseNode = true; - _eyeHome.set(0.0,0.0,0.0); - _centerHome.set(0.0,0.0,-1.0); - _upHome.set(0.0,1.0,0.0); -} - - -CameraManipulator::~CameraManipulator() -{ -} - - -void CameraManipulator::setCamera(Camera *camera) -{ - _camera=camera; -} - - -const Camera *CameraManipulator::getCamera() const -{ - return _camera.get(); -} - - -bool CameraManipulator::handle(const GUIEventAdapter&,GUIActionAdapter&) -{ - return false; -} diff --git a/src/osgUtil/DriveManipulator.cpp b/src/osgUtil/DriveManipulator.cpp deleted file mode 100644 index 002d6031a..000000000 --- a/src/osgUtil/DriveManipulator.cpp +++ /dev/null @@ -1,560 +0,0 @@ -#if defined(_MSC_VER) - #pragma warning( disable : 4786 ) -#endif - -#include -#include -#include - -using namespace osg; -using namespace osgUtil; - -DriveManipulator::DriveManipulator() -{ - _modelScale = 0.01f; - _velocity = 0.0f; - //_speedMode = USE_MOUSE_Y_FOR_SPEED; - _speedMode = USE_MOUSE_BUTTONS_FOR_SPEED; -} - - -DriveManipulator::~DriveManipulator() -{ -} - - -void DriveManipulator::setNode(osg::Node* node) -{ - _node = node; - if (_node.get()) - { - const osg::BoundingSphere& boundingSphere=_node->getBound(); - _modelScale = boundingSphere._radius; - _height = sqrtf(_modelScale)*0.03f; - _buffer = sqrtf(_modelScale)*0.05f; - } -} - - -const osg::Node* DriveManipulator::getNode() const -{ - return _node.get(); -} - - -void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - - if(_node.get() && _camera.get()) - { - - const osg::BoundingSphere& boundingSphere=_node->getBound(); - - osg::Vec3 ep = boundingSphere._center; - osg::Vec3 bp = ep; - ep.z() -= _modelScale*0.0001f; - bp.z() -= _modelScale; - - // check to see if any obstruction in front. - IntersectVisitor iv; - - bool cameraSet = false; - - osg::ref_ptr segDown = osgNew osg::LineSegment; - segDown->set(ep,bp); - iv.addLineSegment(segDown.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - osg::Vec3 uv; - if (np.z()>0.0f) uv = np; - else uv = -np; - - float lookDistance = _modelScale*0.1f; - - ep = ip; - ep.z() += _height; - osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f); - osg::Vec3 cp = ep+lv*lookDistance; - - _camera->setLookAt(ep,cp,uv); - - cameraSet = true; - - } - - } - - if (!cameraSet) - { - bp = ep; - bp.z() += _modelScale; - - osg::ref_ptr segUp = osgNew osg::LineSegment; - segUp->set(ep,bp); - iv.addLineSegment(segUp.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segUp.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - osg::Vec3 uv; - if (np.z()>0.0f) uv = np; - else uv = -np; - - float lookDistance = _modelScale*0.1f; - - ep = ip; - ep.z() += _height; - osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f); - osg::Vec3 cp = ep+lv*lookDistance; - - _camera->setLookAt(ep,cp,uv); - - cameraSet = true; - - } - - } - } - - if (!cameraSet) - { - // eye - _camera->setLookAt(boundingSphere._center+osg::Vec3( 0.0,-2.0f * boundingSphere._radius,0.0f), - // look - boundingSphere._center, - // up - osg::Vec3(0.0f,0.0f,1.0f)); - } - - } - - _velocity = 0.0f; - - us.requestRedraw(); - - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); - - flushMouseEventStack(); - -} - - -void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - flushMouseEventStack(); - - us.requestContinuousUpdate(false); - - _velocity = 0.0f; - - osg::Vec3 ep = _camera->getEyePoint(); - osg::Vec3 sv = _camera->getSideVector(); - osg::Vec3 bp = ep; - bp.z() -= _modelScale; - - // check to see if any obstruction in front. - IntersectVisitor iv; - - bool cameraSet = false; - - osg::ref_ptr segDown = osgNew osg::LineSegment; - segDown->set(ep,bp); - iv.addLineSegment(segDown.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - osg::Vec3 uv; - if (np.z()>0.0f) uv = np; - else uv = -np; - - float lookDistance = _modelScale*0.1f; - - ep = ip+uv*_height; - osg::Vec3 lv = uv^sv; - osg::Vec3 lp = ep+lv*lookDistance; - - _camera->setLookAt(ep,lp,uv); - _camera->ensureOrthogonalUpVector(); - - cameraSet = true; - - } - - } - - if (!cameraSet) - { - bp = ep; - bp.z() += _modelScale; - - osg::ref_ptr segUp = osgNew osg::LineSegment; - segUp->set(ep,bp); - iv.addLineSegment(segUp.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segUp.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - osg::Vec3 uv; - if (np.z()>0.0f) uv = np; - else uv = -np; - - float lookDistance = _modelScale*0.1f; - - ep = ip+uv*_height; - osg::Vec3 lv = uv^sv; - osg::Vec3 lp = ep+lv*lookDistance; - - _camera->setLookAt(ep,lp,uv); - _camera->ensureOrthogonalUpVector(); - - cameraSet = true; - - } - - } - } - - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); - -} - - -bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - if(!_camera.get()) return false; - - switch(ea.getEventType()) - { - case(GUIEventAdapter::PUSH): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::RELEASE): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::DRAG): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::MOVE): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::KEYBOARD): - { - if (ea.getKey()==' ') - { - flushMouseEventStack(); - home(ea,us); - us.requestRedraw(); - us.requestContinuousUpdate(false); - return true; - } - else if (ea.getKey()=='q') - { - _speedMode = USE_MOUSE_Y_FOR_SPEED; - return true; - } - else if (ea.getKey()=='a') - { - _speedMode = USE_MOUSE_BUTTONS_FOR_SPEED; - return true; - } - else if (ea.getKey()=='+') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f); - return true; - } - else if (ea.getKey()=='-') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f); - return true; - } - return false; - } - - case(GUIEventAdapter::FRAME): - { - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::RESIZE): - { - init(ea,us); - us.requestRedraw(); - return true; - } - - default: - return false; - } -} - - -void DriveManipulator::flushMouseEventStack() -{ - _ga_t1 = NULL; - _ga_t0 = NULL; -} - - -void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea) -{ - _ga_t1 = _ga_t0; - _ga_t0 = &ea; -} - - -bool DriveManipulator::calcMovement() -{ - _camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE); - - // return if less then two events have been added. - if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - - double dt = _ga_t0->time()-_ga_t1->time(); - - if (dt<0.0f) - { - notify(WARN) << "warning dt = "<getYmin()+_ga_t0->getYmax())/2.0f; - float dy = _ga_t0->getY()-my; - _velocity = -_modelScale*0.0002f*dy; - break; - } - case(USE_MOUSE_BUTTONS_FOR_SPEED): - { - unsigned int buttonMask = _ga_t1->getButtonMask(); - if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON) - { - // pan model. - - _velocity += dt*_modelScale*0.02f; - - } - else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON || - buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON)) - { - - _velocity = 0.0f; - - } - else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON) - { - - _velocity -= dt*_modelScale*0.02f; - - } - break; - } - } - - // rotate the camera. - osg::Vec3 center = _camera->getEyePoint(); - osg::Vec3 uv = _camera->getUpVector(); - - float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f; - - float dx = _ga_t0->getX()-mx; - - float yaw = -inDegrees(dx*0.1f*dt); - - osg::Matrix mat; - mat.makeTranslate(-center.x(),-center.y(),-center.z()); - mat *= Matrix::rotate(yaw,uv.x(),uv.y(),uv.z()); - mat *= Matrix::translate(center.x(),center.y(),center.z()); - - center = _camera->getEyePoint(); - uv = _camera->getUpVector(); - - _camera->transformLookAt(mat); - - // get the new forward (look) vector. - osg::Vec3 sv = _camera->getSideVector(); - osg::Vec3 lv = _camera->getCenterPoint()-_camera->getEyePoint(); - float lookDistance = lv.length(); - lv.normalize(); - - // movement is big enough the move the eye point along the look vector. - if (fabsf(_velocity*dt)>1e-8) - { - osg::Vec3 ep = _camera->getEyePoint(); - float distanceToMove = _velocity*dt; - - float signedBuffer; - if (distanceToMove>=0.0f) signedBuffer=_buffer; - else signedBuffer=-_buffer; - - // check to see if any obstruction in front. - IntersectVisitor iv; - osg::ref_ptr segForward = osgNew osg::LineSegment; - segForward->set(ep,ep+lv*(signedBuffer+distanceToMove)); - iv.addLineSegment(segForward.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segForward.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit obstruction"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - distanceToMove = (ip-ep).length()-_buffer; - _velocity = 0.0f; - } - - } - - // check to see if forward point is correct height above terrain. - osg::Vec3 fp = ep+lv*distanceToMove; - osg::Vec3 lfp = fp-uv*_height*5; - - iv.reset(); - - osg::ref_ptr segNormal = osgNew osg::LineSegment; - segNormal->set(fp,lfp); - iv.addLineSegment(segNormal.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segNormal.get()); - if (!hitList.empty()) - { - // notify(INFO) << "Hit terrain ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - if (uv*np>0.0f) uv = np; - else uv = -np; - - ep = ip+uv*_height; - lv = uv^sv; - osg::Vec3 lp = ep+lv*lookDistance; - - _camera->setLookAt(ep,lp,uv); - _camera->ensureOrthogonalUpVector(); - - return true; - - } - - } - - // no hit on the terrain found therefore resort to a fall under - // under the influence of gravity. - osg::Vec3 dp = lfp; - dp.z() -= 2*_modelScale; - - iv.reset(); - - osg::ref_ptr segFall = osgNew osg::LineSegment; - segFall->set(lfp,dp); - iv.addLineSegment(segFall.get()); - - _node->accept(iv); - - if (iv.hits()) - { - osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segFall.get()); - if (!hitList.empty()) - { - - notify(INFO) << "Hit terrain on decent ok"<< std::endl; - osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); - osg::Vec3 np = hitList.front().getWorldIntersectNormal(); - - if (uv*np>0.0f) uv = np; - else uv = -np; - - ep = ip+uv*_height; - lv = uv^sv; - osg::Vec3 lp = ep+lv*lookDistance; - - _camera->setLookAt(ep,lp,uv); - _camera->ensureOrthogonalUpVector(); - - return true; - } - } - - // no collision with terrain has been found therefore track horizontally. - - lv *= (_velocity*dt); - ep += lv; - osg::Vec3 lp = _camera->getCenterPoint()+lv; - - _camera->setLookAt(ep,lp,uv); - _camera->ensureOrthogonalUpVector(); - - } - - return true; -} diff --git a/src/osgUtil/FlightManipulator.cpp b/src/osgUtil/FlightManipulator.cpp deleted file mode 100644 index 2af65bd4f..000000000 --- a/src/osgUtil/FlightManipulator.cpp +++ /dev/null @@ -1,239 +0,0 @@ -#include -#include -#include - -using namespace osg; -using namespace osgUtil; - -FlightManipulator::FlightManipulator() -{ - _modelScale = 0.01f; - _velocity = 0.0f; - _yawMode = YAW_AUTOMATICALLY_WHEN_BANKED; -} - - -FlightManipulator::~FlightManipulator() -{ -} - - -void FlightManipulator::setNode(osg::Node* node) -{ - _node = node; - if (_node.get()) - { - const osg::BoundingSphere& boundingSphere=_node->getBound(); - _modelScale = boundingSphere._radius; - } -} - - -const osg::Node* FlightManipulator::getNode() const -{ - return _node.get(); -} - - -void FlightManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - if(_node.get() && _camera.get()) - { - - const osg::BoundingSphere& boundingSphere=_node->getBound(); - - _camera->setLookAt( - boundingSphere._center+osg::Vec3( 0.0,-3.0f * boundingSphere._radius,0.0f), - boundingSphere._center, - osg::Vec3(0.0f,0.0f,1.0f)); - - _velocity = 0.0f; - - us.requestRedraw(); - - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); - - flushMouseEventStack(); - - } - -} - - -void FlightManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - flushMouseEventStack(); - - us.requestContinuousUpdate(false); - - _velocity = 0.0f; - - us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2); - -} - - -bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - if(!_camera.get()) return false; - - switch(ea.getEventType()) - { - case(GUIEventAdapter::PUSH): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::RELEASE): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::DRAG): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - return true; - } - - case(GUIEventAdapter::MOVE): - { - - addMouseEvent(ea); - us.requestContinuousUpdate(true); - if (calcMovement()) us.requestRedraw(); - - return true; - } - - case(GUIEventAdapter::KEYBOARD): - if (ea.getKey()==' ') - { - flushMouseEventStack(); - home(ea,us); - us.requestRedraw(); - us.requestContinuousUpdate(false); - return true; - } - else if (ea.getKey()=='+') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f); - return true; - } - else if (ea.getKey()=='-') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f); - return true; - } - return false; - - case(GUIEventAdapter::FRAME): - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - return true; - - case(GUIEventAdapter::RESIZE): - init(ea,us); - us.requestRedraw(); - return true; - - default: - return false; - } -} - - -void FlightManipulator::flushMouseEventStack() -{ - _ga_t1 = NULL; - _ga_t0 = NULL; -} - - -void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea) -{ - _ga_t1 = _ga_t0; - _ga_t0 = &ea; -} - - -bool FlightManipulator::calcMovement() -{ - _camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE); - - // return if less then two events have been added. - if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - - - double dt = _ga_t0->time()-_ga_t1->time(); - - if (dt<0.0f) - { - notify(WARN) << "warning dt = "<getButtonMask(); - if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON) - { - // pan model. - - _velocity += dt*_modelScale*0.05f; - - } - else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON || - buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON)) - { - - _velocity = 0.0f; - - } - else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON) - { - - _velocity -= dt*_modelScale*0.05f; - - } - - float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f; - float my = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f; - - float dx = _ga_t0->getX()-mx; - float dy = _ga_t0->getY()-my; - - osg::Vec3 center = _camera->getEyePoint(); - osg::Vec3 sv = _camera->getSideVector(); - osg::Vec3 lv = _camera->getLookVector(); - - float pitch = inDegrees(dy*0.15f*dt); - float roll = inDegrees(dx*0.1f*dt); - - osg::Matrix mat; - mat.makeTranslate(-center); - mat *= Matrix::rotate(pitch,sv.x(),sv.y(),sv.z()); - mat *= Matrix::rotate(roll,lv.x(),lv.y(),lv.z()); - if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED) - { - float bank = asinf(sv.z()); - float yaw = inRadians(bank)*dt; - mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f); - } - - lv *= (_velocity*dt); - - mat *= Matrix::translate(center+lv); - - _camera->transformLookAt(mat); - - return true; -} diff --git a/src/osgUtil/Makefile b/src/osgUtil/Makefile index 63d6e75f0..36d2c952d 100644 --- a/src/osgUtil/Makefile +++ b/src/osgUtil/Makefile @@ -4,13 +4,10 @@ include $(TOPDIR)/Make/makedefs CXXFILES = \ AppVisitor.cpp\ - CameraManipulator.cpp\ CullVisitor.cpp\ DepthSortedBin.cpp\ DisplayListVisitor.cpp\ DisplayRequirementsVisitor.cpp\ - DriveManipulator.cpp\ - FlightManipulator.cpp\ InsertImpostorsVisitor.cpp\ IntersectVisitor.cpp\ NvTriStripObjects.cpp\ @@ -22,11 +19,8 @@ CXXFILES = \ RenderStageLighting.cpp\ RenderToTextureStage.cpp\ SceneView.cpp\ - SceneViewManipulator.cpp\ SmoothingVisitor.cpp\ - StateSetManipulator.cpp\ Tesselator.cpp\ - TrackballManipulator.cpp\ TransformCallback.cpp\ TriStripVisitor.cpp\ Version.cpp\ diff --git a/src/osgUtil/SceneViewManipulator.cpp b/src/osgUtil/SceneViewManipulator.cpp deleted file mode 100644 index f77011025..000000000 --- a/src/osgUtil/SceneViewManipulator.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace osgUtil; - -SceneViewManipulator::SceneViewManipulator(): - _cm(osgNew TrackballManipulator), - _gm(osgNew StateSetManipulator) -{ -} - -SceneViewManipulator::~SceneViewManipulator() -{ -} - -void SceneViewManipulator::setSceneView(SceneView* sv) -{ - _sv=sv; - _cm->setNode(sv->getSceneData()); - _cm->setCamera(sv->getCamera()); - _gm->setStateSet(sv->getGlobalStateSet()); -} - -SceneView *SceneViewManipulator::getSceneView() -{ - return _sv.get(); -} - -const SceneView *SceneViewManipulator::getSceneView() const -{ - return _sv.get(); -} - -bool SceneViewManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) -{ - if(_cm->handle(ea,aa)) return true; - if(_gm->handle(ea,aa)) return true; - return false; -} diff --git a/src/osgUtil/StateSetManipulator.cpp b/src/osgUtil/StateSetManipulator.cpp deleted file mode 100644 index dec2b38f5..000000000 --- a/src/osgUtil/StateSetManipulator.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include - -using namespace osg; -using namespace osgUtil; - -StateSetManipulator::StateSetManipulator(): _drawState(NULL) -{ -} - -StateSetManipulator::~StateSetManipulator() -{ -} - -void StateSetManipulator::setStateSet(StateSet *drawState) -{ - _drawState=drawState; - if(!_drawState.valid()) return; - _backface = (_drawState->getMode(GL_CULL_FACE)==osg::StateAttribute::ON); - _lighting =(_drawState->getMode(GL_LIGHTING)==osg::StateAttribute::ON); - _texture =(_drawState->getMode(GL_TEXTURE_2D)==osg::StateAttribute::ON); -} - -StateSet *StateSetManipulator::getStateSet() -{ - return _drawState.get(); -} - -const StateSet *StateSetManipulator::getStateSet() const -{ - return _drawState.get(); -} - -bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) -{ - if(!_drawState.valid()) return false; - - if(ea.getEventType()==GUIEventAdapter::KEYBOARD){ - - switch( ea.getKey() ){ - - case 'b' : - _backface = !_backface; - if( _backface ) _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::ON); - else _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE_OFF); - aa.requestRedraw(); - return true; - break; - - case 'l' : - _lighting = !_lighting ; - if( _lighting ) _drawState->setMode(GL_LIGHTING,osg::StateAttribute::ON); - else _drawState->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_OFF); - aa.requestRedraw(); - return true; - break; - - case 't' : - _texture = !_texture; - if (_texture) _drawState->setMode(GL_TEXTURE_2D,osg::StateAttribute::INHERIT); - else _drawState->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF); - aa.requestRedraw(); - return true; - break; - - } - } - return false; -} diff --git a/src/osgUtil/TrackballManipulator.cpp b/src/osgUtil/TrackballManipulator.cpp deleted file mode 100644 index 622aff526..000000000 --- a/src/osgUtil/TrackballManipulator.cpp +++ /dev/null @@ -1,398 +0,0 @@ -#include -#include -#include - -using namespace osg; -using namespace osgUtil; - -TrackballManipulator::TrackballManipulator() -{ - _modelScale = 0.01f; - _minimumZoomScale = 0.05f; - _thrown = false; -} - - -TrackballManipulator::~TrackballManipulator() -{ -} - - -void TrackballManipulator::setNode(osg::Node* node) -{ - _node = node; - if (_node.get()) - { - const osg::BoundingSphere& boundingSphere=_node->getBound(); - _modelScale = boundingSphere._radius; - } -} - - -const osg::Node* TrackballManipulator::getNode() const -{ - return _node.get(); -} - - - /*ea*/ -void TrackballManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us) -{ - if(_node.get() && _camera.get()) - { - - const osg::BoundingSphere& boundingSphere=_node->getBound(); - - _camera->setView(boundingSphere._center+osg::Vec3( 0.0,-3.0f * boundingSphere._radius,0.0f), - boundingSphere._center, - osg::Vec3(0.0f,0.0f,1.0f)); - - us.requestRedraw(); - } - -} - - -void TrackballManipulator::init(const GUIEventAdapter& ,GUIActionAdapter& ) -{ - flushMouseEventStack(); -} - - -bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us) -{ - if(!_camera.get()) return false; - - switch(ea.getEventType()) - { - case(GUIEventAdapter::PUSH): - { - flushMouseEventStack(); - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - us.requestContinuousUpdate(false); - _thrown = false; - return true; - } - - case(GUIEventAdapter::RELEASE): - { - if (ea.getButtonMask()==0) - { - - if (isMouseMoving()) - { - if (calcMovement()) - { - us.requestRedraw(); - us.requestContinuousUpdate(true); - _thrown = true; - } - } - else - { - flushMouseEventStack(); - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - us.requestContinuousUpdate(false); - _thrown = false; - } - - } - else - { - flushMouseEventStack(); - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - us.requestContinuousUpdate(false); - _thrown = false; - } - return true; - } - - case(GUIEventAdapter::DRAG): - { - addMouseEvent(ea); - if (calcMovement()) us.requestRedraw(); - us.requestContinuousUpdate(false); - _thrown = false; - return true; - } - - case(GUIEventAdapter::MOVE): - { - return false; - } - - case(GUIEventAdapter::KEYBOARD): - if (ea.getKey()==' ') - { - flushMouseEventStack(); - _thrown = false; - home(ea,us); - us.requestRedraw(); - us.requestContinuousUpdate(false); - return true; - } else if (ea.getKey()=='+') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f); - return true; - } - else if (ea.getKey()=='-') - { - _camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f); - return true; - } -// this is quick hack to test out othographic projection. -// else if (ea.getKey()=='O') -// { -// float dist = _camera->getLookDistance(); -// _camera->setOrtho(-dist,dist,-dist,dist,-dist,dist); -// return true; -// } - return false; - case(GUIEventAdapter::FRAME): - _camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE); - if (_thrown) - { - if (calcMovement()) us.requestRedraw(); - return true; - } - return false; - default: - return false; - } -} - - -bool TrackballManipulator::isMouseMoving() -{ - if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - - static const float velocity = 100.0f; - - float dx = _ga_t0->getX()-_ga_t1->getX(); - float dy = _ga_t0->getY()-_ga_t1->getY(); - float len = sqrtf(dx*dx+dy*dy); - float dt = _ga_t0->time()-_ga_t1->time(); - - return (len>dt*velocity); -} - - -void TrackballManipulator::flushMouseEventStack() -{ - _ga_t1 = NULL; - _ga_t0 = NULL; -} - - -void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea) -{ - _ga_t1 = _ga_t0; - _ga_t0 = &ea; -} - - -bool TrackballManipulator::calcMovement() -{ - - // return if less then two events have been added. - if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - - float dx = _ga_t0->getX()-_ga_t1->getX(); - float dy = _ga_t0->getY()-_ga_t1->getY(); - - - // return if there is no movement. - if (dx==0 && dy==0) return false; - - float focalLength = (_camera->getCenterPoint()-_camera->getEyePoint()).length(); - unsigned int buttonMask = _ga_t1->getButtonMask(); - if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON) - { - - // rotate camera. - - osg::Vec3 center = _camera->getCenterPoint(); - osg::Vec3 axis; - float angle; - - float mx0 = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f; - float rx0 = (_ga_t0->getXmax()-_ga_t0->getXmin())/2.0f; - - float my0 = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f; - float ry0 = (_ga_t0->getYmax()-_ga_t0->getYmin())/2.0f; - - float mx1 = (_ga_t0->getXmin()+_ga_t1->getXmax())/2.0f; - float rx1 = (_ga_t0->getXmax()-_ga_t1->getXmin())/2.0f; - - float my1 = (_ga_t1->getYmin()+_ga_t1->getYmax())/2.0f; - float ry1 = (_ga_t1->getYmax()-_ga_t1->getYmin())/2.0f; - - float px0 = (_ga_t0->getX()-mx0)/rx0; - float py0 = (my0-_ga_t0->getY())/ry0; - - float px1 = (_ga_t1->getX()-mx1)/rx1; - float py1 = (my1-_ga_t1->getY())/ry1; - - trackball(axis,angle,px1,py1,px0,py0); - - osg::Matrix mat; - mat.makeTranslate(-center.x(),-center.y(),-center.z()); - mat *= Matrix::rotate(angle,axis.x(),axis.y(),axis.z()); - mat *= Matrix::translate(center.x(),center.y(),center.z()); - - _camera->transformLookAt(mat); - - return true; - - } - else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON || - buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON)) - { - - // pan model. - - - float scale = 0.0015f*focalLength; - - osg::Vec3 uv = _camera->getUpVector(); - osg::Vec3 sv = _camera->getSideVector(); - osg::Vec3 dv = uv*(dy*scale)-sv*(dx*scale); - - osg::Matrix mat; - mat.makeTranslate(dv.x(),dv.y(),dv.z()); - - _camera->transformLookAt(mat); - - return true; - - } - else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON) - { - - // zoom model. - - float fd = focalLength; - float scale = 1.0f-dy*0.001f; - if (fd*scale>_modelScale*_minimumZoomScale) - { - // zoom camera in. - osg::Vec3 center = _camera->getCenterPoint(); - - osg::Matrix mat; - mat.makeTranslate(-center.x(),-center.y(),-center.z()); - mat *= Matrix::scale(scale,scale,scale); - mat *= Matrix::translate(center.x(),center.y(),center.z()); - - _camera->transformLookAt(mat); - - } - else - { - - // notify(DEBUG_INFO) << "Pushing forward"<getLookVector()*(dy*scale); - - osg::Matrix mat; - mat.makeTranslate(dv.x(),dv.y(),dv.z()); - - _camera->transformLookAt(mat); - - } - - return true; - - } - - return false; -} - - -/* - * This size should really be based on the distance from the center of - * rotation to the point on the object underneath the mouse. That - * point would then track the mouse as closely as possible. This is a - * simple example, though, so that is left as an Exercise for the - * Programmer. - */ -const float TRACKBALLSIZE = 0.8f; - -/* - * Ok, simulate a track-ball. Project the points onto the virtual - * trackball, then figure out the axis of rotation, which is the cross - * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0) - * Note: This is a deformed trackball-- is a trackball in the center, - * but is deformed into a hyperbolic sheet of rotation away from the - * center. This particular function was chosen after trying out - * several variations. - * - * It is assumed that the arguments to this routine are in the range - * (-1.0 ... 1.0) - */ -void TrackballManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y) -{ - /* - * First, figure out z-coordinates for projection of P1 and P2 to - * deformed sphere - */ - - osg::Vec3 uv = _camera->getUpVector(); - osg::Vec3 sv = _camera->getSideVector(); - osg::Vec3 lv = _camera->getLookVector(); - - osg::Vec3 p1 = sv*p1x+uv*p1y-lv*tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y); - osg::Vec3 p2 = sv*p2x+uv*p2y-lv*tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y); - - /* - * Now, we want the cross product of P1 and P2 - */ - -// Robert, -// -// This was the quick 'n' dirty fix to get the trackball doing the right -// thing after fixing the Quat rotations to be right-handed. You may want -// to do something more elegant. -// axis = p1^p2; -axis = p2^p1; - axis.normalize(); - - /* - * Figure out how much to rotate around that axis. - */ - float t = (p2-p1).length() / (2.0*TRACKBALLSIZE); - - /* - * Avoid problems with out-of-control values... - */ - if (t > 1.0) t = 1.0; - if (t < -1.0) t = -1.0; - angle = inRadians(asin(t)); - -} - - -/* - * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet - * if we are away from the center of the sphere. - */ -float TrackballManipulator::tb_project_to_sphere(float r, float x, float y) -{ - float d, t, z; - - d = sqrt(x*x + y*y); - /* Inside sphere */ - if (d < r * 0.70710678118654752440) - { - z = sqrt(r*r - d*d); - } /* On hyperbola */ - else - { - t = r / 1.41421356237309504880; - z = t*t / d; - } - return z; -}