Hello Guest

Getting the 2d screen coverage of a 3d object

  • 1 Replies
  • 3212 Views
Getting the 2d screen coverage of a 3d object
« on: October 07, 2013, 17:19:28 »
Though this is for a specific question for something I am coding, I will ask it in a broader term for the help of others.

How do I find the polygon outline of an object in lwjgl. So lets say I have a cube drawn in 3d. How do I know if the mouse cerser (or the screen center) is aimed at that block. For example, how does minecraft know which block you are aiming at. Or how does World of Tanks know that your sight is aimed over an enemy tank (A 3d polygon in the distance).

Thanks in advanced for any answers!

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Getting the 2d screen coverage of a 3d object
« Reply #1 on: October 07, 2013, 17:37:15 »
What those games would do is to transform the cursor position into object space, where you can test collision. In 2D (as in side-scrolling) its simple - just the x, y translation of the camera added to the cursor's position on screen. In 3D (first person camera) it's a ray starting at the player's position (the same as the camera pos) and continuing along the "forward" vector of the camera.

http://lwjgl.org/forum/index.php/topic,5194.0/topicseen.html this topic is asking essentially the same question as you and hase some more detailed answers.