185 lines
7.0 KiB
C++
185 lines
7.0 KiB
C++
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
*
|
|
* 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
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* OpenSceneGraph Public License for more details.
|
|
*/
|
|
|
|
#ifndef OSGGA_MatrixManipulator
|
|
#define OSGGA_MatrixManipulator 1
|
|
|
|
#include <osg/Node>
|
|
#include <osg/Matrixd>
|
|
#include <osg/CoordinateSystemNode>
|
|
|
|
#include <osgUtil/SceneView>
|
|
|
|
#include <osgGA/Export>
|
|
#include <osgGA/GUIEventHandler>
|
|
#include <osgGA/GUIEventAdapter>
|
|
#include <osgGA/GUIActionAdapter>
|
|
|
|
namespace osgGA{
|
|
|
|
#define NEW_HOME_POSITION
|
|
|
|
/**
|
|
|
|
MatrixManipulator is an abstract base class defining the interface, and a certain
|
|
amount of default functionality, for classes which wish to control OSG cameras
|
|
in response to GUI events.
|
|
|
|
*/
|
|
class OSGGA_EXPORT MatrixManipulator : public GUIEventHandler
|
|
{
|
|
public:
|
|
|
|
|
|
virtual const char* className() const { return "MatrixManipulator"; }
|
|
|
|
/** callback class to use to allow matrix manipulators to querry the application for the local coordinate frame.*/
|
|
class CoordinateFrameCallback : public osg::Referenced
|
|
{
|
|
public:
|
|
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
|
|
protected:
|
|
virtual ~CoordinateFrameCallback() {}
|
|
};
|
|
|
|
|
|
|
|
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
|
|
center before the center is pushed forward.*/
|
|
virtual void setMinimumDistance(float minimumDistance) { _minimumDistance=minimumDistance; }
|
|
|
|
/** get the minimum distance (as ratio) the eye point can be zoomed in */
|
|
float getMinimumDistance() const { return _minimumDistance; }
|
|
|
|
|
|
/** 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(); }
|
|
|
|
/** get the coordinate frame.*/
|
|
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
|
|
{
|
|
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
|
|
return osg::CoordinateFrame();
|
|
}
|
|
|
|
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)); }
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
|
virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
|
virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
|
|
|
|
/** get the position of the manipulator as 4x4 Matrix.*/
|
|
virtual osg::Matrixd getMatrix() const = 0;
|
|
|
|
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
|
virtual osg::Matrixd getInverseMatrix() const = 0;
|
|
|
|
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
|
|
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE; }
|
|
|
|
/** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
|
|
virtual float getFusionDistanceValue() const { return 1.0f; }
|
|
|
|
|
|
/**
|
|
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.
|
|
*/
|
|
virtual void setNode(osg::Node*) {}
|
|
|
|
/** Return const node if attached.*/
|
|
virtual const osg::Node* getNode() const { return NULL; }
|
|
|
|
/** Return node if attached.*/
|
|
virtual osg::Node* getNode() { return NULL; }
|
|
|
|
virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up)
|
|
{
|
|
_homeEye = eye;
|
|
_homeCenter = center;
|
|
_homeUp = up;
|
|
}
|
|
|
|
virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up)
|
|
{
|
|
eye = _homeEye;
|
|
center = _homeCenter;
|
|
up = _homeUp;
|
|
}
|
|
|
|
virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
|
|
|
|
bool getAutoComputeHomePosition() const { return _autoComputeHomePosition; }
|
|
|
|
virtual void computeHomePosition()
|
|
{
|
|
if(getNode())
|
|
{
|
|
const osg::BoundingSphere& boundingSphere=getNode()->getBound();
|
|
|
|
setHomePosition(boundingSphere._center+osg::Vec3( 0.0,-3.5f * boundingSphere._radius,0.0f),
|
|
boundingSphere._center,
|
|
osg::Vec3(0.0f,0.0f,1.0f));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
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.
|
|
FIXME: what does this actually mean? Provide examples.
|
|
*/
|
|
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
|
|
|
/** Handle events, return true if handled, false otherwise. */
|
|
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
|
|
|
/** Handle visitations */
|
|
virtual void accept(GUIEventHandlerVisitor& v) { v.visit(*this); }
|
|
|
|
protected:
|
|
|
|
MatrixManipulator();
|
|
virtual ~MatrixManipulator();
|
|
|
|
double _minimumDistance;
|
|
|
|
bool _autoComputeHomePosition;
|
|
|
|
osg::Vec3d _homeEye;
|
|
osg::Vec3d _homeCenter;
|
|
osg::Vec3d _homeUp;
|
|
|
|
osg::ref_ptr<CoordinateFrameCallback> _coordinateFrameCallback;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|