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
|
SbVec3f * Pick :: ivEvent_PointByMouse(void *userData, SoEventCallback *eventCB)
//===========================================================
// Fonction qui capture une mesure de distance a la souris
{
static SbVec3f *XYZ1=NULL;
SbVec3f *XYZ2=NULL;
SoSeparator *root = (SoSeparator *) userData;
const SoEvent *event = eventCB->getEvent();
// Check for mouse button being pressed
if (SO_MOUSE_PRESS_EVENT(event, ANY)) {
// Fenetre dans laquelle a ete fait le clique
const SbViewportRegion &myRegion =
eventCB->getAction()->getViewportRegion();
// SbVec3f *XYZ1=GetPointXYZ(root, myRegion,
XYZ1=GetPointXYZ(root, myRegion,
event->getPosition(myRegion));
if ( XYZ1 != NULL ){
// float x,y,z;
// XYZ1->getValue(x,y,z);
// printf("Premier point est : %f %f %f\n",x,y,z);
eventCB->grabEvents(); // on capture tous les evenements
} else eventCB->setHandled(); // ON abandonne...
}
// Pour faire une mesure de distance on teste un autre evenement :
if (SO_MOUSE_RELEASE_EVENT(event, ANY)) {
const SbViewportRegion &myRegion =
eventCB->getAction()->getViewportRegion();
// SbVec3f *XYZ2=GetPointXYZ(root, myRegion,
XYZ2=GetPointXYZ(root, myRegion,
event->getPosition(myRegion));
eventCB->releaseEvents();
eventCB->setHandled(); //testtttt
// Si la distance entre les 2 points est trop faible
const float EPSILON=1.e-5; // il faut le calculer en % de la fenetre ecran
// on ne renvoi les coordonnees du point
// sinon la distance entre les 2
if (( XYZ1 != NULL ) && (XYZ2 != NULL)){
// XYZ1 != NULL normalement
SbVec3f V ;
V=(*XYZ2)-(*XYZ1);
d=V.length();
if (d > EPSILON ) {
// printf("Distance entre les points : %f\n",d);
} else {
float x,y,z;
return XYZ2 ;
// XYZ2->getValue(x,y,z); // Comment ca marche ?
// printf(" XYZ= %f %f %f\n",x,y,z);
}
}
}
} |
Partager