本文整理汇总了C++中IntersectAction::getHitTriangle方法的典型用法代码示例。如果您正苦于以下问题:C++ IntersectAction::getHitTriangle方法的具体用法?C++ IntersectAction::getHitTriangle怎么用?C++ IntersectAction::getHitTriangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntersectAction
的用法示例。
在下文中一共展示了IntersectAction::getHitTriangle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: key
void key( unsigned char key, int , int )
{
switch ( key )
{
case 27: exit(0);
}
// Intersect
IntersectAction * act = IntersectAction::create();
static Pnt3f pnts[] = { Pnt3f( 0,0,1 ), Pnt3f( 1,0,1), Pnt3f( 2,0,1),
Pnt3f( 3,0,1), Pnt3f( 0,0,1 ), Pnt3f( 0,0,1 ),
Pnt3f( 0,0,1 ),Pnt3f( 0,0,1 ), Pnt3f( 0.9,0.9,1 ),
Pnt3f(-Inf,-Inf,-Inf) };
static Vec3f dirs[] = { Vec3f( 0,0,-1), Vec3f( 0,0,-1), Vec3f( 0,0,-1),
Vec3f( 0,0,-1), Vec3f( 0,-.2,-1), Vec3f( 0,.2,-1),
Vec3f( -.2,-.2,-1), Vec3f( .2,.2,-1), Vec3f( 0,0,-1 ),
Vec3f(-Inf,-Inf,-Inf) };
static int i = 0;
act->setLine( Line( pnts[i], dirs[i]) );
act->apply( iroot );
std::cerr << "Line " << act->getLine().getPosition() << " dir "
<< act->getLine().getDirection() << " hit: " << act->didHit() << " ";
beginEditCP(points);
points->setValue( pnts[i], 0 );
points->setValue( pnts[i] + (dirs[i] * Real32(3.0)), 1 );
if ( act->didHit() )
{
std::cerr << " object " << act->getHitObject()
<< " tri " << act->getHitTriangle()
<< " at " << act->getHitPoint();
TriangleIterator it( act->getHitObject() );
it.seek( act->getHitTriangle() );
Matrix m;
act->getHitObject()->getToWorld(m);
Pnt3f p = it.getPosition(0);
m.mult(p, p);
points->setValue( p, 2 );
p = it.getPosition(1);
m.mult(p, p);
points->setValue( p, 3 );
p = it.getPosition(2);
m.mult(p, p);
points->setValue( p, 4 );
}
else
{
points->setValue( Pnt3f(0,0,0), 2 );
points->setValue( Pnt3f(0,0,0), 3 );
points->setValue( Pnt3f(0,0,0), 4 );
}
endEditCP(points);
std::cerr << std::endl;
glutPostRedisplay();
if ( pnts[++i][0] == -Inf )
i = 0;
}
示例2: main
//.........这里部分代码省略.........
// create old action
IntersectAction *pIntAction = IntersectAction ::create();
// make sure bv are up to date
pScene->updateVolume();
SINFO << "-=< Intersect >=-" << endLog;
std::vector<Line>::iterator itRays = testRays.begin();
std::vector<Line>::iterator endRays = testRays.end ();
for(; itRays != endRays; ++itRays)
{
// DepthFirst
tStart = getSystemTime();
pIActorDF->setRay (*itRays);
pIActorDF->setMaxDistance(10000.0);
pIActorDF->reset ( );
pDFAction->apply(pScene);
tStop = getSystemTime();
tDFTotal += (tStop - tStart);
if(pIActorDF->getHit() == true)
{
IntersectResult result;
result._hit = true;
result._pObj = pIActorDF->getHitObject ();
result._tri = pIActorDF->getHitTriangleIndex();
result._dist = pIActorDF->getHitDistance ();
result._time = (tStop - tStart);
resultsDF.push_back(result);
}
else
{
IntersectResult result;
result._hit = false;
result._pObj = NullFC;
result._tri = -1;
result._dist = 0.0;
result._time = (tStop - tStart);
resultsDF.push_back(result);
}
std::string strStatDF;
statDF.putToString(strStatDF);
//SINFO << "stat DF: " << strStatDF << endLog;
// Depth First State
tStart = getSystemTime();
pIActorDFS->setRay (*itRays);
pIActorDFS->setMaxDistance(10000.0);
pIActorDFS->reset ( );
pDFSAction->apply(pScene);
示例3: keyboard
// react to keys
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
case ' ': // send a ray through the clicked pixel
/*
Intersection testing for rays is done using an
IntersectAction. The ray itself is calculated by the
SimpleSceneManager, given the clicked pixel.
It needs to be set up with the line that is to be
intersected. A line is a semi-infinite ray which has a
starting point and a direction, and extends in the
direction to infinity.
To do the actual test the Action's apply() method is used.
The results can be received from the Action. The main
difference is if something was hit or not, which is
returned in didHit().
If an intersection did occur, the other data elements are
valid, otherwise they are undefined.
The information that is stored in the action is the object
which was hit, the triangle of the object that was hit (in
the form of its index) and the actual hit position.
*/
{
Line l;
l = mgr->calcViewRay(x, y);
std::cerr << "From " << l.getPosition ()
<< ", dir " << l.getDirection() << std::endl;
IntersectAction *act = IntersectAction::create();
act->setLine(l);
act->apply(fileroot);
beginEditCP(isectPoints);
isectPoints->setValue(l.getPosition(), 0);
isectPoints->setValue(l.getPosition() + l.getDirection(), 1);
// did we hit something?
if (act->didHit())
{
// yes!! print and highlight it
std::cerr << " object " << act->getHitObject ()
<< " tri " << act->getHitTriangle()
<< " at " << act->getHitPoint ();
mgr->setHighlight(act->getHitObject());
// stop the ray on the hit surface
Pnt3f is = l.getPosition() +
l.getDirection() * act->getHitT();
isectPoints->setValue(is, 1);
// find the triangle that was hit
TriangleIterator it(act->getHitObject());
it.seek(act->getHitTriangle());
// Draw its normal at the intersection point
isectPoints->setValue(is, 2);
isectPoints->setValue(is + act->getHitNormal() * 5, 3);
// calculate its vertex positions in world space
Matrix m;
act->getHitObject()->getToWorld(m);
// and turn them into a triangle
Pnt3f p = it.getPosition(0);
m.mult(p, p);
isectPoints->setValue(p, 4);
p = it.getPosition(1);
m.mult(p, p);
isectPoints->setValue(p, 5);
p = it.getPosition(2);
m.mult(p, p);
isectPoints->setValue(p, 6);
}
else
{
// no, get rid of the triangle and highlight.
isectPoints->setValue(Pnt3f(0,0,0), 2);
isectPoints->setValue(Pnt3f(0,0,0), 3);
isectPoints->setValue(Pnt3f(0,0,0), 4);
//.........这里部分代码省略.........