2010-05-25 20:05:13 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2010-05-25 20:05:13 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2010-05-25 20:05:13 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-05-25 20:05:13 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
#ifndef OSGGA_CameraManipulator
|
|
|
|
#define OSGGA_CameraManipulator 1
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
#include <osg/Node>
|
2003-09-06 06:35:34 +08:00
|
|
|
#include <osg/Matrixd>
|
2004-04-30 06:18:54 +08:00
|
|
|
#include <osg/CoordinateSystemNode>
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
#include <osgUtil/SceneView>
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
#include <osgGA/Export>
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
#include <osgGA/GUIEventAdapter>
|
|
|
|
#include <osgGA/GUIActionAdapter>
|
|
|
|
|
|
|
|
namespace osgGA{
|
|
|
|
|
2004-07-13 03:54:54 +08:00
|
|
|
#define NEW_HOME_POSITION
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
CameraManipulator is an abstract base class defining the interface, and a certain
|
2002-08-28 22:27:18 +08:00
|
|
|
amount of default functionality, for classes which wish to control OSG cameras
|
|
|
|
in response to GUI events.
|
|
|
|
|
|
|
|
*/
|
2010-05-27 23:54:37 +08:00
|
|
|
class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
|
2010-05-26 01:02:11 +08:00
|
|
|
{
|
|
|
|
typedef GUIEventHandler inherited;
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
public:
|
2010-05-25 20:05:13 +08:00
|
|
|
|
|
|
|
// We are not using META_Object as this is abstract class.
|
|
|
|
// Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
|
2010-05-27 23:54:37 +08:00
|
|
|
virtual const char* className() const { return "CameraManipulator"; }
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** callback class to use to allow matrix manipulators to query the application for the local coordinate frame.*/
|
2004-05-06 19:01:16 +08:00
|
|
|
class CoordinateFrameCallback : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
2004-05-20 18:15:48 +08:00
|
|
|
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
|
2004-05-06 19:01:16 +08:00
|
|
|
protected:
|
|
|
|
virtual ~CoordinateFrameCallback() {}
|
|
|
|
};
|
2004-07-09 23:21:33 +08:00
|
|
|
|
2004-05-06 19:01:16 +08:00
|
|
|
/** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
|
|
|
|
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb) { _coordinateFrameCallback = cb; }
|
|
|
|
|
|
|
|
/** get the coordinate frame callback which tells the manipulator which way is up, east and north.*/
|
|
|
|
CoordinateFrameCallback* getCoordinateFrameCallback() { return _coordinateFrameCallback.get(); }
|
|
|
|
|
|
|
|
/** get the coordinate frame callback which tells the manipulator which way is up, east and north.*/
|
|
|
|
const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); }
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2004-04-30 06:18:54 +08:00
|
|
|
/** get the coordinate frame.*/
|
2004-05-20 18:15:48 +08:00
|
|
|
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
|
2004-05-06 19:01:16 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
|
2004-05-06 19:01:16 +08:00
|
|
|
return osg::CoordinateFrame();
|
|
|
|
}
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); }
|
|
|
|
osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); }
|
|
|
|
osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); }
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
|
2003-03-26 20:50:30 +08:00
|
|
|
|
2003-05-19 23:15:17 +08:00
|
|
|
/** get the position of the manipulator as 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getMatrix() const = 0;
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2003-05-19 23:15:17 +08:00
|
|
|
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getInverseMatrix() const = 0;
|
2003-05-19 23:15:17 +08:00
|
|
|
|
2013-10-25 22:54:15 +08:00
|
|
|
/** update the camera for the current frame, typically called by the viewer classes.
|
2012-07-10 01:32:13 +08:00
|
|
|
Default implementation simply set the camera view matrix. */
|
2012-07-10 01:49:04 +08:00
|
|
|
virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
|
2012-07-10 01:32:13 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
|
2003-05-19 23:15:17 +08:00
|
|
|
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE; }
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
2003-05-19 23:15:17 +08:00
|
|
|
virtual float getFusionDistanceValue() const { return 1.0f; }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2005-03-23 05:06:06 +08:00
|
|
|
/** Set the mask to use when set up intersection traversal such as used in manipulators that follow terrain or have collision detection.
|
|
|
|
* The intersection traversal mask is useful for controlling what parts of the scene graph should be used for intersection purposes.*/
|
|
|
|
void setIntersectTraversalMask(unsigned int mask) { _intersectTraversalMask = mask; }
|
|
|
|
|
|
|
|
/** Get the mask to use when set up intersection traversal such as used in manipulators that follow terrain or have collision detection.*/
|
|
|
|
unsigned int getIntersectTraversalMask() const { return _intersectTraversalMask; }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
Attach a node to the manipulator, automatically detaching any previously attached node.
|
|
|
|
setNode(NULL) detaches previous nodes.
|
|
|
|
May be ignored by manipulators which do not require a reference model.
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
virtual void setNode(osg::Node*) {}
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/** Return const node if attached.*/
|
2002-05-09 18:31:03 +08:00
|
|
|
virtual const osg::Node* getNode() const { return NULL; }
|
|
|
|
|
|
|
|
/** Return node if attached.*/
|
|
|
|
virtual osg::Node* getNode() { return NULL; }
|
|
|
|
|
2004-09-01 18:18:46 +08:00
|
|
|
/** Manually set the home position, and set the automatic compute of home position. */
|
|
|
|
virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false)
|
2004-07-13 03:54:54 +08:00
|
|
|
{
|
2004-09-01 18:18:46 +08:00
|
|
|
setAutoComputeHomePosition(autoComputeHomePosition);
|
2004-07-13 03:54:54 +08:00
|
|
|
_homeEye = eye;
|
|
|
|
_homeCenter = center;
|
|
|
|
_homeUp = up;
|
|
|
|
}
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the manually set home position. */
|
2004-10-26 01:41:54 +08:00
|
|
|
virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
|
2004-07-13 03:54:54 +08:00
|
|
|
{
|
2004-08-26 14:41:09 +08:00
|
|
|
eye = _homeEye;
|
|
|
|
center = _homeCenter;
|
|
|
|
up = _homeUp;
|
2004-07-13 03:54:54 +08:00
|
|
|
}
|
2004-09-01 18:18:46 +08:00
|
|
|
|
2010-05-25 20:05:13 +08:00
|
|
|
/** Set whether the automatic compute of the home position is enabled.*/
|
2004-07-13 03:54:54 +08:00
|
|
|
virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
|
|
|
|
|
2010-05-25 20:05:13 +08:00
|
|
|
/** Get whether the automatic compute of the home position is enabled.*/
|
|
|
|
bool getAutoComputeHomePosition() const { return _autoComputeHomePosition; }
|
2004-07-13 03:54:54 +08:00
|
|
|
|
2010-05-25 20:05:13 +08:00
|
|
|
/** Compute the home position.*/
|
|
|
|
virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
|
2004-07-13 03:54:54 +08:00
|
|
|
|
2013-11-16 00:15:09 +08:00
|
|
|
/** finish any active manipulator animations.*/
|
|
|
|
virtual void finishAnimation() {}
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
2010-05-25 20:05:13 +08:00
|
|
|
Move the camera to the default position.
|
2002-08-28 22:27:18 +08:00
|
|
|
May be ignored by manipulators if home functionality is not appropriate.
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
2002-08-28 22:27:18 +08:00
|
|
|
|
2005-03-21 07:57:17 +08:00
|
|
|
/**
|
2010-05-25 20:05:13 +08:00
|
|
|
Move the camera to the default position.
|
2005-03-21 07:57:17 +08:00
|
|
|
This version does not require GUIEventAdapter and GUIActionAdapter so may be
|
|
|
|
called from somewhere other than a handle() method in GUIEventHandler. Application
|
|
|
|
must be aware of implications.
|
|
|
|
*/
|
|
|
|
virtual void home(double /*currentTime*/) {}
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
Start/restart the manipulator.
|
|
|
|
FIXME: what does this actually mean? Provide examples.
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
|
|
|
|
2013-10-25 22:54:15 +08:00
|
|
|
/** Handle event. Override the handle(..) method in your event handlers to respond to events. */
|
|
|
|
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/** Handle events, return true if handled, false otherwise. */
|
|
|
|
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
protected:
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
CameraManipulator();
|
|
|
|
CameraManipulator(const CameraManipulator& mm, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
virtual ~CameraManipulator();
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2010-05-25 20:05:13 +08:00
|
|
|
std::string getManipulatorName() const;
|
|
|
|
|
2005-03-23 05:06:06 +08:00
|
|
|
unsigned int _intersectTraversalMask;
|
|
|
|
|
2004-07-13 03:54:54 +08:00
|
|
|
bool _autoComputeHomePosition;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2004-07-13 03:54:54 +08:00
|
|
|
osg::Vec3d _homeEye;
|
|
|
|
osg::Vec3d _homeCenter;
|
|
|
|
osg::Vec3d _homeUp;
|
2004-07-09 23:21:33 +08:00
|
|
|
|
2004-05-06 19:01:16 +08:00
|
|
|
osg::ref_ptr<CoordinateFrameCallback> _coordinateFrameCallback;
|
2005-03-23 05:06:06 +08:00
|
|
|
|
2002-05-09 18:31:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|