mouse

Started by
2 comments, last by tomsh 12 years, 6 months ago
I tried to drew a square in the mouse position.
I got from the wndproc the position of the mouse.
the problam that my room's size is (640,480)
and the ogl room is (13.0f, 13.0f).

so when I got from the windows the position of the mouse I can't use it in the OpenGl room...


to fix the problem I tried this code:
xPos = xPos/(640.0f/13.0f)-6.5f;
yPos = -yPos/(480.0f/13.0f) +6.5f;




Now it works, the square is in the position mouse...
but it has a litlle [font="Arial,"]deviation.[/font][font="Arial,"]..[/font]
[font="Arial,"] [/font]
[font="Arial,"]as the mouse closer to the edge of the window, the deviation became bigger...[/font]
[font="Arial,"]In the middle of the window, it doesn't have deviation...[/font]
[font="Arial,"] [/font]
[font="Arial,"]someone know what's wrong with my code?[/font]
[font="Arial,"]know other way to do it?[/font]
[font="Arial,"] [/font]
[font="Arial,"]thanks a lot[/font]
[font="Arial,"]
[/font]
Advertisement
Whats the "room"? is it the window size? I think the titlebar sometimes gets included in the height. Does this deviation occur on both axis(up/down, left/right) or only up/down. If its just up/down then it might be the titlebars height. You could then account for that (subtracting it from your height (480).

You could also change the projection to be more appropriate - instead of being 13/13 it could be 640/480.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Did you try using gluUnProject()?
room, I mean the rendering size I don't know what it's name...

here:
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -13.0f);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POLYGON); //create polygon
glVertex3f( xPos-0.6, yPos-0.5, 0.0f); //down left
glVertex3f( xPos-0.6, yPos+1.5, 0.0f); //up left
glVertex3f( xPos+0.6, yPos+1.5, 0.0f); //up right
glVertex3f( xPos+0.6, yPos-0.5, 0.0f); //down right
glEnd();

because the gltransltef,
when I write the -13.0f
it maked the room 13.0f*13.0f
that what I mean is room size...

[color="#1C2837"]gluUnProject()
[color="#1C2837"]I don't understand how to use this function...
[color="#1C2837"]can you give an exmpale?
[color="#1C2837"]
[color="#1c2837"]and it's happand in all the 4 sizes

This topic is closed to new replies.

Advertisement