PDA

View Full Version : how can I translate 3d coordinate to 2d(x,y) coord



dyahav
10-11-2002, 07:13 AM
hi
Im looking for an algorithem to calculate x,y,z to x,y coordinate on screen
thank

Gavin
10-11-2002, 07:20 AM
gluUnproject

jubei_GL
10-11-2002, 07:20 AM
well how about omiting the Z value in (x,y,z) ? If you want to look at 3D space from 2D perspective, you will look at X and Y, thus no matter where in Z coordinate the 3D shapes lie, since you will see them from the Side ... Other than that I don't understand what you really want to accomplish ..

[This message has been edited by jubei_GL (edited 10-11-2002).]

bumby
10-11-2002, 09:55 AM
but wouldnt you need to have an orthographic projection? Otherwise, the x any y coords may not be the correct values that you are looking for.


J

10-12-2002, 02:33 AM
I'm developing a 3D shooting game... is there anyway to translate a 2D(x,y) coordinate (Mouse click) into 3D?

Bob
10-12-2002, 02:49 AM
You can't transform a 2D point to 3D. It's an equation system with three equations and two unknowns: impossible to find a unique solution. What you CAN find is a line from the viepwoint throught the "mouse cursor". You can have a look at gluUnProject, but you will see it requires a third component from the mouse cursor to give you a unique point in 3D space.

nomad82
10-12-2002, 04:17 AM
err...guys, i think what he's asking is how to calculate where on the screen an (x,y,z) vertex will be shown (which is an x,y)...

try searching for "Denthor of Asphyxia" tutorials, then look for the one with introduction to 3D...you'll find your equation there...

if i remember correctly when i dealt with DOS graphics, it's:

x_screen = x_coord / z_coord * 256
y_screen = y_coord / z_coord * 256

with the 256 being a "trial and error" value... http://www.opengl.org/discussion_boards/ubb/wink.gif.

---------------------------------------
Visit Me: http://nomad.openglforums.com

10-12-2002, 05:33 AM
Can't I just specify the z? I tried gluUnproject, but, I can't seem to read the
GL_MODELVIEW_MATRIX,GL_PROJECTION_MATRIX, GL_VIEWPORT...

10-12-2002, 05:34 AM
how do yoo find a line from the viewport thru the cursor anyway?

Bob
10-12-2002, 05:44 AM
Use gluUnProject two times with winz set to 0 and 1 (in fact, any two values in thew range [0, 1] will do, as long as they are not the same). Then you have two points in space, and you can form a line between them.

EPHERE
10-12-2002, 07:56 AM
Have you considered simply making a subroutine that would calculate a 3x4 projective matrix based on your camera's rigid displacement and basic intrinsic parameters? Then all you'd have to do is multiply the 3x4 projective matrix P by your (x,y,z,1) point as a projective vector. Getting the (u,v,s) result your x=u/s and y=v/s. And vice versa to get 3d coordinates of point at infinity (projective line)(x,y,z,0) just multiply the inverse of P by (u,v,s).

I have implemented this fundamental technique many times because it can work with an indefinite amount of cameras at the same time.

[This message has been edited by EPHERE (edited 10-12-2002).]