Initial revision

This commit is contained in:
Don BURNS
2001-01-10 16:32:10 +00:00
parent 7c12eb9361
commit 70208ebc06
461 changed files with 70936 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#ifndef OSGUTIL_CAMERAMANIPULATOR
#define OSGUTIL_CAMERAMANIPULATOR 1
#include <osg/Referenced>
#include <osg/Camera>
#include <osgUtil/Export>
#include <osgUtil/GUIEventAdapter>
#include <osgUtil/GUIActionAdapter>
namespace osgUtil{
class OSGUTIL_EXPORT CameraManipulator : public osg::Referenced
{
public:
CameraManipulator();
virtual ~CameraManipulator();
/** attach a camera to the manipulator to be used for specifying view.*/
virtual void setCamera(osg::Camera*);
/** get the attached a camera.*/
virtual osg::Camera * getCamera() const;
/** 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 osg::Node* getNode() const { return NULL; }
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual void home(GUIEventAdapter& ,GUIActionAdapter&) {}
/** Start/restart the manipulator.*/
virtual void init(GUIEventAdapter& ,GUIActionAdapter&) {}
/** Handle events, return true if handled, false otherwise.*/
virtual bool update(GUIEventAdapter& ea,GUIActionAdapter& us);
protected:
// Reference pointer to a camera
osg::ref_ptr<osg::Camera> _camera;
};
}
#endif

View File

@@ -0,0 +1,72 @@
#ifndef OSGUTIL_COMPILEGEOSETVISITOR
#define OSGUTIL_COMPILEGEOSETVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osgUtil/Export>
namespace osgUtil {
/** Visitor for traversing scene set each osg::GeoSet's _useDisplayList flag, or
* immediately compiling osg::GeoSet's OpenGL Display lists. The mode of operation
* of the vistor is controlled by setting the DisplayListMode either on visitor
* constructor or via the setDisplayListMode() method. DisplayListMode options are:
* _displayListMode == SWITCH_ON_AND_COMPILE_DISPLAY_LISTS cals gset->compile() on
* all Geode childern. Note, the visitor must only be used within a valid
* OpenGL context as compile uses OpenGL calls.
* _displayListMode == SWITCH_ON_DISPLAY_LISTS sets the Geode's children with
* gset->setUseDisplayList(true), this method does not directly create display list,
* or uses OpenGL calls so if safe to use before a valid OpenGL context has been set up.
* On the next redraw of the scene, the gset's draw methods will be called
* which then will respond to their _useDisplayList being set by creating display lists
* automatically.
* _displayListMode == SWITCH_OFF_DISPLAY_LISTS sets the Geode's children with
* gset->setUseDisplayList(false), this method does not directly create display list,
* or uses OpenGL calls so if safe to use before a valid OpenGL context has been set up.
*/
class OSGUTIL_EXPORT DisplayListVisitor : public osg::NodeVisitor
{
public:
/** Operation modes of the DisplayListVisitor.*/
enum DisplayListMode
{
SWITCH_ON_AND_COMPILE_DISPLAY_LISTS,
SWITCH_ON_DISPLAY_LISTS,
SWITCH_OFF_DISPLAY_LISTS
};
/** Construct a CompileGeoSetsVisior to traverse all child,
* with set specfied display list mode. Default mode is to
* gset->setUseDisplayList(true).
*/
DisplayListVisitor(DisplayListMode mode=SWITCH_ON_DISPLAY_LISTS);
/** Set the operational mode of how the visitor should set up osg::GeoSet's.*/
void setDisplayListMode(DisplayListMode mode) { _displayListMode = mode; }
/** Get the operational mode.*/
DisplayListMode getDisplayListMode() const { return _displayListMode; }
/** Simply traverse using standard NodeVisitor traverse method.*/
virtual void apply(osg::Node& node)
{
traverse(node);
}
/** For each Geode visited set the display list usage according to the
* _displayListMode.
*/
virtual void apply(osg::Geode& node);
protected:
DisplayListMode _displayListMode;
};
};
#endif

View File

