Jump to content
  • Advertisement


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


3D space to 2D screen

This topic is 6155 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

Okay, I''m sure this is a dumb question, but I haven''t been able to figure it out yet. Here''s the setup: I''m using the basic method of screenX = (objectX / ObjectZ) + HALF_SCREEN_WIDTH screenY = (objectY / ObjectZ) + HALF_SCREEN_HEIGHT to project from the 3D world onto the 2D screen. How do I set up the world and the objects in it so that ObjectZ is never zero? I thought the way to simulate moving the camera about inside the world was to move the world about. So if I translate the objects in the world to simulate camera movement, how do I keep the Z values from being zero? Thanks anybody who can help me with this! -Snork "Get busy livin, or get busy dyin."

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Well, usually people build near and far planes to their camera. So if the z coordinate is too high or to low, you don''t draw the object (or you clip the object, if you want to be fancy.)

So just set your near clipping plane at something greater than 0, (assuming your camera is at 0) and you will be fine!

Share this post

Link to post
Share on other sites

First, you forgot something:

X'' = (X/Z) * D
Y'' = (y/Z) * D

Where D is the distance between the camera point
and your projection plane (screen).

You can figure out D as following:

D = (ScreenWidth / 2) / tan(FOVangle / 2)

FOVangle means how big your Field Of View is.
Most Engines have 90 degrees.
NOTE: Most Programming languages'' tan functions
expect the angle in radians.
Angle in rad = angle in deg * (pi/180)

You have to determine, which polygons have a coordinate
with z<=0. Your camera is moving in the world,
and there will be objects with negative or zero z-coords,
those are behind you!! (you cannot prevent that there
are objects behind you )

Don''t draw those polygons.
You have to test all polygons for that.
If not every z-coord of a polygon is <=0, you''ll have to
clip the polygon, into two parts, the one that is visible,
which you draw, and the one which is not visible, and which
you not draw.

Share this post

Link to post
Share on other sites
Sorry, with the 3d to 2d equations, i forgot
the + half_screenwidth, of course.

for Y you should use: Y'' = half_scrheight - (Y/Z)*D,
if you want positive values beeing on upper side of the screen,
and negative ones lower.

Share this post

Link to post
Share on other sites
Why do I always remember things AFTER pressing
the "send" button...

NOTE: DO NOT use different D values for X and Y,
use the same. Of course, the Distance of your
projection plane to view point is the same for
X and Y :-)

(I say this, because I saw some guys doing nonsense
like that, it looks ugly, and is incorrect, of course...)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!