1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Group> modele3D =
dynamic_cast<osg::Group*>(osgDB::readNodeFile("boule_repere.obj")); //boule
osg::ref_ptr<osg::Group> modele3DD =
dynamic_cast<osg::Group*>(osgDB::readNodeFile("boule_repere.obj"));
HDdouble pos[3];
hdGetDoublev(HD_CURRENT_POSITION,pos);//position de l'interface haptique
osg::PositionAttitudeTransform* movingPAT = new osg::PositionAttitudeTransform;
movingPAT->setPosition( osg::Vec3d(pos[0]/10,-pos[2]/10,pos[1]/10 )); //associer les positions de l'interface haptique a la boule
movingPAT->addChild(modele3D.get());
root->addChild(movingPAT);
MovableObject* movingObject = new MovableObject(modele3D.get(), movingPAT);//crée un objet de la classe MovableObject
////////creation de l'objet statique
osg::PositionAttitudeTransform* stationaryPAT = new osg::PositionAttitudeTransform;
const osg::BoundingSphere& bb2=modele3DD->getBound();
stationaryPAT->addChild(modele3DD.get());
root->addChild(stationaryPAT);
MovableObject* stationaryObject = new MovableObject(modele3DD.get(), stationaryPAT);
////////// la partie ajouter
osg::PositionAttitudeTransform* tempPAT = new osg::PositionAttitudeTransform;
tempPAT->setPosition( osg::Vec3d(pos[0]/10,-pos[2]/10,pos[1]/10 ));
MovableObject* temp = new MovableObject(modele3D.get(),tempPAT);
//////////
osgViewer::Viewer viewer;
viewer.setUpViewInWindow( 100,100, 512, 512 );
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.setSceneData(root);
viewer.realize();
while( !viewer.done() )
{
viewer.frame();
HDdouble pos[3];
hdGetDoublev(HD_CURRENT_POSITION,pos);
osg::PositionAttitudeTransform* tempPAT = new osg::PositionAttitudeTransform;
tempPAT->setPosition( osg::Vec3d(pos[0]/10,-pos[2]/10,pos[1]/10 ));
tempPAT->addChild(modele3D);
MovableObject* temp = new MovableObject(modele3D.get(),tempPAT);//crée un objet de la classe MovableObject
///teste de collision//// je teste temp non pas movableObject comme je faisais
if( temp->collidesWith(stationaryObject) )
{
//cout<<"collision boooooooooooooooooom"<<endl;
compt=1;
}
else{
//cout<<"pas de collision "<<endl;
compt=0;
}
if(compt==1)
{
MovableObject* movingObject = new MovableObject(modele3D.get(), movingPAT);
}
else
{
movingPAT->setPosition( osg::Vec3d(pos[0]/10,-pos[2]/10,pos[1]/10 ));
MovableObject* movingObject = new MovableObject(modele3D.get(),movingPAT);
}
}
} |
Partager