From 4a47a79c231b98600fa84ee6f9a2bbb12da7872a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 Sep 2005 12:51:03 +0000 Subject: [PATCH] Added more intersection testing code. --- src/osgSim/SphereSegment.cpp | 61 +++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/osgSim/SphereSegment.cpp b/src/osgSim/SphereSegment.cpp index d51ab5714..1762a4b0b 100644 --- a/src/osgSim/SphereSegment.cpp +++ b/src/osgSim/SphereSegment.cpp @@ -1131,17 +1131,68 @@ struct TriangleIntersectOperator _numInside(0), _numIntersecting(0) {} - typedef osg::ref_ptr PositionArray; - typedef std::vector RegionArray; + typedef std::vector PositionArray; + typedef std::vector RegionArray; PositionArray _positions; RegionArray _regions; + osg::Vec3 _centre; float _radius; float _azMin, _azMax, _elevMin, _elevMax; unsigned int _numOutside; unsigned int _numInside; unsigned int _numIntersecting; + + void computePositionAndRegions(const osg::Matrixd& matrix, osg::Vec3Array& array) + { + _positions.resize(array.size()); + _regions.resize(array.size(), 1); + + for(unsigned int i=0; i_radius) + { + _regions[i] = 1; + } + else + { + float inv_length_xy = sqrtf(vertex.x()*vertex.x() + vertex.y()*vertex.y()); + float elevation = atan2(vertex.z(),inv_length_xy); + if (elevation<_elevMin || elevation>_elevMax) + { + _regions[i] = 1; + } + else + { + float azim = atan2(vertex.x(),vertex.y()); + if (azim<0.0) azim += 2.0f*osg::PI; + if (azim<_azMin || azim>_azMax) + { + _regions[i] = 1; + } + else + { + if (radius==_radius || elevation==_elevMin || elevation==_elevMax || azim==_azMin || azim==_azMax) + { + _regions[i] = 0; + } + else + { + _regions[i] = -1; + } + + } + } + + + } + } + + } inline void operator()(unsigned int p1, unsigned int p2, unsigned int p3) { @@ -1165,7 +1216,7 @@ struct TriangleIntersectOperator }; -SphereSegment::LineList SphereSegment::computeIntersection(const osg::Matrixd& transform, osg::Drawable* drawable) +SphereSegment::LineList SphereSegment::computeIntersection(const osg::Matrixd& matrix, osg::Drawable* drawable) { // cast to Geometry, return empty handed if Drawable not a Geometry. osg::Geometry* geometry = dynamic_cast(drawable); @@ -1178,14 +1229,14 @@ SphereSegment::LineList SphereSegment::computeIntersection(const osg::Matrixd& t typedef osg::TriangleIndexFunctor TriangleIntersectFunctor; TriangleIntersectFunctor tif; + tif._centre = _centre; tif._radius = _radius; tif._azMin = _azMin; tif._azMax = _azMax; tif._elevMin = _elevMin; tif._elevMax = _elevMax; - tif._positions = vertices; - tif._regions.resize(vertices->size(), 1); + tif.computePositionAndRegions(matrix, *vertices); // traverse the triangles in the Geometry dedicating intersections geometry->accept(tif);