@@ -0,0 +1,68 @@
#ifndef OSGUTIL_DRIVEMANIPULATOR
#define OSGUTIL_DRIVEMANIPULATOR 1
#include <osgUtil/CameraManipulator>
namespace osgUtil{
class OSGUTIL_EXPORT DriveManipulator : public CameraManipulator
{
public:
DriveManipulator();
virtual ~DriveManipulator();
/** 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 osg::Node* getNode() const;
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual void home(GUIEventAdapter& ea,GUIActionAdapter& us);
/** Start/restart the manipulator.*/
virtual void init(GUIEventAdapter& ea,GUIActionAdapter& us);
/** handle events, return true if handled, false otherwise.*/
virtual bool update(GUIEventAdapter& ea,GUIActionAdapter& us);
private:
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(GUIEventAdapter& ea);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/
bool calcMovement();
// Internal event stack comprising last three mouse events.
osg::ref_ptr<GUIEventAdapter> _ga_t1;
osg::ref_ptr<GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _velocity;
float _height;
float _buffer;
enum SpeedControlMode {
USE_MOUSE_Y_FOR_SPEED,
USE_MOUSE_BUTTONS_FOR_SPEED
};
SpeedControlMode _speedMode;
};
}
#endif

22
include/osgUtil/Export Normal file
View File

@@ -0,0 +1,22 @@
// The following symbole has a underscore suffix for compatibility.
#ifndef OSGUTIL_EXPORT_
#define OSGUTIL_EXPORT_ 1
#ifdef WIN32
#pragma warning( disable : 4251 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4786 )
#endif
#if defined(_MSC_VER)
# ifdef OSGUTIL_LIBRARY
# define OSGUTIL_EXPORT __declspec(dllexport)
# else
# define OSGUTIL_EXPORT __declspec(dllimport)
#endif /* OSGUTIL_LIBRARY */
#else
#define OSGUTIL_EXPORT
#endif
#endif

View File

@@ -0,0 +1,69 @@
#ifndef OSGUTIL_FLIGHTMANIPULATOR
#define OSGUTIL_FLIGHTMANIPULATOR 1
#include <osgUtil/CameraManipulator>
namespace osgUtil{
class OSGUTIL_EXPORT FlightManipulator : public CameraManipulator
{
public:
FlightManipulator();
virtual ~FlightManipulator();
/** 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 osg::Node* getNode() const;
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual void home(GUIEventAdapter& ea,GUIActionAdapter& us);
/** Start/restart the manipulator.*/
virtual void init(GUIEventAdapter& ea,GUIActionAdapter& us);
/** handle events, return true if handled, false otherwise.*/
virtual bool update(GUIEventAdapter& ea,GUIActionAdapter& us);
enum YawControlMode {
YAW_AUTOMATICALLY_WHEN_BANKED,
NO_AUTOMATIC_YAW
};
/** Set the yaw control between no yaw and yawing when banked.*/
void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
private:
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(GUIEventAdapter& ea);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/
bool calcMovement();
// Internal event stack comprising last three mouse events.
osg::ref_ptr<GUIEventAdapter> _ga_t1;
osg::ref_ptr<GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _velocity;
YawControlMode _yawMode;
};
}
#endif

View File

@@ -0,0 +1,23 @@
#ifndef OSGUTIL_GUIACTIONADAPTER
#define OSGUTIL_GUIACTIONADAPTER 1
#include <osgUtil/Export>
namespace osgUtil{
/** Pure virtual base class for adapting the GUI actions for use in CameraManipulators.*/
class GUIActionAdapter
{
public:
virtual void needRedraw(bool needed=true) = 0;
virtual void needContinuousUpdate(bool needed=true) = 0;
virtual void needWarpPointer(int x,int y) = 0;
};
}
#endif

View File

