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


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

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


在下文中一共展示了IntersectAction::getHitObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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         (       );
开发者ID:mlimper,项目名称:OpenSG1x,代码行数:66,代码来源:testIntersectActor.cpp

示例2: 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

示例3: mouseButtonPress

void SpaceNavigatorSSM::mouseButtonPress(UInt16 button, Int16 x, Int16 y)
{
	switch (button)
	{
		case MouseLeft:
			// test if an object is picked
			if(_objectPicking)
			{
				Line ray = calcViewRay(x, y);
				IntersectAction *iAct = IntersectAction::create();
				iAct->setLine(ray);
				iAct->apply(this->getRoot());

				// we have a hit
				if(iAct->didHit())
				{
					_pickedObjectNode = iAct->getHitObject();
					#ifdef SPACENAVIGATOR_DEBUG_OUTPUT
					std::cout << "SpaceNavigatorSSM: Object transformation mode active ( " << getName(_pickedObjectNode) << " )" << std::endl;
					#endif // SPACENAVIGATOR_DEBUG_OUTPUT

					// go up in the graph to the next transformation
					while(!_pickedObjectNode->getCore()->getType().isDerivedFrom(Transform::getClassType()))
					{
						if(_pickedObjectNode->getParent() != this->getRoot())
							_pickedObjectNode = _pickedObjectNode->getParent();
						else
						{
							// insert a new transformation node
							NodePtr pickedObject = iAct->getHitObject();
							TransformPtr newTransform = Transform::create();
							Matrix m;
							m.setIdentity();
							beginEditCP(newTransform, Transform::MatrixFieldMask);
								newTransform->setMatrix(m);
							endEditCP(newTransform, Transform::MatrixFieldMask);

							NodePtr newTransformNode = Node::create();

							beginEditCP(newTransformNode, Node::CoreFieldMask);
								newTransformNode->setCore(newTransform);
							endEditCP(newTransformNode, Node::CoreFieldMask);
							
							NodePtr pickedObjectParent = pickedObject->getParent();

							// add reference because reCount would be 0 and then it will
							// be deleted
							addRefCP(pickedObject);

							beginEditCP(pickedObjectParent);
								pickedObjectParent->replaceChildBy(pickedObject, newTransformNode);
							endEditCP(pickedObjectParent);

							beginEditCP(newTransformNode);
								newTransformNode->addChild(pickedObject);
							endEditCP(newTransformNode);
							
							// sub the reference which was added before
							subRefCP(pickedObject);

							_pickedObjectNode = newTransformNode;
						}
					}

					// a transformation was found and the objects bounding box is showed
					this->setHighlight(_pickedObjectNode);
				}
			}
			_navigator.buttonPress(Navigator::LEFT_MOUSE,x,y);
			break;

		case MouseMiddle: 
			_navigator.buttonPress(Navigator::MIDDLE_MOUSE,x,y);
			break;

		case MouseRight:
			// release picked object and switch off bounding box rendering
			if(_objectPicking)
			{
				_pickedObjectNode = NullFC;
				this->setHighlight(NullFC);
				#ifdef SPACENAVIGATOR_DEBUG_OUTPUT
					std::cout << "SpaceNavigatorSSM: Camera transformation mode active" << std::endl;
				#endif // SPACENAVIGATOR_DEBUG_OUTPUT
			}
			_navigator.buttonPress(Navigator::RIGHT_MOUSE,x,y);
			break;

		case MouseUp:     
			_navigator.buttonPress(Navigator::UP_MOUSE,x,y);
			break;

		case MouseDown:    
			_navigator.buttonPress(Navigator::DOWN_MOUSE,x,y);
			break;
		}

		_mousebuttons |= 1 << button;
		_lastx = x;
		_lasty = y;
//.........这里部分代码省略.........
开发者ID:ufz-vislab,项目名称:vislab,代码行数:101,代码来源:SpaceNavigatorSSM.cpp

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