Archived

This topic is now archived and is closed to further replies.

Jam0079

Problem with coordinate systyem

Recommended Posts

HI All, I am newbie to OpenGl. And i have a very "simple" doubt. I want the user to input the coordinates for drawing a sphere in pixel values ie draw_sphere(100(xpos),100(ypos),200(radius)) and i want my OpenGL program to convert it in open GL float values to draw at that position. How do i map these pixel values accurately to openGL coordinate systems float Value. Any help would be greately appreciated. Thanks In advance... Jam0079

Share this post


Link to post
Share on other sites
Opengl is independent of scale values, so 1 opengl unit can be anything you want. So if you specify a sphere of radius 10, opengl doesn''t care about the size so you can make it as small or as large as you want. Don''t do a conversion that makes it too small how since you''ll probably end up loosing perscision maybe 1.0f = 1 meter?

But i think want your asking is that if you click a point on the screen with the mouse and you want to create a sphere at that location in 3-space with a radius to where you release the drag for your mouse then what you want is to convert screen coordinates to world cooridnates. Since the points you have from your mouse are in screen coordiantes (2d) you have to convert them into 3d (called unprojecting, since 3d-to-2d is called a projection). So you can unproject the your initial mouse click point and the mouse point where you release the mouse button. Now you have 2 points in world space, where the first is the center of the sphere and the second is a point on the surface of the sphere (use the distance from these two points as your radius). The transformation that computes this unprojection can be computed using the ModelView matrix and ProjectionMatrix and the information about the viewport. You can simply derive this yourself (for optimizations) or you can use the GLU lib function gluUnproject and glGet* (to get the current model view and projection matricies). You''ll have to specify a depth for your point in screen corindates (this will map to the z component of unprojected point in world space). Zero will give you a z value at the camera, and 1.0f will give you a point at the far clipping plane. You might want the sphere to appear slightly infront of the camera so dont quite set the depth value to 0 (also note that the depth component grows non-linearly). I hope this helps.

Share this post


Link to post
Share on other sites