CameraManipulator
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_CameraManipulator
#define OSGGA_CameraManipulator 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
class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
{
typedef GUIEventHandler inherited;
public:
// We are not using META_Object as this is abstract class.
// Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
virtual const char* className() const { return "CameraManipulator"; }
class CoordinateFrameCallback : public osg::Referenced
{
public:
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
protected:
virtual ~CoordinateFrameCallback() {}
};
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb) { _coordinateFrameCallback = cb; }
CoordinateFrameCallback* getCoordinateFrameCallback() { return _coordinateFrameCallback.get(); }
const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); }
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)); }
virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
virtual osg::Matrixd getMatrix() const = 0;
virtual osg::Matrixd getInverseMatrix() const = 0;
virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE; }
virtual float getFusionDistanceValue() const { return 1.0f; }
void setIntersectTraversalMask(unsigned int mask) { _intersectTraversalMask = mask; }
unsigned int getIntersectTraversalMask() const { return _intersectTraversalMask; }
virtual void setNode(osg::Node*) {}
virtual const osg::Node* getNode() const { return NULL; }
virtual osg::Node* getNode() { return NULL; }
virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false)
{
setAutoComputeHomePosition(autoComputeHomePosition);
_homeEye = eye;
_homeCenter = center;
_homeUp = up;
}
virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
{
eye = _homeEye;
center = _homeCenter;
up = _homeUp;
}
virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
bool getAutoComputeHomePosition() const { return _autoComputeHomePosition; }
virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
virtual void finishAnimation() {}
virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
virtual void home(double /*currentTime*/) {}
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
protected:
CameraManipulator();
CameraManipulator(const CameraManipulator& mm, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
virtual ~CameraManipulator();
std::string getManipulatorName() const;
unsigned int _intersectTraversalMask;
bool _autoComputeHomePosition;
osg::Vec3d _homeEye;
osg::Vec3d _homeCenter;
osg::Vec3d _homeUp;
osg::ref_ptr<CoordinateFrameCallback> _coordinateFrameCallback;
};
}
#endif
CoordinateSystemNode
GUIActionAdapter
GUIEventAdapter
GUIEventHandler
Matrixd
Node
SceneView
osgGA::CameraManipulator::CoordinateFrameCallback
Definition CameraManipulator:51
osgGA::CameraManipulator::CoordinateFrameCallback::getCoordinateFrame
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d &position) const =0
osgGA::CameraManipulator::CoordinateFrameCallback::~CoordinateFrameCallback
virtual ~CoordinateFrameCallback()
Definition CameraManipulator:55
osgGA::CameraManipulator::setIntersectTraversalMask
void setIntersectTraversalMask(unsigned int mask)
Definition CameraManipulator:102
osgGA::CameraManipulator::_coordinateFrameCallback
osg::ref_ptr< CoordinateFrameCallback > _coordinateFrameCallback
Definition CameraManipulator:191
osgGA::CameraManipulator::getUpVector
osg::Vec3d getUpVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:76
osgGA::CameraManipulator::CameraManipulator
CameraManipulator()
osgGA::CameraManipulator::setByInverseMatrix
virtual void setByInverseMatrix(const osg::Matrixd &matrix)=0
osgGA::CameraManipulator::finishAnimation
virtual void finishAnimation()
Definition CameraManipulator:147
osgGA::CameraManipulator::CameraManipulator
CameraManipulator(const CameraManipulator &mm, const osg::CopyOp &copyOp=osg::CopyOp::SHALLOW_COPY)
osgGA::CameraManipulator::getHomePosition
virtual void getHomePosition(osg::Vec3d &eye, osg::Vec3d &center, osg::Vec3d &up) const
Definition CameraManipulator:130
osgGA::CameraManipulator::setAutoComputeHomePosition
virtual void setAutoComputeHomePosition(bool flag)
Definition CameraManipulator:138
osgGA::CameraManipulator::computeHomePosition
virtual void computeHomePosition(const osg::Camera *camera=NULL, bool useBoundingBox=false)
osgGA::CameraManipulator::init
virtual void init(const GUIEventAdapter &, GUIActionAdapter &)
Definition CameraManipulator:166
osgGA::CameraManipulator::updateCamera
virtual void updateCamera(osg::Camera &camera)
Definition CameraManipulator:92
osgGA::CameraManipulator::setHomePosition
virtual void setHomePosition(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up, bool autoComputeHomePosition=false)
Definition CameraManipulator:121
osgGA::CameraManipulator::_intersectTraversalMask
unsigned int _intersectTraversalMask
Definition CameraManipulator:183
osgGA::CameraManipulator::~CameraManipulator
virtual ~CameraManipulator()
osgGA::CameraManipulator::getCoordinateFrameCallback
const CoordinateFrameCallback * getCoordinateFrameCallback() const
Definition CameraManipulator:65
osgGA::CameraManipulator::getNode
virtual osg::Node * getNode()
Definition CameraManipulator:118
osgGA::CameraManipulator::setNode
virtual void setNode(osg::Node *)
Definition CameraManipulator:112
osgGA::CameraManipulator::handle
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
Definition CameraManipulator:169
osgGA::CameraManipulator::_autoComputeHomePosition
bool _autoComputeHomePosition
Definition CameraManipulator:185
osgGA::CameraManipulator::getCoordinateFrameCallback
CoordinateFrameCallback * getCoordinateFrameCallback()
Definition CameraManipulator:62
osgGA::CameraManipulator::getFrontVector
osg::Vec3d getFrontVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:75
osgGA::CameraManipulator::getManipulatorName
std::string getManipulatorName() const
osgGA::CameraManipulator::getFusionDistanceValue
virtual float getFusionDistanceValue() const
Definition CameraManipulator:98
osgGA::CameraManipulator::home
virtual void home(double)
Definition CameraManipulator:161
osgGA::CameraManipulator::className
virtual const char * className() const
Definition CameraManipulator:47
osgGA::CameraManipulator::getNode
virtual const osg::Node * getNode() const
Definition CameraManipulator:115
osgGA::CameraManipulator::_homeCenter
osg::Vec3d _homeCenter
Definition CameraManipulator:188
osgGA::CameraManipulator::handle
virtual bool handle(const GUIEventAdapter &ea, GUIActionAdapter &us)
osgGA::CameraManipulator::getMatrix
virtual osg::Matrixd getMatrix() const =0
osgGA::CameraManipulator::getCoordinateFrame
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d &position) const
Definition CameraManipulator:68
osgGA::CameraManipulator::setCoordinateFrameCallback
virtual void setCoordinateFrameCallback(CoordinateFrameCallback *cb)
Definition CameraManipulator:59
osgGA::CameraManipulator::_homeEye
osg::Vec3d _homeEye
Definition CameraManipulator:187
osgGA::CameraManipulator::getInverseMatrix
virtual osg::Matrixd getInverseMatrix() const =0
osgGA::CameraManipulator::home
virtual void home(const GUIEventAdapter &, GUIActionAdapter &)
Definition CameraManipulator:153
osgGA::CameraManipulator::getSideVector
osg::Vec3d getSideVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:74
osgGA::CameraManipulator::_homeUp
osg::Vec3d _homeUp
Definition CameraManipulator:189
osgGA::CameraManipulator::setByMatrix
virtual void setByMatrix(const osg::Matrixd &matrix)=0
osgGA::CameraManipulator::getFusionDistanceMode
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
Definition CameraManipulator:95
osgGA::CameraManipulator::getIntersectTraversalMask
unsigned int getIntersectTraversalMask() const
Definition CameraManipulator:105
osgGA::CameraManipulator::getAutoComputeHomePosition
bool getAutoComputeHomePosition() const
Definition CameraManipulator:141
osgGA::EventHandler::event
virtual void event(osg::NodeVisitor *nv, osg::Drawable *drawable)
osgGA::Event
Definition Event:27
osgGA::GUIActionAdapter
Definition GUIActionAdapter:62
osgGA::GUIEventAdapter
Definition GUIEventAdapter:82
osgGA::GUIEventHandler::handle
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
osgGA::GUIEventHandler::GUIEventHandler
GUIEventHandler()
Definition GUIEventHandler:53
osgUtil::SceneView::FusionDistanceMode
FusionDistanceMode
Definition SceneView:339
osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE
@ PROPORTIONAL_TO_SCREEN_DISTANCE
Definition SceneView:343
osg::Camera
Definition Camera:45
osg::Camera::setViewMatrix
void setViewMatrix(const osg::Matrixf &matrix)
Definition Camera:244
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Matrixd
Definition Matrixd:27
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::Referenced
Definition Referenced:44
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgGA
Definition Callback:21
osg::CoordinateFrame
Matrixd CoordinateFrame
Definition CoordinateSystemNode:91
Export
OSGGA_EXPORT
#define OSGGA_EXPORT
Definition osgGA/Export:40
NULL
#define NULL
Definition osg/Export:55