当前位置: 首页>>代码示例>>C++>>正文


C++ IntersectAction::getHitPoint方法代码示例

本文整理汇总了C++中IntersectAction::getHitPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ IntersectAction::getHitPoint方法的具体用法?C++ IntersectAction::getHitPoint怎么用?C++ IntersectAction::getHitPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntersectAction的用法示例。


在下文中一共展示了IntersectAction::getHitPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:mlimper,项目名称:OpenSG1x,代码行数:70,代码来源:testIntersectActionRender.cpp

示例2: 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);
                    
//.........这里部分代码省略.........
开发者ID:mlimper,项目名称:OpenSG1x,代码行数:101,代码来源:11picking.cpp


注:本文中的IntersectAction::getHitPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。