Public Group

# 2D/3D Projection?

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

## Recommended Posts

Hiya,

I'd like to draw some 2D markers on objects in 3D space. I have no problems doing the actual drawing, but I'm unsure of a way to calculate a 2D coordinate given a 3D position, camera position and camera orientation.

Does anyone know how to do this?

Many thanks.

##### Share on other sites

Hiya,

I'd like to draw some 2D markers on objects in 3D space. I have no problems doing the actual drawing, but I'm unsure of a way to calculate a 2D coordinate given a 3D position, camera position and camera orientation.

Does anyone know how to do this?

Many thanks.

The exact way to do this will depend on what system you are using but if you are using custom shaders you should be able to understand this. In the vertex shader you multiply the input position with the world, view, and projections matrices. This results in a (-1, 1) screen coordinate which is used to point to the pixel that will be rendered Taking this away from shaders you can use (most likely built-in) vector transformation functions in order to transform (using those same matrices) the 3d position of your object into a coord (-1, 1) that you can then adjust by expanding it to the (0, width or height) region to find the proper pixel on your screen.

If you don't understand this, just give some more details about the framework/API (XNA, DirectX, OpenGL) and we'll be able to give you more help.

Hope this helps a little.
-BiT

##### Share on other sites
Thanks, that was quick!

I'm using OpenGL / fixed-function.

I think I see what you mean - it's pushing the point through the render pipeline transforms to get the final positiion.

Thanks

##### Share on other sites
Just make sure once you do your transforms, that you divide your x and y by the w value. This will ensure a correct value in the range of -1 to 1 for both, then just expand.

Good luck
-BiT

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 23
• 11
• 25