Jump to content
  • Advertisement
Sign in to follow this  
beebs1

2D/3D Projection?

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

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!