converting cursor pos to opengl double coordinate for engine

Im making what started off as a 3d game and decided to have a development mode built in where a 3d world could be developed in the game in a cad like manner to create custom rooms, buildings, walls, ect.
But
my stumbling block is in GetCursorPos(). That returns a pixel value that starts
from the top left corner. However opengl starts from the center and goes negative or ositive...not just positive.

its going to be hard to manipulate objects in the z-axis since getcrspos only returns the mouses ortho x and y coordinates though. my result is that when i try to draw 3d objects in the 3d world the coordinates do
not show up as the x and y pos of the mouse is large and only positive. I'm gonna
have to convert it based on width and height of screen in pixels and the current camera position (or inverse world position). That seems simple enough except cursorpos varies based on window size and location on the screen. Im most likely going to make it a full screen application (which would solve my problem). But i need to figure out how wide my screen is in opengl doubles in order to convert the mouse coordinates to opengl double.

I played a game at walmart on ps3 and it would allow you to calibrate the picture to your custom screen size by moving yellow lines to the edge of the screen and figured i would do the same in my game/development environment.

my screen is 1366 X 768 pixel. Dividing both those numbers by 2 would give me
the center coordinate but not be opengl compatible. anywho dividing 683 by double value where vertical line was at edge of screen would give me a decimal double value per pixel. So i could just multiply the pixel coordinate by this decimal value ratio to convert it to opengl compatible double correct? Then make this value positive or negative depending on which quadrant the mouse is in when it is converted...correct? Then change the pixel:double decimal ratio based on z value. Farther back objects are being placed the more double value per pixel. z value to have it as close to user as possible without going out of view would be near clipping
plane +0.01. so Z = nearClippingPlane +0.01;

but when curspos.x = 0; the opengl double value is going to be a larger - double value. So how would i convert the 0 position on up. im guessing i should multiply the double value of the left side of the screen from center by 2 to find the double value of the width of the screen.
i needa get this figured out. any help is appreciated.

nvrmind i figured it out. Say -3.0 represents the left edge of screen in opengl double value. we know then that 3.0 would equal the right edge of the screen. So as curspos.x>=0 for every pixel value i multiply it by the double decimal value then add it to -3.0. so as you move mouse towards 683 (mouse center) -3.0 gets closer to (0.0 opengl center). as you move past 683 it gets larger until you reach edge of screen meaning 0.0 (opengl center) gets larger until it reaches 3.0 (opengl right side of screen). Then to make sure my object is placed accurately in 3d world i will find current camera position. then use that to determine my opengl left, top, right and bottom screen values. So if screen is 6.0 double wide in opengl and xpos in 3d world is -50.0 double left side of screen would equal -53.0 and right side would equal -47.0. This way when i place object (wall, door, ect) it will show up in correct coordinate of screen and 3d world coordinate.


does anybody know a better way to do this.

.
Last edited on
Topic archived. No new replies allowed.