LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on July 28, 2005, 16:15:00

Title: How to translate a 3D object's position to 2D?
Post by: elias4444 on July 28, 2005, 16:15:00
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?
Title: How to translate a 3D object's position to 2D?
Post by: tomb on July 28, 2005, 19:37:11
You don't need to translate any positions. Read the "Selection and Feedback" chapter in the red book.
Title: How to translate a 3D object's position to 2D?
Post by: Orangy Tang on July 28, 2005, 20:21:47
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.
Title: How to translate a 3D object's position to 2D?
Post by: elias4444 on July 28, 2005, 20:27:52
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?