#### Archived

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.

## 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 on other sites
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 on other sites

First, you forgot something:

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

Where D is the distance between the camera point

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

1. 1
2. 2
Rutin
22
3. 3
4. 4
5. 5
frob
12

• 17
• 9
• 31
• 16
• 9
• ### Forum Statistics

• Total Topics
632615
• Total Posts
3007441

×