Added new TerrainManipulator to osgGA, and new callback for getting the

CoordinateFrame for a given X,Y,Z location.
This commit is contained in:
Robert Osfield
2004-05-06 11:01:16 +00:00
parent 1a09763515
commit 47dd0ece28
12 changed files with 740 additions and 61 deletions

View File

@@ -77,8 +77,8 @@ public:
// Overrides from MatrixManipulator...
/** Set the coordinate frame which tells the manipulator which way is up, east and north.*/
virtual void setCoordinateFrame(const osg::CoordinateFrame& cf) { _coordinateFrame = cf; _current->setCoordinateFrame(cf); }
/** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb);
/** Set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); }

View File

@@ -41,15 +41,34 @@ public:
virtual const char* className() const { return "MatrixManipulator"; }
/** set the coordinate frame which tells the manipulator which way is up, east and north.*/
virtual void setCoordinateFrame(const osg::CoordinateFrame& cf) { _coordinateFrame = cf; }
/** 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(double X, double Y, double Z) const = 0;
protected:
virtual ~CoordinateFrameCallback() {}
};
/** 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.*/
const osg::CoordinateFrame& getCoordinateFrame() const { return _coordinateFrame; }
osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const
{
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(X,Y,Z);
return osg::CoordinateFrame();
}
osg::Vec3 getSideVector() const { return osg::Vec3(_coordinateFrame(0,0),_coordinateFrame(1,0),_coordinateFrame(2,0)); }
osg::Vec3 getFromVector() const { return osg::Vec3(_coordinateFrame(0,1),_coordinateFrame(1,1),_coordinateFrame(2,1)); }
osg::Vec3 getUpVector() const { return osg::Vec3(_coordinateFrame(0,2),_coordinateFrame(1,2),_coordinateFrame(2,2)); }
osg::Vec3 getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(0,0),cf(0,1),cf(0,2)); }
osg::Vec3 getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(1,0),cf(1,1),cf(1,2)); }
osg::Vec3 getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(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;
@@ -106,7 +125,7 @@ protected:
MatrixManipulator();
virtual ~MatrixManipulator();
osg::CoordinateFrame _coordinateFrame;
osg::ref_ptr<CoordinateFrameCallback> _coordinateFrameCallback;
};
}

View File

@@ -0,0 +1,123 @@
/* -*-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_TERRAINMANIPULATOR
#define OSGGA_TERRAINMANIPULATOR 1
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
namespace osgGA{
class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
{
public:
TerrainManipulator();
virtual const char* className() const { return "Terrain"; }
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
center before the center is pushed forward.*/
void setMinimumZoomScale(float minimumZoomScale) { _minimumZoomScale=minimumZoomScale; }
/** get the minimum distance (as ratio) the eye point can be zoomed in */
float getMinimumZoomScale() const { return _minimumZoomScale; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrixd& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrixd getMatrix() const;
/** 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;
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
/** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
virtual float getFusionDistanceValue() const { return _distance; }
/** Attach a node to the manipulator.
Automatically detaches previously attached node.
setNode(NULL) detaches previously nodes.
Is ignored by manipulators which do not require a reference model.*/
virtual void setNode(osg::Node*);
/** Return node if attached.*/
virtual const osg::Node* getNode() const;
/** Return node if attached.*/
virtual osg::Node* getNode();
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
/** Start/restart the manipulator.*/
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
/** handle events, return true if handled, false otherwise.*/
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
/** Get the keyboard and mouse usage of this manipulator.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
protected:
virtual ~TerrainManipulator();
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/
bool calcMovement();
void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
float tb_project_to_sphere(float r, float x, float y);
/** Check the speed at which the mouse is moving.
If speed is below a threshold then return false, otherwise return true.*/
bool isMouseMoving();
// Internal event stack comprising last three mouse events.
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _minimumZoomScale;
bool _thrown;
osg::CoordinateFrame _coordinateFrame;
osg::Quat _rotation;
float _distance;
};
}
#endif

View File

@@ -53,15 +53,17 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
TRACKBALL_MANIPULATOR = 1,
DRIVE_MANIPULATOR = 2,
FLIGHT_MANIPULATOR = 4,
STATE_MANIPULATOR = 8,
HEAD_LIGHT_SOURCE = 16,
SKY_LIGHT_SOURCE = 32,
STATS_MANIPULATOR = 64,
VIEWER_MANIPULATOR = 128,
ESCAPE_SETS_DONE = 256,
TERRAIN_MANIPULATOR = 8,
STATE_MANIPULATOR = 16,
HEAD_LIGHT_SOURCE = 32,
SKY_LIGHT_SOURCE = 64,
STATS_MANIPULATOR = 128,
VIEWER_MANIPULATOR = 256,
ESCAPE_SETS_DONE = 512,
STANDARD_SETTINGS = TRACKBALL_MANIPULATOR|
DRIVE_MANIPULATOR |
FLIGHT_MANIPULATOR |
TERRAIN_MANIPULATOR |
STATE_MANIPULATOR |
HEAD_LIGHT_SOURCE |
STATS_MANIPULATOR |
@@ -106,7 +108,7 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
void setCoordindateSystemNodePath(const osg::NodePath& nodePath);
const RefNodePath& getCoordindateSystemNodePath() { return _coordinateSystemNodePath; }
const RefNodePath& getCoordindateSystemNodePath() const { return _coordinateSystemNodePath; }
/** Dispatch the cull and draw for each of the Camera's for this frame.*/
virtual void frame();