1

Possible Duplicate:
Mapping coordinates from plane given by normal vector to XY plane

How is it possible to get the screen position of a dot, which is located in the 3D space?

The position of the camera is 0,0,0 and it isn't rotated.

Community
  • 1
  • 1
Hard Rain
  • 1,380
  • 4
  • 14
  • 19

1 Answers1

3

Depends on your type of projection.

A standard perspective projection is:

x' = (centre of viewport) - (half width of viewport) * x/z
y' = (centre of viewport) - (half height of viewport) * y/z

That'll give your a 90 degree field of view in both directions and assume you're looking from (0, 0, 0) along z.

It's normal to scale the geometry prior to projection to deal with the fact that the viewport isn't often square. You'll also notice that the results are undefined when z is 0 and will become problematic as z tends towards 0. It also maps both positive and negative z to screen when one of them should be behind the camera. Normally you'd trim geometry (or discard points) with z less than a certain threshold.

In terms of dots, also notice that (assuming you're keeping positive z) if abs(x) > z or abs(y) > z then the dot is offscreen. If you move on to full geometry then you can use that observation to clip it at the screen edges, saving per-pixel tests.

Tommy
  • 99,986
  • 12
  • 185
  • 204