How to translate a 3D object's position to 2D?

Started by elias4444, July 28, 2005, 16:15:00

Previous topic - Next topic

elias4444

I'm struggling trying to figure out how to translate a 3D objects position into it's 2D position and size on screen in order to allow someone to click the mouse on it and detect a collision. Am I overlooking something?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

tomb

You don't need to translate any positions. Read the "Selection and Feedback" chapter in the red book.

Orangy Tang

Selection buffer is a hack (and not a particularly fast one).

You can either transform your 2d click into a 3d ray and pick using that, or you can transform your 3d object onto the screen and see if it lies under the mouse. Which is better will depend on what you're using it for.

3d -> 2d can be done via gluProject. 2d -> 3d can be done with gluUnProjection. Although with unproject you typically want to use two points (at different depths) and construct a ray between them for collision testing.

elias4444

I have a feeling I'll be using the 2d-click-into-3d-ray method. Other than using some trigonometric math functions, is there a simpler way to do it?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com