1 #ifndef ENTITY2DINTERSECTOR_H 2 #define ENTITY2DINTERSECTOR_H 7 #include <osgUtil/LineSegmentIntersector> 14 template <
typename EntityType>
19 : osgUtil::LineSegmentIntersector(MODEL, 0.f, 0.f)
26 : osgUtil::LineSegmentIntersector(start, end)
33 : osgUtil::LineSegmentIntersector(cf, x, y)
40 : osgUtil::LineSegmentIntersector(cf, start, end)
46 void setOffset(
float offset)
51 float getOffset()
const 56 void getHitIndices(
int& first,
int& last)
const 58 if (m_hitIndices.empty()){
63 first = m_hitIndices.front();
64 last = m_hitIndices.back();
68 virtual Intersector* clone( osgUtil::IntersectionVisitor& iv )
70 if ( _coordinateFrame==MODEL && iv.getModelMatrix()==0 )
73 cloned->_parent =
this;
74 cloned->m_offset = m_offset;
75 return cloned.release();
79 switch ( _coordinateFrame )
82 if (iv.getWindowMatrix()) matrix.preMult( *iv.getWindowMatrix() );
83 if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
84 if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
85 if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
88 if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
89 if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
90 if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
93 if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
94 if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
97 if (iv.getModelMatrix()) matrix = *iv.getModelMatrix();
101 osg::Matrix inverse = osg::Matrix::inverse(matrix);
102 osg::ref_ptr<Entity2DIntersector> cloned =
new Entity2DIntersector( _start*inverse, _end*inverse );
103 cloned->_parent =
this;
104 cloned->m_offset = m_offset;
105 return cloned.release();
108 virtual void intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable )
110 osg::BoundingBox bb = drawable->getBoundingBox();
111 bb.xMin() -= m_offset; bb.xMax() += m_offset;
112 bb.yMin() -= m_offset; bb.yMax() += m_offset;
113 bb.zMin() -= m_offset; bb.zMax() += m_offset;
115 osg::Vec3d s(_start), e(_end);
116 if (!intersectAndClip(s, e, bb))
return;
117 if (iv.getDoDummyTraversal())
return;
119 EntityType* geometry =
dynamic_cast<EntityType*
>(drawable->asGeometry());
122 osg::Vec3Array* vertices =
dynamic_cast<osg::Vec3Array*
>(geometry->getVertexArray());
123 if (!vertices)
return;
125 for (
unsigned int i=1; i<vertices->size(); ++i)
130 if (m_offset<distance)
continue;
133 hit.ratio = distance;
134 hit.nodePath = iv.getNodePath();
135 hit.drawable = drawable;
136 hit.matrix = iv.getModelMatrix();
137 hit.localIntersectionPoint = (*vertices)[i];
138 m_hitIndices.push_back(i);
139 insertIntersection(hit);
149 std::vector<unsigned int> m_hitIndices;
152 #endif // ENTITY2DINTERSECTOR_H static double getSkewLinesDistance(const osg::Vec3d &r1, const osg::Vec3d &r2, const osg::Vec3d &v1, const osg::Vec3d &v2)
Definition: Utilities.cpp:271
Definition: Entity2DIntersector.h:15