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:
Robert Osfield
2002-06-09 13:10:09 +00:00
parent 0a8d0a255f
commit d91b848a63
44 changed files with 151 additions and 2129 deletions

View File

@@ -4,7 +4,7 @@
#include <osg/Notify>
using namespace osg;
using namespace osgUtil;
using namespace osgGA;
GliderManipulator::GliderManipulator()
{

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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());

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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))

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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\

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}