points and relations

Started by
0 comments, last by Zakwayda 18 years ago
I would like to create a program that would allow the user to click a point in the window and have a rectangle appear there (the top right of the rectangle starting EXACTLY at the point). I have been using the nehe basecode with glut. Using this I can send 2 >integer< values to a mouse structure using 'glutMouseFunc(glutMouse);'. Unfortunately, the cartisian plane for the mouse coordinates starts at the top left, and increments by the pixel. The openGL plane starts at the center of the window, and I have been unable to come up with a mathmatical formula that would allow me to use the mouse coordinates as GLfloats in a vertex, so that my square could start exactly where the mouse was clicked. My question is, how can I convert those values into GLfloats that would work within a vertex to allow me to start an object from that exact location, or send me in the right direction. Any easier way or alternative method would also be helpful. For Example: If this was the screen --------------------- // The mouse will give me output like that |(1,1) (2,1) (3,1) | |(1,2) (2,2) (3,2) | |(1,3) (2,3) (3,3) | -------------------- In openGL --------------------- // Open gl uses a cartisian plain like that |(-1,1) (0,1) (1,1) | |(-1,0) (0,0) (1,0) | |(-1,-1)(0,-1)(1,-1)| -------------------- I translate the screen back by a factor of -10.0f so that I can see all the objects on the screen. My screen resolution is 1024x768 Using window width and height, how can I calculate float value of the pixel. For example a window 800 pixels wide and high, all edges would be approximately 5.5f from the middle. So if I clicked at 600x and 600y, that would translate to approximately x: 2.7f and y: -2.7f. Using the zoom, and the size of the window is there anyway I can change mouse coordinates to openGL floats? [Edited by - viper161616 on April 12, 2006 11:05:08 PM]
Advertisement
Careful about cross-posting. Anyway, I'll go try and post an answer to your other thread, here.

This topic is closed to new replies.

Advertisement