views:

182

answers:

2

Say I have a 3D object's position, and the camera's location and rotation matrix.

How, would I go about converting this to a 2 Dimensional position on the screen? So that I could draw over the 3D object?

You see, I'm using an engine that only allows 3D Env + 2D Gui, so I can't do my normal approach of drawing in 3D, but scaled up.

I need the X/Y positions of the objects on the 2D plane.

In lua, by the way, but that don't really matter, as I could possibly convert the math to lua if needed.

Thanks peeps, SilentC

+3  A: 

Mathematically this is called Projection...

Googling for that finds interesting algorithms, and implementations...

John Weldon
+2  A: 

You also need the field of view of your camera.

Let's say north is up on your 2d projection. From your boresight (the line along the optical axis) you'll sweep with a north/south component and an east-west component. These angles relate to the pixel position in your plane:

X/tan(A) = x/tan(a)

where X and x are measured from the center pixel, A is the field of view (or half of it) in radians, and a is the deviation in the x direction in radians.

Same for the Y direction.

For a rotation around from north, you'll need to rotate the points in your plane.

Something like that, anyway. ;)

John at CashCommons
Would it be possible to calculate the FOV if I had the focus as well as the position of the cam?
You can calculate FOV in the context of a particular film size, but not by itself.
John at CashCommons