Hi,
I'm scratching my head on this one.
I have a line segment, that is aligned to the tracked wand. I'm trying
to intersect it with the scene, which is composed of a single box.
However, the intersections that I get are not making sense.
Here is the line segment, made from two points:
p1 = ( -.24, 5.5, .033 ) p2 = (-.24 5.5 -1.96)
Note that this is a line of constant Y=5.5
Length of 2 along the -Z direction.
The box is cenetered at 0, 4.5, -1, and has unit dimensions.
The bounding box of the box is:
xyzMin = [-.5, 4, -1.5] xyzMax = [.5, 5, -.5]
The box has no transformations above it, it's a direct child of the
scene root.
When I run IntersectVisitor on the graph, it detects an intersection
with the box at: [-.17, 4.0, -.88]
Which is NOT on the LineSegment.
I'm confused. Here is the code that I'm using.
m_wandP1 and m_wandP2 are the two points mentioned above.
Thanks,
-dave
void CWand::UpdateIntersect( osg::Group *pSceneRoot )
{
osg::Vec3 wandDir = m_wandP2 - m_wandP1;
//Create a line segment for the wand end points.
osg::ref_ptr<osg::LineSegment> wandStick = new osg::LineSegment(
m_wandP2, -wandDir );
//Intersect with the scene graph.
osgUtil::IntersectVisitor intersectVisitor;
intersectVisitor.setLODSelectionMode(
osgUtil::IntersectVisitor::USE_HIGHEST_LEVEL_OF_DETAIL );
intersectVisitor.addLineSegment( wandStick.get() );
pSceneRoot->accept( intersectVisitor );
if ( m_bPrintUpdate )
printf( "Poke: P0 <%f %f %f> P1 <%f %f %f> Dir:[%f %f %f]\n\n",
m_wandP1[0],m_wandP1[1],m_wandP1[2],
m_wandP2[0],m_wandP2[1],m_wandP2[2],
wandDir[0],wandDir[1],wandDir[2] );
osgUtil:: IntersectVisitor::HitList htl =
intersectVisitor.getHitList( wandStick.get() );
vector<osg::Geode*> geodeHits;
int numHits = 0;
if ( htl.size() > 0 ) // We always hit the wand, so only consider
"additional" hits.
{
for ( int i = 0; i < htl.size(); i++ )
{
osg::Vec3 pt = htl[i].getWorldIntersectPoint();
osg::Vec3 n = htl[i].getWorldIntersectNormal();
osg::NodePath np = htl[i].getNodePath();
//osg::Vec3 pt = htl[i].getLocalIntersectPoint();
osg::Vec3 dir = m_wandP1-pt;
if ( true )
{
numHits++;
geodeHits.push_back( htl[i].getGeode() );
if ( m_bPrintUpdate )
{
printf( "\tIsect[%d]: %s D=%f [%f %f %f] Pt=<%f %f %f> N<%f
%f
%f>\n", numHits,
htl[i].getGeode()->getName().c_str(),
dir.length(),
dir[0],dir[1],dir[2],pt[0],pt[1],pt[2],
n[0],n[1],n[2] );
osg::BoundingBox bb = htl[i].getGeode()->getBoundingBox();
printf( "\tBBOX: [%f %f %f] [%f %f %f]\n",
bb.xMin(),bb.yMin(),bb.zMin(),
bb.xMax(),bb.yMax(),bb.zMax() );
printf( "\t Node path:\n" );
for ( int j = 0; j < np.size(); j++ )
{
osg::Node *node = np[j];
printf( "\t%d: %s\n", j, node->className() );
osg::MatrixTransform *pMT =
dynamic_cast<osg::MatrixTransform*>(node);
osg::PositionAttitudeTransform *pPAT =
dynamic_cast<osg::PositionAttitudeTransform*>(node);
if ( pMT != NULL ) //node->className() ==
"MatrixTransform" )
{
osg::MatrixTransform *pMtx = (osg::MatrixTransform
*) node;
osg::Matrix mtx = pMtx->getMatrix();
printf( "\t T[%f %f %f] [%f %f %f] [%f %f %f] [%f
%f %f]\n",
mtx(3,0),mtx(3,1),mtx(3,2),
mtx(0,0),mtx(0,1),mtx(0,2),
mtx(1,0),mtx(1,1),mtx(1,2),
mtx(2,0),mtx(2,1),mtx(2,2) );
}
else if ( pPAT != NULL )
{
osg::Vec3 p = pPAT->getPosition();
osg::Quat Q = pPAT->getAttitude();
osg::Vec4 q = Q.asVec4();
printf( "\t T[ %f %f %f] Q[%f %f %f %f]\n",
p[0],p[1],p[2], q[0],q[1],q[2],q[3] );
}
else
printf( "??\n" );
}
//osg::Matrix *mtx = (osg::Matrix*)htl[i].getMatrix();
//printf( "\tRM: [%f %f %f]\n", (*mtx)(0,0), (*mtx)(0,1),
(*mtx)(0,2) );
}
}
}
}
m_wandShapeDrawable->setColor( (numHits > 0 ? m_IntersectColor :
m_Color) );
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org