Time for action – pick a brick (pointer with ray casting)
Now your player can click items, but how do you find out what he clicked? In principle, we can use the same ray casting algorithm as for the previous example with the crosshairs. Only instead of casting the ray from the camera forward, we now cast it forward from the 3D coordinates of the click location.
- Implement the
AnalogListener
object on theAnalog()
method to test for our left-click action,MAPPING_ROTATE
.private AnalogListener analogListener = new AnalogListener() { public void onAnalog(String name, float intensity, float tpf) { if (name.equals(MAPPING_ROTATE)) { // implement action here } } };
- Replace the implement action here comment by the following code. To identify what was clicked, ...
Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.