Archived

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

Converting x,y,z coordinates to x,y coordinates

This topic is 6078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a simple mathematical formula that converts x,y,z coordinates to x,y coordinates? I read somewhere that the formula was: X=x/z Y=y/z I tried that, but I didn''t seem to work. I don''t want the code for a whole 3d engine, just that formula. I would be thankfull for any help!

Share this post


Link to post
Share on other sites
pseudo code for some basic 3d projection...

x = (Xwidth/2) + x*256 / (256 - z);
y = (Yheight/2) + y*256 / (256 - z);

check books for more info....

Share this post


Link to post
Share on other sites
cyer:
I am very curious about your formulas. Well, especially those 256 seems to be a speed-hack.

Well, I use a different formula, that supposes that you have a lefthanded coordinate system, x pointing to the right, y up and z away from you and a screen system that stores x right and y down, and the screen has width Xwidth and height Yheight.
Let me say your x-FOV (field of Vision) is v (in degrees):
X = (Xwidth/2) + x * (tan(v/2)*XWidth/2) / z
Y = (Yheight/2) - y * (tan(v/2)*XWidth/2) / z

where tan(v/2)*XWidth/2 is constant for one frame and should thus be precalculated at frame start (changing v from frame to frame can result in the camera-trick seen in Karpov, and some horror movies).

I am not quite sure whether I got the formula correct, but you may find it out yourself, when drawing it on paper (solve it for 2D (x,z) and (y,z))

Share this post


Link to post
Share on other sites