Game Development Reference
In-Depth Information
How it works...
This example shows you one of the strengths of using Control and AppState , as it's
easy to add functionalities to a spatial object as long as the logic is kept modular.
Another (although possibly less effective) way of performing the selection would be to run
a collision check against all spatial objects in a scene and use Spa-
tial.getControl (SelectableControl.class) to see whether any of the
spatials should be possible to select.
In this recipe, the items in the selectables list extend the Spatial class, but the only
actual requirement is that the objects implement the Collidable interface.
When shooting the ray, we get the position of the mouse cursor from InputManager . It's
a Vector2f object, where 0,0 is the bottom-left corner, and the top-right corner equals
the height and width of the screen (in units). After this, we use Cam-
era.getWorldCoordinates to give us a 3D position of the mouse click (or any posi-
tion on the screen). To do this, we must supply a depth value. This is between 0, which is
closest to the screen, and 1f, into infinity. The direction would then be the difference
between the nearest and farthest value, and it would be normalized.
Search WWH ::




Custom Search