|
我使用osgbullet里面的demo中collision代码做了下修改,主要移植到自己代码中并没有修改重要的部分,但是,实际的碰撞检测中两个物体在很远的距离便已经没检测到碰撞,这个是什么问题呢?
//create collisionshape
root->addChild(marker_geode_1);
这个是不动的模型
btCollisionObject* marker_collision_1 = new btCollisionObject;
marker_collision_1->setCollisionShape( osgbCollision::btBoxCollisionShapeFromOSG(marker_geode_1 ) );
marker_collision_1->setCollisionFlags( btCollisionObject::CF_STATIC_OBJECT );
cw->addCollisionObject( marker_collision_1 );
这个是随着鼠标移动的,基本是按照例子代码来改的
osg::Matrix transMatrix = osg::Matrix::translate( 0., 0., 0. );
osg::MatrixTransform* mt = new osg::MatrixTransform( transMatrix );
mt->addChild(marker_geode_2);
root->addChild(mt);
btCollisionObject* marker_collision_2 = new btCollisionObject;
marker_collision_2->setCollisionShape( osgbCollision::btBoxCollisionShapeFromOSG(marker_geode_2 ) );
marker_collision_2->setCollisionFlags( btCollisionObject::CF_STATIC_OBJECT );
marker_collision_2->setWorldTransform(osgbCollision::asBtTransform( transMatrix ));
cw->addCollisionObject( marker_collision_2 );
mm->setCollisionObject( marker_collision_2 );
mm->setMatrixTransform( mt );
viewer.setUpViewInWindow( 10, 30, 800, 600 );
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
viewer.addEventHandler( mm );
viewer.setSceneData(root.get());
root->setName("Root");
viewer.realize();
bool lastColState = false;
while( !viewer.done() )
{
cw->performDiscreteCollisionDetection();
vc->detectCollision( lastColState, cw );
viewer.frame();
} |
|