PDA

View Full Version : passing coordinates from mouse clicks



Jaymz
09-17-2011, 01:10 PM
so I have this mouse(click,state,x,y) function that generates coordinates for each click, and I want to pass some clicks to another function that for example draws a polygon using those coordinates. how do I do this ? create new points in the mouse function, or is there some other way to pass along these click coordinates ?

-Mil0-
09-18-2011, 03:04 PM
so I have this mouse(click,state,x,y) function that generates coordinates for each click, and I want to pass some clicks to another function that for example draws a polygon using those coordinates. how do I do this ? create new points in the mouse function, or is there some other way to pass along these click coordinates ?

Draws the polygon where?

If you were just looking to draw in the top-down view, you have to derive OpenGL coordinates from your mouse coordinates.

So, if you have a 640x480 viewport, where the origin is at the top left corner of the screen, you have to create a function that maps 0:640 to -1.0:1.0 and 0:480 to 1.0:-1.0:



gl_vert = toGlVert(mouse_xy); // You write this function
// gl_vert: [mouse.x, mouse.y, 0.0f, 1.0f]


And then you just send a collection of those verts to the GPU, in a VBO, as you usually would.