OpenGL Cords for Mouse

Abyssal
Unregistered
 
Post: #1
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

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!
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
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

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #3
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

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
What I put there was wrong. oops! Blush

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 131
Joined: 2004.10
Post: #5
Alternatively you may want to look at gluProject() and gluUnProject().
Quote this message in a reply
Post Reply