I’m trying to dragg a rectangle in a condition that tha mouse pointer is inside that rectangle …

I drew the rectangle using
glRectf(px1,py1,px2,py2)…

the coordinates of the rectangle are (0,-65,20,-70);

The problem that when I click INSIDE the rectangle and get back the value of x & y using the glutMouse function , I found that the values of x & y CAN’T be inside the rectangle ( something like 209, 361 ) eventhough I was pressing inside that rectangle !!!

Mouse coordinates have nothing to do with the coordinates of the rectangle, on most platforms the mouse coordinates has their origin in the upper left corner and maps 1:1 to the device resolution.

The rectangle coordinates depends on your modeview matrix setup, if you do want to map them to mouse coordinates have a peek at the faq on this website (transformations section), there is an example on how to setup the modelview matrix to match the device resolution (with a flipped Y axis).

I’m really not familiar on what you have said a bout mapping the modelview to match the device resolution eventhough I will look in the transformations section …

I wonder if there is other method to make sure that the mouse click is inside the rectangle … ??

I think ur problem is that u r not converting the mouse coordinates from window co-ordinate system to rectangle coordinate system.

Based on the code u posted for the previous problem, I think ur doing lots of projection and modelview transformations, and then render the rectangle, so u have to take care of those for mouse co-oridnates also.

Originally posted by virtualchetan:
[b]I think ur problem is that u r not converting the mouse coordinates from window co-ordinate system to rectangle coordinate system.

Chetan[/b]

Hello Chetan …

How can I do that … I.e, convert the mouse coordinate from window to rectangle coordinate system ???

I tried to apply the projection and modelview transformations I did to glut mouse function and I get no result I mean there is still big different between the two system coordinate …

// Mouse_x/y tells us where in openGL units the mouse was clicked.

}

// My reshape routine
void reshape_1 (int w, int h)
{
Win_x = w; // Get new value of windows witdh when window size change
Win_y = h; // Get new value of hight
glViewport (0, 0, (GLsizei) w, (GLsizei) h); // Tell openGL the new window size
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
}

[This message has been edited by nexusone (edited 12-02-2003).]

The problem is you did not copy my code correctly, there is an error in your reshape routine.

Also if you like I can e-mail you a example drawing program I wrote, just drop me a e-mail.

See corrections below

Here is my reshape function :
void myGlutReshape( int x, int y )
{
int tx, ty, tw, th; //
Winx= tw; <----error you set Winx to zero every call here…
Winy= th;
// Correct code
Winx = x;
Winy = y;

// tx, ty, tw, th; all have zero until this is called
GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
glViewport( tx, ty, tw, th );

// xy_aspect = (float)tw / (float)th;

glutPostRedisplay();
}

I beleived my world is between ( -80,-80, 80,80) and my viewport is 600 × 600 .

Thank you in advance

[This message has been edited by nexusone (edited 12-04-2003).]

the problem still there even I changed what you tell me to change …I beleive it give me a zero somewhere in the second part of the equation here … x = -80 + 160 * ( x/ Winx) … because the value of x remains -80 always the same happened to y…

I checked the value of intial x … it’s not zero , Winx also not zero … but the value of x after the equation is always -80 !!!

Originally posted by glcrazy: I did as you mentioned ( … *0.1). It changed the values of x&y but not in the right way … !!

Well, I told you to use 1.0*x to force the C compiler to do the division in double precision. You could use ((double)x) too… NOT *0.1 .
Of course, 0.1 will change your values in a wrong way… Maybe a typo ?