OpenSceneGraph 3.6.5
CameraManipulator
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGGA_CameraManipulator
15#define OSGGA_CameraManipulator 1
16
17#include <osg/Node>
18#include <osg/Matrixd>
20
21#include <osgUtil/SceneView>
22
23#include <osgGA/Export>
24#include <osgGA/GUIEventHandler>
25#include <osgGA/GUIEventAdapter>
27
28namespace osgGA{
29
30#define NEW_HOME_POSITION
31
40{
41 typedef GUIEventHandler inherited;
42
43 public:
44
45 // We are not using META_Object as this is abstract class.
46 // Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
47 virtual const char* className() const { return "CameraManipulator"; }
48
51 {
52 public:
53 virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
54 protected:
56 };
57
60
63
66
69 {
70 if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
71 return osg::CoordinateFrame();
72 }
73
74 osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); }
75 osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); }
76 osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); }
77
79 virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
80
82 virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
83
85 virtual osg::Matrixd getMatrix() const = 0;
86
88 virtual osg::Matrixd getInverseMatrix() const = 0;
89
92 virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
93
96
98 virtual float getFusionDistanceValue() const { return 1.0f; }
99
102 void setIntersectTraversalMask(unsigned int mask) { _intersectTraversalMask = mask; }
103
105 unsigned int getIntersectTraversalMask() const { return _intersectTraversalMask; }
106
112 virtual void setNode(osg::Node*) {}
113
115 virtual const osg::Node* getNode() const { return NULL; }
116
118 virtual osg::Node* getNode() { return NULL; }
119
121 virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false)
122 {
123 setAutoComputeHomePosition(autoComputeHomePosition);
124 _homeEye = eye;
125 _homeCenter = center;
126 _homeUp = up;
127 }
128
130 virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
131 {
132 eye = _homeEye;
133 center = _homeCenter;
134 up = _homeUp;
135 }
136
138 virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
139
142
144 virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
145
147 virtual void finishAnimation() {}
148
153 virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
154
161 virtual void home(double /*currentTime*/) {}
162
166 virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
167
169 virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
170
172 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
173
174 protected:
175
178
180
181 std::string getManipulatorName() const;
182
184
186
190
192
193};
194
195}
196
197#endif
Matrixd CoordinateFrame
CoordinateFrame encapsulates the orientation of east, north and up.
Definition CoordinateSystemNode:91
The 'GA' in osgGA stands for 'GUI Abstraction'; the osgGA namespace provides facilities to help devel...
Definition Callback:21
Camera - is a subclass of Transform which represents encapsulates the settings of a Camera.
Definition Camera:45
void setViewMatrix(const osg::Matrixf &matrix)
Set the view matrix.
Definition Camera:244
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition Matrixd:27
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
void setIntersectTraversalMask(unsigned int mask)
Set the mask to use when set up intersection traversal such as used in manipulators that follow terra...
Definition CameraManipulator:102
osg::ref_ptr< CoordinateFrameCallback > _coordinateFrameCallback
Definition CameraManipulator:191
osg::Vec3d getUpVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:76
virtual void setByInverseMatrix(const osg::Matrixd &matrix)=0
set the position of the matrix manipulator using a 4x4 Matrix.
virtual void finishAnimation()
finish any active manipulator animations.
Definition CameraManipulator:147
CameraManipulator(const CameraManipulator &mm, const osg::CopyOp &copyOp=osg::CopyOp::SHALLOW_COPY)
virtual void getHomePosition(osg::Vec3d &eye, osg::Vec3d &center, osg::Vec3d &up) const
Get the manually set home position.
Definition CameraManipulator:130
virtual void setAutoComputeHomePosition(bool flag)
Set whether the automatic compute of the home position is enabled.
Definition CameraManipulator:138
virtual void computeHomePosition(const osg::Camera *camera=NULL, bool useBoundingBox=false)
Compute the home position.
virtual void init(const GUIEventAdapter &, GUIActionAdapter &)
Start/restart the manipulator.
Definition CameraManipulator:166
virtual void updateCamera(osg::Camera &camera)
update the camera for the current frame, typically called by the viewer classes.
Definition CameraManipulator:92
virtual void setHomePosition(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up, bool autoComputeHomePosition=false)
Manually set the home position, and set the automatic compute of home position.
Definition CameraManipulator:121
unsigned int _intersectTraversalMask
Definition CameraManipulator:183
const CoordinateFrameCallback * getCoordinateFrameCallback() const
get the coordinate frame callback which tells the manipulator which way is up, east and north.
Definition CameraManipulator:65
virtual osg::Node * getNode()
Return node if attached.
Definition CameraManipulator:118
virtual void setNode(osg::Node *)
Attach a node to the manipulator, automatically detaching any previously attached node.
Definition CameraManipulator:112
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
Handle event.
Definition CameraManipulator:169
bool _autoComputeHomePosition
Definition CameraManipulator:185
CoordinateFrameCallback * getCoordinateFrameCallback()
get the coordinate frame callback which tells the manipulator which way is up, east and north.
Definition CameraManipulator:62
osg::Vec3d getFrontVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:75
std::string getManipulatorName() const
virtual float getFusionDistanceValue() const
Get the FusionDistanceValue.
Definition CameraManipulator:98
virtual void home(double)
Move the camera to the default position.
Definition CameraManipulator:161
virtual const char * className() const
return the name of the object's class type.
Definition CameraManipulator:47
virtual const osg::Node * getNode() const
Return const node if attached.
Definition CameraManipulator:115
osg::Vec3d _homeCenter
Definition CameraManipulator:188
virtual bool handle(const GUIEventAdapter &ea, GUIActionAdapter &us)
Handle events, return true if handled, false otherwise.
virtual osg::Matrixd getMatrix() const =0
get the position of the manipulator as 4x4 Matrix.
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d &position) const
get the coordinate frame.
Definition CameraManipulator:68
virtual void setCoordinateFrameCallback(CoordinateFrameCallback *cb)
set the coordinate frame which callback tells the manipulator which way is up, east and north.
Definition CameraManipulator:59
osg::Vec3d _homeEye
Definition CameraManipulator:187
virtual osg::Matrixd getInverseMatrix() const =0
get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model...
virtual void home(const GUIEventAdapter &, GUIActionAdapter &)
Move the camera to the default position.
Definition CameraManipulator:153
osg::Vec3d getSideVector(const osg::CoordinateFrame &cf) const
Definition CameraManipulator:74
osg::Vec3d _homeUp
Definition CameraManipulator:189
virtual void setByMatrix(const osg::Matrixd &matrix)=0
set the position of the matrix manipulator using a 4x4 Matrix.
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
Get the FusionDistanceMode.
Definition CameraManipulator:95
unsigned int getIntersectTraversalMask() const
Get the mask to use when set up intersection traversal such as used in manipulators that follow terra...
Definition CameraManipulator:105
bool getAutoComputeHomePosition() const
Get whether the automatic compute of the home position is enabled.
Definition CameraManipulator:141
callback class to use to allow matrix manipulators to query the application for the local coordinate ...
Definition CameraManipulator:51
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d &position) const =0
virtual ~CoordinateFrameCallback()
Definition CameraManipulator:55
Base Event class.
Definition Event:27
virtual void event(osg::NodeVisitor *nv, osg::Drawable *drawable)
Event traversal drawable callback method.
Definition GUIActionAdapter:62
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
Handle event.
GUIEventHandler()
Definition GUIEventHandler:53
FusionDistanceMode
FusionDistanceMode is used only when working in stereo.
Definition SceneView:339
@ PROPORTIONAL_TO_SCREEN_DISTANCE
Compute the fusion distance by multiplying the screen distance by the fusion distance value.
Definition SceneView:343
#define NULL
Definition Export:55
#define OSGGA_EXPORT
Definition Export:40

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.