@@ -0,0 +1,80 @@
#ifndef OSGUTIL_GUIEVENTADAPTER
#define OSGUTIL_GUIEVENTADAPTER 1
#include <osg/Referenced>
#include <osgUtil/Export>
namespace osgUtil{
/** Pure virtual base class for adapting platform specfic events into
generic keyboard and mouse events. */
class GUIEventAdapter : public osg::Referenced
{
public:
GUIEventAdapter() {}
enum MouseButtonMask {
LEFT_BUTTON=1,
MIDDLE_BUTTON=2,
RIGHT_BUTTON=4
};
enum EventType {
PUSH,
RELEASE,
DRAG,
MOVE,
KEYBOARD,
FRAME,
RESIZE,
NONE
};
/** Get the EventType of the GUI event.*/
virtual EventType getEventType() const = 0;
/** key pressed, return -1 if inapropriate for this event. */
virtual int getKey() const = 0;
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const = 0;
/** window minimum x. */
virtual int getXmin() const = 0;
/** window maximum x. */
virtual int getXmax() const = 0;
/** window minimum y. */
virtual int getYmin() const = 0;
/** window maximum y. */
virtual int getYmax() const = 0;
/** current mouse x position.*/
virtual int getX() const = 0;
/** current mouse y position.*/
virtual int getY() const = 0;
/** current mouse button state */
virtual unsigned int getButtonMask() const = 0;
/** time in seconds of event. */
virtual float time() const = 0;
protected:
/** Force users to create on heap, so that mulitple referencing is safe.*/
virtual ~GUIEventAdapter() {}
};
}
#endif

View File

@@ -0,0 +1,142 @@
#ifndef OSGUTIL_INTERSECTVISITOR
#define OSGUTIL_INTERSECTVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Seg>
#include <osg/Geode>
#include <osg/Matrix>
#include <osgUtil/Export>
#include <map>
#include <set>
#include <vector>
namespace osgUtil {
class OSGUTIL_EXPORT IntersectState : public osg::Referenced
{
public:
IntersectState();
osg::Matrix* _matrix;
osg::Matrix* _inverse;
typedef std::vector< std::pair<osg::Seg*,osg::Seg*> > SegList;
SegList _segList;
typedef unsigned int SegmentMask;
typedef std::vector<SegmentMask> SegmentMaskStack;
SegmentMaskStack _segmentMaskStack;
bool isCulled(const osg::BoundingSphere& bs,SegmentMask& segMaskOut);
bool isCulled(const osg::BoundingBox& bb,SegmentMask& segMaskOut);
protected:
~IntersectState();
};
class OSGUTIL_EXPORT Hit : public osg::Referenced
{
public:
Hit();
Hit(const Hit& hit);
~Hit();
Hit& operator = (const Hit& hit);
typedef std::vector<int> VecIndexList;
bool operator < (const Hit& hit) const
{
if (_originalSeg<hit._originalSeg) return true;
if (_originalSeg>hit._originalSeg) return false;
return _ratio<hit._ratio;
}
float _ratio;
osg::Seg* _originalSeg;
osg::Seg* _localSeg;
osg::NodePath _nodePath;
osg::Geode* _geode;
osg::GeoSet* _geoset;
osg::Matrix* _matrix;
VecIndexList _vecIndexList;
int _primitiveIndex;
osg::Vec3 _intersectPoint;
osg::Vec3 _intersectNormal;
};
/** Basic visitor for ray based collisions of a scene.
Note, still in development, current version has not
pratical functionality!*/
class OSGUTIL_EXPORT IntersectVisitor : public osg::NodeVisitor
{
public:
IntersectVisitor();
virtual ~IntersectVisitor();
void reset();
/** Add a line segment to use for intersection testing during scene traversal.*/
void addSeg(osg::Seg* seg);
/** Modes to control how IntersectVisitor reports hits. */
enum HitReportingMode {
ONLY_NEAREST_HIT,
ALL_HITS
};
/** Set the mode of how hits should reported back from a traversal.*/
void setHitReportingMode(HitReportingMode hrm) { _hitReportingMode = hrm; }
/** Get the mode of how hits should reported back from a traversal.*/
HitReportingMode getHitReportingMode() { return _hitReportingMode; }
//typedef std::multiset<Hit> HitList;
typedef std::vector<Hit> HitList;
typedef std::map<osg::Seg*,HitList > SegHitListMap;
HitList& getHitList(osg::Seg* seg) { return _segHitList[seg]; }
int getNumHits(osg::Seg* seg) { return _segHitList[seg].size(); }
bool hits();
virtual void apply(osg::Node&);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::DCS& node);
virtual void apply(osg::Switch& node);
virtual void apply(osg::LOD& node);
virtual void apply(osg::Scene& node);
protected:
bool intersect(osg::GeoSet& gset);
void pushMatrix(const osg::Matrix& matrix);
void popMatrix();
bool enterNode(osg::Node& node);
void leaveNode();
typedef std::vector<IntersectState*> IntersectStateStack;
IntersectStateStack _intersectStateStack;
osg::NodePath _nodePath;
HitReportingMode _hitReportingMode;
SegHitListMap _segHitList;
};
};
#endif

