OpenGL Cords for Mouse
I have just started working with mac programming and OpenGL, I picked up the redbook and I am making progress with a little demo program to pratice my skills on. I kind of hit a dead end though. Im trying to convert the mouse cords from the screen location into OpenGL.
Im using
To get the mouse cords, but I was looking at an easy way to convert that to my Ortho view, the main problem im having is depending on the user resizing the window or the screen resolution changing I get diffrent points at the edges of the screen which dont seem to match up with the current resolution.
I did find an article about apply a "drawing matrix" to my points to get the OpenGL points, but like i said i am very new to this and I dont know how to do that.
Am I missing something because it seems that there would be an easy function to do this as almost every game requires mouse input of some kind? Any suggestions or code snippets?
Thanks!
Im using
Quote: GetPort(&oldPort);
SetPort(gGameWindowGrafPtr);
GetMouse(&pt);
SetPort(oldPort);
x = pt.h;
y = pt.v;
To get the mouse cords, but I was looking at an easy way to convert that to my Ortho view, the main problem im having is depending on the user resizing the window or the screen resolution changing I get diffrent points at the edges of the screen which dont seem to match up with the current resolution.
I did find an article about apply a "drawing matrix" to my points to get the OpenGL points, but like i said i am very new to this and I dont know how to do that.
Am I missing something because it seems that there would be an easy function to do this as almost every game requires mouse input of some kind? Any suggestions or code snippets?
Thanks!
what is x, y. Is this mouse coords relative to the screen, if so you need to know the window position.
Then you can convert it to windows coords, by scaling it from the size of the window to the size of the ortho view, somthing like this:
x = x*screen_width/window_width
Then you can convert it to windows coords, by scaling it from the size of the window to the size of the ortho view, somthing like this:
x = x*screen_width/window_width
Sir, e^iπ + 1 = 0, hence God exists; reply!
Try
OpenGL_X_CORD = ((pt.v/Screen_res_x))*Your_Window_SizeX;
OpenGL_Y_CORD = ((pt.h/Screen_res_y))*Your_Window_SizeY;
Thats how I do it atleast
OpenGL_X_CORD = ((pt.v/Screen_res_x))*Your_Window_SizeX;
OpenGL_Y_CORD = ((pt.h/Screen_res_y))*Your_Window_SizeY;
Thats how I do it atleast
What I put there was wrong. oops!
Sir, e^iπ + 1 = 0, hence God exists; reply!
Alternatively you may want to look at gluProject() and gluUnProject().

