Added support for osgUtil::Intersectors being in WINDOW, PROJECTION, VIEW or MODEL coordinates

This commit is contained in:
Robert Osfield
2006-11-01 14:41:32 +00:00
parent a253e17d3e
commit 75169ad16f
3 changed files with 170 additions and 20 deletions

View File

@@ -34,9 +34,23 @@ class Intersector : public osg::Referenced
{
public:
enum CoordinateFrame
{
WINDOW,
PROJECTION,
VIEW,
MODEL
};
Intersector():
_coordinateFrame(MODEL),
_disabledCount(0) {}
void setCoordinateFrame(CoordinateFrame cf) { _coordinateFrame = cf; }
CoordinateFrame getCoordinateFrame() const { return _coordinateFrame; }
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv) = 0;
virtual bool enter(const osg::Node& node) = 0;
@@ -57,6 +71,7 @@ class Intersector : public osg::Referenced
protected:
CoordinateFrame _coordinateFrame;
unsigned int _disabledCount;
};
@@ -68,9 +83,13 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
public:
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end, LineSegmentIntersector* parent=0);
struct Intersection
{
Intersection():
ratio(-1.0),
primitiveIndex(0) {}
bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; }
typedef std::vector<unsigned int> IndexList;
@@ -90,7 +109,8 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
public:
@@ -199,12 +219,24 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
/** Get the const read callback.*/
const ReadCallback* getReadCallback() const { return _readCallback.get(); }
void pushWindowMatrix(osg::RefMatrix* matrix) { _windowStack.push_back(matrix); }
void pushWindowMatrix(osg::Viewport* viewport) { _windowStack.push_back(new osg::RefMatrix( viewport->computeWindowMatrix()) ); }
void popWindowMatrix() { _windowStack.pop_back(); }
osg::RefMatrix* getWindowMatrix() { return _windowStack.empty() ? 0 : _windowStack.back().get(); }
osg::RefMatrix* getProjectionMatrix() { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
osg::RefMatrix* getViewMatrix() { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
osg::RefMatrix* getModelMatrix() { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
void pushProjectionMatrix(osg::RefMatrix* matrix) { _projectionStack.push_back(matrix); }
void popProjectionMatrix() { _projectionStack.pop_back(); }
osg::RefMatrix* getProjectionMatrix() { return _projectionStack.empty() ? 0 : _projectionStack.back().get(); }
void pushViewMatrix(osg::RefMatrix* matrix) { _viewStack.push_back(matrix); }
void popViewMatrix() { _viewStack.pop_back(); }
osg::RefMatrix* getViewMatrix() { return _viewStack.empty() ? 0 : _viewStack.back().get(); }
void pushModelMatrix(osg::RefMatrix* matrix) { _modelStack.push_back(matrix); }
void popModelMatrix() { _modelStack.pop_back(); }
osg::RefMatrix* getModelMatrix() { return _modelStack.empty() ? 0 : _modelStack.back().get(); }
public: