hii
i have problem to drag/move a rectangle using mouse click…
heres my codes…my codes can draw a rectangle using mouse event,display the rectangle coordinates and when user click could determine whether the coordinates is inside or outside the rectangle border…
now im stuck at how to move/drag the rectangle when user click inside the border.
Thanks in advance…
void myMotion(int x, int y)
{
corner[1].x = x;
corner[1].y = windowHeight - y;
corner[2].x = x;
corner[2].y = windowHeight - y;
corner[3].x = corner[0].x;
corner[3].y = corner[0].y;
glClear(GL_COLOR_BUFFER_BIT);
glRecti( corner[0].x, corner[0].y, corner[1].x, corner[1].y);
printf("%3d %3d , %3d %3d
", corner[0].x, corner[0].y, corner[1].x, corner[1].y);
glFlush();
}
void myMouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
corner[0].x = x;
corner[0].y = windowHeight - y;
corner[1].x = corner[0].x;
corner[1].y = corner[0].y;
printf("%3d %3d
", corner[0].x, corner[0].y);
if(corner[0].x >=corner[3].x && corner[0].x <= corner[2].x && corner[0].y <=corner[3].y && corner[0].y >=corner[2].y)
{
printf("Yup, the point is inside the boundary
");
}
else
{
printf("Sorry…the point is outside the boundary
");
}
}
}