how can I translate 3d coordinate to 2d(x,y) coord

hi
Im looking for an algorithem to calculate x,y,z to x,y coordinate on screen
thank

gluUnproject

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).]

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

I’m developing a 3D shooting game… is there anyway to translate a 2D(x,y) coordinate (Mouse click) into 3D?

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.

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… .


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

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…

how do yoo find a line from the viewport thru the cursor anyway?

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.

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).]