View File

@@ -0,0 +1,196 @@
#ifndef OSGUTIL_RENDERVISITOR
#define OSGUTIL_RENDERVISITOR 1
#include <osg/NodeVisitor>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/Matrix>
#include <osg/GeoSet>
#include <osg/GeoState>
#include <osg/Camera>
#include <osgUtil/Export>
#include <map>
#include <vector>
namespace osgUtil {
/** Container class for encapsulating the viewing state in local
coordinates, during the cull traversal.
*/
class OSGUTIL_EXPORT ViewState : public osg::Referenced
{
public:
ViewState();
osg::Matrix* _matrix;
osg::Matrix* _inverse;
osg::Vec3 _eyePoint;
osg::Vec3 _centerPoint;
osg::Vec3 _lookVector;
osg::Vec3 _upVector;
osg::Vec3 _frustumTopNormal;
osg::Vec3 _frustumBottomNormal;
osg::Vec3 _frustumLeftNormal;
osg::Vec3 _frustumRightNormal;
float _ratio;
bool _viewFrustumCullingActive;
bool _smallFeatureCullingActive;
bool isCulled(const osg::BoundingSphere& sp);
bool isCulled(const osg::BoundingBox& bb);
protected:
~ViewState();
};
/**
* Basic NodeVisitor implementation for rendering a scene.
* This visitor traverses the scene graph, collecting transparent and
* opaque osg::GeoSets into a depth sorted transparent bin and a state
* sorted opaque bin. The opaque bin is rendered first, and then the
* transparent bin in rendered in order from the furthest osg::GeoSet
* from the eye to the one nearest the eye.
*/
class OSGUTIL_EXPORT RenderVisitor : public osg::NodeVisitor
{
public:
RenderVisitor();
virtual ~RenderVisitor();
void reset();
virtual void apply(osg::Node&);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::LightSource& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::DCS& node);
virtual void apply(osg::Switch& node);
virtual void apply(osg::LOD& node);
virtual void apply(osg::Scene& node);
void setGlobalState(osg::GeoState* global);
void setPerspective(const osg::Camera& camera);
void setPerspective(float fovy,float aspect,float znear,float zfar);
void setLookAt(const osg::Camera& camera);
void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& upVector);
void setLookAt(double eyeX,double eyeY,double eyeZ,
double centerX,double centerY,double centerZ,
double upX,double upY,double upZ);
void setLODBias(float bias) { _LODBias = bias; }
float getLODBias() { return _LODBias; }
enum TransparencySortMode {
LOOK_VECTOR_DISTANCE,
OBJECT_EYE_POINT_DISTANCE
};
void setTransparencySortMode(TransparencySortMode tsm) { _tsm = tsm; }
enum CullingType {
VIEW_FRUSTUM_CULLING,
SMALL_FEATURE_CULLING
};
/**
* Enables/disables the specified culling type.
* @param ct The culling type to enable/disable.
* @param active true enables the culling type, false disables.
*/
void setCullingActive(CullingType ct, bool active);
/**
* Returns the state of the specified culling type.
* @result true, if culling type is enabled, false otherwise.
*/
bool getCullingActive(CullingType ct);
/**
* Calculates the near_plane and the far_plane for the current
* camera view depending on the objects currently stored in the
* opaque and transparent bins.
* @param near_plane reference to a variable that can store the
* near plane result.
* @param far_plane reference to a variable that can store the
* far plane result.
* @result true, if near_plane and far_plane contain valid values,
* false otherwise.
*/
bool calcNearFar(double& near_plane, double& far_plane);
/**
* Renders the osg::GeoSets that were collected in the opaque and
* transparent bins before.
*/
void render();
protected:
void pushMatrix(const osg::Matrix& matrix);
void popMatrix();
osg::Matrix* getCurrentMatrix();
osg::Matrix* getInverseCurrentMatrix();
const osg::Vec3& getEyeLocal();
const osg::Vec3& getCenterLocal();
const osg::Vec3& getLookVectorLocal();
bool _viewFrustumCullingActive;
bool _smallFeatureCullingActive;
bool isCulled(const osg::BoundingSphere& sp);
bool isCulled(const osg::BoundingBox& bb);
typedef std::pair<osg::Matrix*,osg::GeoSet*> MatrixGeoSet;
typedef std::vector<ViewState*> ViewStateStack;
ViewStateStack _viewStateStack;
ViewState* _tvs;
ViewState* _cvs;
typedef std::multimap<osg::GeoState*,MatrixGeoSet> OpaqueList;
typedef std::multimap<float,MatrixGeoSet> TransparentList;
typedef std::map<osg::Matrix*,osg::Light*> LightList;
OpaqueList _opaqueGeoSets;
TransparentList _transparentGeoSets;
LightList _lights;
osg::GeoState* _globalState;
float _LODBias;
float _fovy;
float _aspect;
float _znear;
float _zfar;
void calculateClippingPlanes();
// frustum clipping normals.
osg::Vec3 _frustumTop;
osg::Vec3 _frustumBottom;
osg::Vec3 _frustumLeft;
osg::Vec3 _frustumRight;
TransparencySortMode _tsm;
};
};
#endif

