open inventor 碰撞检测


利用open inventor Coin3D中自带的Intersections 类实现两个物体之间的碰撞检测
资源截图
代码片段和文件信息

// 添加COIN头文件-Window操作显示库和节点库   
#include    
#include 
#include 
#include 
#include 
#include    
#include 
#include 
#include    
#include   
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


SoIntersectionDetectionAction::Resp onIntersection(void *userDataconst 

SoIntersectingPrimitive *primitive1const SoIntersectingPrimitive *primitive2)
{
// These two primitive have an intersection.
  (void)fprintf(stdout “intersection hit!/n“);  

// This callback will be called for the two next colliding shapes
  return SoIntersectionDetectionAction::NEXT_SHAPE;
}

static void alarmCB(void * data SoSensor *sensor)  //响应函数
{
   
SoWin::exitMainLoop(); 


//重新调度警报传感器
SoAlarmSensor *alarm=(SoAlarmSensor*)sensor;
alarm->setTimeFromNow(0.022);
alarm->schedule();
}


int main(int argc char **argv)  
{  
    SoDB::init();                                       // 初始化SoDB读取iv文件   
    HWND hWnd = SoWin::init(argv[0]);   // 产生窗口句柄   
    SoSeparator *pRootSeparator = new SoSeparator;  
    pRootSeparator->ref();                       // 创建根节点并ref计数   
    
//SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
    SoPendulum *myPend = new SoPendulum;
    myPend->rotation0.setValue(SbVec3f(001)0);
    myPend->rotation1.setValue(SbVec3f(001)-1);
    myPend->speed=0.2f;

    
    SoInput input;  
    if (input.openFile(“finger002.iv“))                    // 加载iv文件并读取全部内容   
    {  
        pRootSeparator->addChild(SoDB::readAll(&input));  
    }  
    //子节点1
    SoSeparator *pSon1Separator = new SoSeparator; 
    SoPendulum *mySon1Pend = new SoPendulum;
    pRootSeparator->addChild(pSon1Separator);
    
SoTransform *mySon1Tform=new SoTransform;
    pSon1Separator->addChild(mySon1Tform);
mySon1Tform->translation.setValue(0.04f 0.0 0.00);
    pSon1Separator->addChild(mySon1Pend);
    mySon1Pend->rotation0.setValue(SbVec3f(001)0);
    mySon1Pend->rotation1.setValue(SbVec3f(001)-1.0);
    mySon1Pend->speed=0.2;

    if (input.openFile(“finger001.iv“))                    // 加载iv文件并读取全部内容   
    {  
        pSon1Separator->addChild(SoDB::readAll(&input));  
    }  
   


    SoSeparator *sphere=new SoSeparator;
pRootSeparator->addChild

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-10-08 09:13  碰撞
     目录           0  2013-10-08 09:13  碰撞Debug
     文件     2573312  2013-10-08 09:11  碰撞Debug est.bsc
     文件      221234  2013-10-08 09:11  碰撞Debug est.exe
     文件      412688  2013-10-08 09:11  碰撞Debug est.ilk
     文件       43428  2013-10-08 09:11  碰撞Debug est.obj
     文件     5663172  2013-10-07 20:01  碰撞Debug est.pch
     文件      738304  2013-10-08 09:11  碰撞Debug est.pdb
     文件           0  2013-10-08 09:11  碰撞Debug est.sbr
     文件      525312  2013-10-08 09:13  碰撞Debugvc60.idb
     文件      372736  2013-10-08 09:11  碰撞Debugvc60.pdb
     文件      477791  2013-09-07 17:02  碰撞finger001.iv
     文件      319532  2013-09-07 17:01  碰撞finger002.iv
     文件        4251  2013-10-08 09:11  碰撞 est.cpp
     文件        4229  2013-09-08 23:04  碰撞 est.dsp
     文件         531  2013-05-04 10:26  碰撞 est.dsw
     文件       66560  2013-10-08 09:13  碰撞 est.ncb
     文件       54784  2013-10-08 09:13  碰撞 est.opt
     文件         242  2013-10-08 09:13  碰撞 est.plg

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)