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
| void COpenGL::Mouse(int button, int state, int x, int y)
{
_mouseX = x;
_mouseY = y;
ctrl_pressed = false;
switch (glutGetModifiers()) // on détecte l'appuis sur CTRL ou SHIFT
{
case GLUT_ACTIVE_CTRL:
ctrl_pressed = true;
break;
}
if (state==GLUT_UP)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
{
xSelectedZone2=x;
ySelectedZone2=y;
if (ctrl_pressed)
{
double tmpx2=(xSelectedZone1+xSelectedZone2)/2;
double tmpy2=(ySelectedZone1+ySelectedZone2)/2;
//Calculer le rapport de zoom
double ss1 = window_x/(double)abs(xSelectedZone1-xSelectedZone2);
double ss2 = window_y/(double)abs(ySelectedZone1-ySelectedZone2);
scale=min(ss1,ss2);
}
glScaled(scale,scale,scale);
Transform2Dto3D(tmpx2, tmpy2, tx2, ty2, tz2);
Transform2Dto3D(tmpx1, tmpy1, tx1, ty1, tz1);
tx+=(tx2-tx1)*ss;
ty+=(ty2-ty1)*ss;
tz+=(tz2-tz1)*ss;
glTranslated(-tx, -ty, -tz);
glutPostRedisplay();
}
}
break;
}
}
else
{
switch (button)
{
case GLUT_LEFT_BUTTON:
{
xSelectedZone1=x;
ySelectedZone1=y;
}
break;
}
}
} |
Partager