165
include/osgUtil/SceneView Normal file
View File

@@ -0,0 +1,165 @@
#ifndef OSGUTIL_SCENEVIEW
#define OSGUTIL_SCENEVIEW 1
#include <osg/Node>
#include <osg/GeoState>
#include <osg/Light>
#include <osg/Camera>
#include <osgUtil/RenderVisitor>
#include <osgUtil/Export>
namespace osgUtil {
/**
* SceneView is literaly a view of a scene, encapsulating the
* camera, global state, lights and the scene itself. Provides
* methods for setting up the view and rendering it.
*/
class OSGUTIL_EXPORT SceneView : public osg::Referenced
{
public:
/** Constrcut a default scene view.*/
SceneView();
/** Set the data which to view. The data will typically be
* an osg::Scene but can be any osg::Node type.
*/
void setSceneData(osg::Node* node) { _sceneData = node; _need_compile = true;}
/** Get the scene data which to view. The data will typically be
* an osg::Scene but can be any osg::Node type.
*/
osg::Node* getSceneData() { return _sceneData.get(); }
/** Set the viewport of the scene view. */
void setViewport(int x,int y,int width,int height)
{
_view[0] = x;
_view[1] = y;
_view[2] = width;
_view[3] = height;
}
/** Get the viewport of the scene view. */
void getViewport(int& x,int& y,int& width,int& height)
{
x = _view[0];
y = _view[1];
width = _view[2];
height = _view[3];
}
/** Set scene view to use default global state, light, camera
* and render visitor.
*/
void setDefaults();
/** Set the background color used in glClearColor().
Defaults to an off blue color.*/
void setBackgroundColor(const osg::Vec4& color) { _backgroundColor=color; }
/** Get the background color.*/
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
void setGlobalState(osg::GeoState* state) { _globalState = state; }
osg::GeoState* getGlobalState() const { return _globalState.get(); }
enum LightingMode {
HEADLIGHT, // default
SKY_LIGHT,
NO_SCENEVIEW_LIGHT
};
void setLightingMode(LightingMode mode) { _lightingMode=mode; }
LightingMode getLightingMode() const { return _lightingMode; }
void setLight(osg::Light* light) { _light = light; }
osg::Light* getLight() const { return _light.get(); }
void setCamera(osg::Camera* camera) { _camera = camera; }
osg::Camera* getCamera() const { return _camera.get(); }
void setRenderVisitor(osgUtil::RenderVisitor* rv) { _renderVisitor = rv; }
osgUtil::RenderVisitor* getRenderVisitor() const { return _renderVisitor.get(); }
void setLODBias(float bias) { _lodBias = bias; }
float getLODBias() const { return _lodBias; }
/** Set to true if you want SceneView to automatically calculate values
for the near/far clipping planes, each frame, set false to use camera's
internal near and far planes. Default value is true.
*/
void setCalcNearFar(bool calc) { _calc_nearfar = calc; }
/** return true if SceneView automatically caclculates near and
far clipping planes for each frame.
*/
bool getCalcNearFar() { return _calc_nearfar; }
/** Calculate, via glUnProject, the object coordinates of a window point.
Note, current implementation requires that SceneView::draw() has been previously called
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
windows coordinates are calculated relative to the bottom left of the window.
Returns true on successful projection.
*/
bool projectWindowIntoObject(const osg::Vec3& window,osg::Vec3& object) const;
/** Calculate, via glUnProject, the object coordinates of a window x,y
when projected onto the near and far planes.
Note, current implementation requires that SceneView::draw() has been previously called
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
windows coordinates are calculated relative to the bottom left of the window.
Returns true on successful projection.
*/
bool projectWindowXYIntoObject(int x,int y,osg::Vec3& near_point,osg::Vec3& far_point) const;
/** Calculate, via glProject, the object coordinates of a window.
Note, current implementation requires that SceneView::draw() has been previously called
for projectWindowIntoObject to produce valid values. Consistent with OpenGL
windows coordinates are calculated relative to the bottom left of the window,
whereas as window API's normally have the top left as the origin,
so you may need to pass in (mouseX,window_height-mouseY,...).
Returns true on successful projection.
*/
bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const;
virtual void cull();
virtual void draw();
protected:
virtual ~SceneView();
osg::ref_ptr<osg::Node> _sceneData;
osg::ref_ptr<osg::GeoState> _globalState;
osg::ref_ptr<osg::Light> _light;
osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osgUtil::RenderVisitor> _renderVisitor;
bool _need_compile;
bool _calc_nearfar;
osg::Vec4 _backgroundColor;
double _near_plane;
double _far_plane;
float _lodBias;
// viewport x,y,width,height respectiveyly.
GLint _view[4];
// model and project matices, used by glUnproject to get
// to generate rays form the eyepoint through the mouse x,y.
GLdouble _model[16];
GLdouble _proj[16];
LightingMode _lightingMode;
};
};
#endif

