Projector
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.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_PROJECTOR
#define OSGMANIPULATOR_PROJECTOR 1
#include <osgManipulator/Export>
#include <osg/LineSegment>
#include <osgUtil/SceneView>
#include <osgManipulator/Dragger>
namespace osgManipulator {
class OSGMANIPULATOR_EXPORT Projector : public osg::Referenced
{
public:
Projector();
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const = 0;
void setLocalToWorld(const osg::Matrix& localToWorld)
{
_localToWorld = localToWorld;
_worldToLocalDirty = true;
}
inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
inline const osg::Matrix& getWorldToLocal() const
{
if (_worldToLocalDirty)
{
_worldToLocal.invert(_localToWorld);
_worldToLocalDirty = false;
}
return _worldToLocal;
}
protected:
virtual ~Projector();
osg::Matrix _localToWorld;
mutable osg::Matrix _worldToLocal;
mutable bool _worldToLocalDirty;
};
class OSGMANIPULATOR_EXPORT LineProjector : public Projector
{
public:
LineProjector();
LineProjector(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e);
inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
inline osg::LineSegment::vec_type& getLineStart() { return _line->start(); }
inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
inline osg::LineSegment::vec_type& getLineEnd() { return _line->end(); }
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
protected:
virtual ~LineProjector();
osg::ref_ptr<osg::LineSegment> _line;
};
class OSGMANIPULATOR_EXPORT PlaneProjector : public Projector
{
public:
PlaneProjector();
PlaneProjector(const osg::Plane& plane);
inline void setPlane(const osg::Plane& plane) { _plane = plane; }
inline const osg::Plane& getPlane() const { return _plane; }
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
protected:
virtual ~PlaneProjector();
osg::Plane _plane;
};
class OSGMANIPULATOR_EXPORT SphereProjector : public Projector
{
public:
SphereProjector();
SphereProjector(osg::Sphere* sphere);
inline void setSphere(osg::Sphere* sphere) { _sphere = sphere; }
inline const osg::Sphere* getSphere() const { return _sphere.get(); }
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const;
void setFront(bool front) { _front = front; }
protected:
virtual ~SphereProjector();
osg::ref_ptr<osg::Sphere> _sphere;
bool _front;
};
class OSGMANIPULATOR_EXPORT SpherePlaneProjector : public SphereProjector
{
public:
SpherePlaneProjector();
SpherePlaneProjector(osg::Sphere* sphere);
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
bool isProjectionOnSphere() const { return _onSphere; }
osg::Quat getRotation(const osg::Vec3d& p1, bool p1OnSphere,
const osg::Vec3d& p2, bool p2OnSphere,
float radialFactor = 0.0f) const;
protected:
virtual ~SpherePlaneProjector();
mutable osg::Plane _plane;
mutable bool _onSphere;
};
class OSGMANIPULATOR_EXPORT CylinderProjector : public Projector
{
public:
CylinderProjector();
CylinderProjector(osg::Cylinder* cylinder);
inline void setCylinder(osg::Cylinder* cylinder)
{
_cylinder = cylinder;
_cylinderAxis = osg::Vec3d(0.0,0.0,1.0) * osg::Matrix(cylinder->getRotation());
_cylinderAxis.normalize();
}
inline const osg::Cylinder* getCylinder() const { return _cylinder.get(); }
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const;
void setFront(bool front) { _front = front; }
protected:
virtual ~CylinderProjector();
osg::ref_ptr<osg::Cylinder> _cylinder;
osg::Vec3d _cylinderAxis;
bool _front;
};
class OSGMANIPULATOR_EXPORT CylinderPlaneProjector : public CylinderProjector
{
public:
CylinderPlaneProjector();
CylinderPlaneProjector(osg::Cylinder* cylinder);
virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
osg::Quat getRotation(const osg::Vec3d& p1, const osg::Vec3d& p2) const;
protected:
virtual ~CylinderPlaneProjector();
mutable osg::Plane _plane;
mutable osg::Vec3d _planeLineStart, _planeLineEnd;
mutable bool _parallelPlane;
};
}
#endif
Dragger
LineSegment
SceneView
osgManipulator::CylinderPlaneProjector::_plane
osg::Plane _plane
Definition Projector:303
osgManipulator::CylinderPlaneProjector::_planeLineStart
osg::Vec3d _planeLineStart
Definition Projector:304
osgManipulator::CylinderPlaneProjector::getRotation
osg::Quat getRotation(const osg::Vec3d &p1, const osg::Vec3d &p2) const
osgManipulator::CylinderPlaneProjector::_parallelPlane
bool _parallelPlane
Definition Projector:305
osgManipulator::CylinderPlaneProjector::_planeLineEnd
osg::Vec3d _planeLineEnd
Definition Projector:304
osgManipulator::CylinderPlaneProjector::~CylinderPlaneProjector
virtual ~CylinderPlaneProjector()
osgManipulator::CylinderPlaneProjector::CylinderPlaneProjector
CylinderPlaneProjector(osg::Cylinder *cylinder)
osgManipulator::CylinderPlaneProjector::CylinderPlaneProjector
CylinderPlaneProjector()
osgManipulator::CylinderPlaneProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::CylinderProjector::_cylinder
osg::ref_ptr< osg::Cylinder > _cylinder
Definition Projector:260
osgManipulator::CylinderProjector::_front
bool _front
Definition Projector:262
osgManipulator::CylinderProjector::getCylinder
const osg::Cylinder * getCylinder() const
Definition Projector:238
osgManipulator::CylinderProjector::isPointInFront
bool isPointInFront(const PointerInfo &pi, const osg::Matrix &localToWorld) const
osgManipulator::CylinderProjector::CylinderProjector
CylinderProjector(osg::Cylinder *cylinder)
osgManipulator::CylinderProjector::setCylinder
void setCylinder(osg::Cylinder *cylinder)
Definition Projector:232
osgManipulator::CylinderProjector::_cylinderAxis
osg::Vec3d _cylinderAxis
Definition Projector:261
osgManipulator::CylinderProjector::setFront
void setFront(bool front)
Definition Projector:254
osgManipulator::CylinderProjector::~CylinderProjector
virtual ~CylinderProjector()
osgManipulator::CylinderProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::CylinderProjector::CylinderProjector
CylinderProjector()
osgManipulator::LineProjector::_line
osg::ref_ptr< osg::LineSegment > _line
Definition Projector:116
osgManipulator::LineProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::LineProjector::LineProjector
LineProjector()
osgManipulator::LineProjector::getLineEnd
const osg::LineSegment::vec_type & getLineEnd() const
Definition Projector:102
osgManipulator::LineProjector::getLineStart
osg::LineSegment::vec_type & getLineStart()
Definition Projector:100
osgManipulator::LineProjector::getLineStart
const osg::LineSegment::vec_type & getLineStart() const
Definition Projector:99
osgManipulator::LineProjector::setLine
void setLine(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
Definition Projector:97
osgManipulator::LineProjector::getLineEnd
osg::LineSegment::vec_type & getLineEnd()
Definition Projector:103
osgManipulator::LineProjector::LineProjector
LineProjector(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
osgManipulator::LineProjector::~LineProjector
virtual ~LineProjector()
osgManipulator::PlaneProjector::setPlane
void setPlane(const osg::Plane &plane)
Definition Projector:130
osgManipulator::PlaneProjector::~PlaneProjector
virtual ~PlaneProjector()
osgManipulator::PlaneProjector::getPlane
const osg::Plane & getPlane() const
Definition Projector:131
osgManipulator::PlaneProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::PlaneProjector::PlaneProjector
PlaneProjector()
osgManipulator::PlaneProjector::_plane
osg::Plane _plane
Definition Projector:144
osgManipulator::PlaneProjector::PlaneProjector
PlaneProjector(const osg::Plane &plane)
osgManipulator::PointerInfo
Definition Dragger:84
osgManipulator::Projector::getWorldToLocal
const osg::Matrix & getWorldToLocal() const
Definition Projector:65
osgManipulator::Projector::getLocalToWorld
const osg::Matrix & getLocalToWorld() const
Definition Projector:59
osgManipulator::Projector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const =0
osgManipulator::Projector::~Projector
virtual ~Projector()
osgManipulator::Projector::_worldToLocalDirty
bool _worldToLocalDirty
Definition Projector:82
osgManipulator::Projector::setLocalToWorld
void setLocalToWorld(const osg::Matrix &localToWorld)
Definition Projector:49
osgManipulator::Projector::_worldToLocal
osg::Matrix _worldToLocal
Definition Projector:80
osgManipulator::Projector::_localToWorld
osg::Matrix _localToWorld
Definition Projector:79
osgManipulator::Projector::Projector
Projector()
osgManipulator::SpherePlaneProjector::SpherePlaneProjector
SpherePlaneProjector()
osgManipulator::SpherePlaneProjector::_plane
osg::Plane _plane
Definition Projector:217
osgManipulator::SpherePlaneProjector::isProjectionOnSphere
bool isProjectionOnSphere() const
Definition Projector:207
osgManipulator::SpherePlaneProjector::~SpherePlaneProjector
virtual ~SpherePlaneProjector()
osgManipulator::SpherePlaneProjector::getRotation
osg::Quat getRotation(const osg::Vec3d &p1, bool p1OnSphere, const osg::Vec3d &p2, bool p2OnSphere, float radialFactor=0.0f) const
osgManipulator::SpherePlaneProjector::_onSphere
bool _onSphere
Definition Projector:218
osgManipulator::SpherePlaneProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::SpherePlaneProjector::SpherePlaneProjector
SpherePlaneProjector(osg::Sphere *sphere)
osgManipulator::SphereProjector::setFront
void setFront(bool front)
Definition Projector:174
osgManipulator::SphereProjector::getSphere
const osg::Sphere * getSphere() const
Definition Projector:159
osgManipulator::SphereProjector::SphereProjector
SphereProjector(osg::Sphere *sphere)
osgManipulator::SphereProjector::project
virtual bool project(const PointerInfo &pi, osg::Vec3d &projectedPoint) const
osgManipulator::SphereProjector::setSphere
void setSphere(osg::Sphere *sphere)
Definition Projector:158
osgManipulator::SphereProjector::~SphereProjector
virtual ~SphereProjector()
osgManipulator::SphereProjector::_sphere
osg::ref_ptr< osg::Sphere > _sphere
Definition Projector:180
osgManipulator::SphereProjector::isPointInFront
bool isPointInFront(const PointerInfo &pi, const osg::Matrix &localToWorld) const
osgManipulator::SphereProjector::SphereProjector
SphereProjector()
osgManipulator::SphereProjector::_front
bool _front
Definition Projector:181
osg::Cylinder
Definition Shape:304
osg::Cylinder::getRotation
const Quat & getRotation() const
Definition Shape:345
osg::LineSegment::vec_type
Vec3d vec_type
Definition LineSegment:28
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Quat
Definition Quat:30
osg::Referenced
Definition Referenced:44
osg::Sphere
Definition Shape:147
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgManipulator
Definition AntiSquish:23
osg::Matrix
Matrixd Matrix
Definition Matrix:27
Export
OSGMANIPULATOR_EXPORT
#define OSGMANIPULATOR_EXPORT
Definition osgManipulator/Export:27