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 <osgUtil/CameraManipulator (etc) to osgGA/CameraManipulator and the extra dependency of the link line.
This commit is contained in:
parent
0a8d0a255f
commit
d91b848a63
@ -94,7 +94,7 @@ else
|
||||
endif
|
||||
LINKARGS =
|
||||
DYNAMICLIBRARYLIB = -ldl
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
FREETYPE_LIB = -L/usr/local/lib -lfreetype
|
||||
GLUT_LIB = -lglut
|
||||
GL_LIBS = -lGLU -lGL
|
||||
@ -132,7 +132,7 @@ else
|
||||
endif
|
||||
LINKARGS = -L${TOPDIR}/lib -LANG:std -OPT:Olimit=0
|
||||
DYNAMICLIBRARYLIB = -ldl
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
FREETYPE_LIB = -L/usr/freeware/lib32 -lfreetype
|
||||
GLUT_LIB = -lglut
|
||||
GL_LIBS = -lGLU -lGL
|
||||
@ -171,7 +171,7 @@ endif
|
||||
LINKARGS = -L/usr/X11R6/lib
|
||||
LIBS = -lstdc++
|
||||
DYNAMICLIBRARYLIB = -ldl
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
FREETYPE_LIB = -lfreetype
|
||||
GLUT_LIB = -lglut
|
||||
GL_LIBS = -lGLU -lGL
|
||||
@ -199,7 +199,7 @@ ifeq ($(OS),FreeBSD)
|
||||
ARCHARGS =
|
||||
LINKARGS = -L/usr/X11R6/lib -L/usr/local/lib -rpath /usr/local/lib
|
||||
DYNAMICLIBRARYLIB =
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
FREETYPE_LIB = -lfreetype
|
||||
GLUT_LIB = -lglut
|
||||
GL_LIBS = -lGLU -lGL
|
||||
@ -224,7 +224,7 @@ ifeq ($(OS),Darwin)
|
||||
ARCHARGS =
|
||||
LINKARGS = -L/usr/lib -L/sw/lib
|
||||
DYNAMICLIBRARYLIB =
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
FREETYPE_LIB = -lfreetype
|
||||
GLUT_LIB = -framework GLUT
|
||||
CARBON_LIB = -framework Carbon
|
||||
@ -258,7 +258,7 @@ ifeq ($(OS),CYGWIN)
|
||||
LINKARGS = -W -Wall
|
||||
DYNAMICLIBRARYLIB =
|
||||
|
||||
OSG_LIBS = -losgGLUT -losgDB -losgUtil -losg
|
||||
OSG_LIBS = -losgGLUT -losgGA -losgDB -losgUtil -losg
|
||||
GL_LIBS = -lglu32 -lopengl32
|
||||
GLUT_LIB = -lglut32 $(GL_LIBS)
|
||||
X_LIBS = -lgdi32 -luser32
|
||||
|
@ -97,10 +97,6 @@ SOURCE=..\..\src\osgUtil\AppVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\CameraManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\CullVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -117,14 +113,6 @@ SOURCE=..\..\src\osgUtil\DisplayRequirementsVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\DriveManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\FlightManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\InsertImpostorsVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -169,26 +157,14 @@ SOURCE=..\..\src\osgUtil\SceneView.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\SceneViewManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\SmoothingVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\StateSetManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\Tesselator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\TrackballManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\TransformCallback.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -209,10 +185,6 @@ SOURCE=..\..\include\osgUtil\AppVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\CameraManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\CullVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -229,30 +201,10 @@ SOURCE=..\..\Include\osgUtil\DisplayRequirementsVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\DriveManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\Export
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\FlightManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\GUIActionAdapter
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\GUIEventAdapter
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\GUIEventHandler
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\InsertImpostorsVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -297,26 +249,14 @@ SOURCE=..\..\Include\osgUtil\SceneView
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\SceneViewManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\SmoothingVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\StateSetManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\Tesselator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\TrackballManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osgUtil\TransformCallback
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -73,7 +73,7 @@ class GUIEventAdapter : public osg::Referenced
|
||||
virtual unsigned int getButtonMask() const = 0;
|
||||
|
||||
/** time in seconds of event. */
|
||||
virtual float time() const = 0;
|
||||
virtual double time() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -5,14 +5,14 @@
|
||||
#ifndef OSGGLUT_GLUTEVENTADAPTER
|
||||
#define OSGGLUT_GLUTEVENTADAPTER 1
|
||||
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
|
||||
#include <osgGLUT/Export>
|
||||
|
||||
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:
|
||||
|
@ -11,8 +11,9 @@
|
||||
#include <osg/Timer>
|
||||
#include <osg/DisplaySettings>
|
||||
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/CameraManipulator>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
#include <osgUtil/SceneView>
|
||||
|
||||
#include <osgGLUT/Window>
|
||||
@ -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<osg::ref_ptr<osgUtil::CameraManipulator> > CameraManipList;
|
||||
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
|
||||
|
||||
protected:
|
||||
|
||||
@ -112,13 +113,14 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgUtil::GUIActionAdapter
|
||||
|
||||
static Viewer* s_theViewer;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
|
||||
|
||||
struct ViewportDef
|
||||
{
|
||||
osg::ref_ptr<osgUtil::SceneView> sceneView;
|
||||
float viewport[4]; // Win-size-relative [0,1]
|
||||
|
||||
osg::ref_ptr<osgUtil::CameraManipulator> _cameraManipulator;
|
||||
osg::ref_ptr<osgGA::CameraManipulator> _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;
|
||||
|
@ -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 <osg/Camera>
|
||||
#include <osg/Node>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
#include <osgUtil/GUIEventHandler>
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/GUIActionAdapter>
|
||||
|
||||
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<osg::Camera> _camera;
|
||||
|
||||
bool _homeToUseNode;
|
||||
osg::Vec3 _eyeHome;
|
||||
osg::Vec3 _centerHome;
|
||||
osg::Vec3 _upHome;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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 <osgUtil/CameraManipulator>
|
||||
|
||||
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<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _velocity;
|
||||
float _height;
|
||||
float _buffer;
|
||||
|
||||
enum SpeedControlMode {
|
||||
USE_MOUSE_Y_FOR_SPEED,
|
||||
USE_MOUSE_BUTTONS_FOR_SPEED
|
||||
};
|
||||
|
||||
SpeedControlMode _speedMode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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 <osgUtil/CameraManipulator>
|
||||
|
||||
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<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _velocity;
|
||||
|
||||
YawControlMode _yawMode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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 <osgUtil/Export>
|
||||
|
||||
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
|
||||
|
@ -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 <osg/Referenced>
|
||||
#include <osgUtil/Export>
|
||||
|
||||
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
|
||||
|
@ -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 <osg/Referenced>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/GUIActionAdapter>
|
||||
|
||||
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
|
@ -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 <osgUtil/Export>
|
||||
#include <osgUtil/SceneView>
|
||||
#include <osgUtil/CameraManipulator>
|
||||
#include <osgUtil/StateSetManipulator>
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/GUIActionAdapter>
|
||||
|
||||
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<SceneView> _sv;
|
||||
|
||||
osg::ref_ptr<CameraManipulator> _cm;
|
||||
osg::ref_ptr<StateSetManipulator> _gm;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -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 <osg/StateSet>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/GUIActionAdapter>
|
||||
#include <osgUtil/GUIEventHandler>
|
||||
|
||||
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<osg::StateSet> _drawState;
|
||||
|
||||
bool _backface;
|
||||
bool _lighting;
|
||||
bool _texture;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -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 <osgUtil/CameraManipulator>
|
||||
|
||||
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<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _minimumZoomScale;
|
||||
|
||||
bool _thrown;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgUtil;
|
||||
using namespace osgGA;
|
||||
|
||||
GliderManipulator::GliderManipulator()
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef HANGGLIDE_GLIDERMANIPULATOR
|
||||
#define HANGGLIDE_GLIDERMANIPULATOR 1
|
||||
|
||||
#include <osgUtil/CameraManipulator>
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
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<const osgUtil::GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const osgUtil::GUIEventAdapter> _ga_t0;
|
||||
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <osg/Texture>
|
||||
#include <osg/Billboard>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
@ -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();
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
@ -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();
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
@ -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();
|
||||
|
@ -8,9 +8,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
@ -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();
|
||||
|
@ -9,9 +9,9 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
@ -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();
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Transform>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
|
||||
#include <osgGLUT/Viewer>
|
||||
#include <osgGLUT/glut>
|
||||
@ -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();
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgText/Text>
|
||||
|
||||
@ -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();
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgUtil/InsertImpostorsVisitor>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
@ -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();
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
@ -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();
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ -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();
|
||||
|
@ -9,9 +9,9 @@
|
||||
#include <osg/Depth>
|
||||
#include <osg/ClipPlane>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
@ -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();
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
@ -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();
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Texture>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
@ -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();
|
||||
|
||||
|
@ -20,9 +20,9 @@
|
||||
#include <osg/Depth>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/Viewer>
|
||||
#include <osgGLUT/glut>
|
||||
@ -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();
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <osg/Texture>
|
||||
#include <osg/DrawPixels>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
@ -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();
|
||||
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
@ -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();
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
@ -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();
|
||||
|
@ -65,7 +65,7 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
|
||||
|
||||
bool cameraSet = false;
|
||||
|
||||
osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> 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<osg::LineSegment> segUp = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> 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<osg::LineSegment> segDown = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> 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<osg::LineSegment> segUp = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> 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<osg::LineSegment> segForward = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> 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<osg::LineSegment> segNormal = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> segNormal = osgNew osg::LineSegment;
|
||||
segNormal->set(fp,lfp);
|
||||
iv.addLineSegment(segNormal.get());
|
||||
|
||||
@ -520,7 +520,7 @@ bool DriveManipulator::calcMovement()
|
||||
|
||||
iv.reset();
|
||||
|
||||
osg::ref_ptr<osg::LineSegment> segFall = new osg::LineSegment;
|
||||
osg::ref_ptr<osg::LineSegment> segFall = osgNew osg::LineSegment;
|
||||
segFall->set(lfp,dp);
|
||||
iv.addLineSegment(segFall.get());
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -41,9 +41,9 @@
|
||||
#include <osgUtil/TriStripVisitor>
|
||||
#include <osgUtil/DisplayRequirementsVisitor>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osg/Version>
|
||||
#include <osgUtil/Version>
|
||||
@ -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))
|
||||
|
@ -1,37 +0,0 @@
|
||||
#include <osg/GL>
|
||||
#include <osg/Matrix>
|
||||
#include <osgUtil/CameraManipulator>
|
||||
|
||||
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;
|
||||
}
|
@ -1,560 +0,0 @@
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
|
||||
#include <osgUtil/DriveManipulator>
|
||||
#include <osgUtil/IntersectVisitor>
|
||||
#include <osg/Notify>
|
||||
|
||||
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<osg::LineSegment> 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<osg::LineSegment> 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<osg::LineSegment> 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<osg::LineSegment> 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 = "<<dt<< std::endl;
|
||||
dt = 0.0f;
|
||||
}
|
||||
|
||||
switch(_speedMode)
|
||||
{
|
||||
case(USE_MOUSE_Y_FOR_SPEED):
|
||||
{
|
||||
float my = (_ga_t0->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<osg::LineSegment> 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<osg::LineSegment> 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<osg::LineSegment> 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;
|
||||
}
|
@ -1,239 +0,0 @@
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osg/Types>
|
||||
#include <osg/Notify>
|
||||
|
||||
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 = "<<dt<< std::endl;
|
||||
dt = 0.0f;
|
||||
}
|
||||
|
||||
unsigned int buttonMask = _ga_t1->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;
|
||||
}
|
@ -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\
|
||||
|
@ -1,39 +0,0 @@
|
||||
#include <osgUtil/SceneViewManipulator>
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
|
||||
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;
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
#include <osgUtil/StateSetManipulator>
|
||||
|
||||
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;
|
||||
}
|
@ -1,398 +0,0 @@
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osg/Types>
|
||||
#include <osg/Notify>
|
||||
|
||||
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"<<std::endl;
|
||||
// push the camera forward.
|
||||
float scale = 0.0015f*fd;
|
||||
osg::Vec3 dv = _camera->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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user