View File

@@ -0,0 +1,70 @@
#ifndef OSGUTIL_TRACKBALLMANIPULATOR
#define OSGUTIL_TRACKBALLMANIPULATOR 1
#include <osgUtil/CameraManipulator>
namespace osgUtil{
class OSGUTIL_EXPORT TrackballManipulator : public CameraManipulator
{
public:
TrackballManipulator();
virtual ~TrackballManipulator();
/** 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 osg::Node* getNode() const;
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual void home(GUIEventAdapter& ea,GUIActionAdapter& us);
/** Start/restart the manipulator.*/
virtual void init(GUIEventAdapter& ea,GUIActionAdapter& us);
/** handle events, return true if handled, false otherwise.*/
virtual bool update(GUIEventAdapter& ea,GUIActionAdapter& us);
private:
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(GUIEventAdapter& ea);
/** 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<GUIEventAdapter> _ga_t1;
osg::ref_ptr<GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _minimumZoomScale;
bool _thrown;
};
}
#endif

35
include/osgUtil/Version Normal file
View File

@@ -0,0 +1,35 @@
#ifndef OSGUTIL_VERSION
#define OSGUTIL_VERSION 1
#include <osgUtil/Export>
extern "C" {
/**
* getVersion_osgUtil() returns the library version number.
* Numbering conventon : osg_src-0.8-31 will return 0.8.31 from getVersion_osgUtil.
*
* This C function can be also used to check for the existance of the OpenSceneGraph
* library using autoconf and its m4 macro AC_CHECK_LIB.
*
* Here is the code to add to your configure.in:
\verbatim
#
# Check for the OpenSceneGraph (OSG) utility library
#
AC_CHECK_LIB(osg, osgUtilGetVersion, ,
[AC_MSG_ERROR(OpenSceneGraph utility library not found. See http://www.openscenegraph.org)],)
\endverbatim
*/
extern OSGUTIL_EXPORT const char* osgUtilGetVersion();
/**
* getLibraryName_osgUtil() returns the library name in human friendly form.
*/
extern OSGUTIL_EXPORT const char* osgUtilGetLibraryName();
};
#endif