You want the player to aim and click one of the cubes. You want to identify the selected cube, and make it rotate.
Start by implementing the
AnalogListener
object on theAnalog()
method to test for our left-click action,MAPPING_ROTATE
. Remember, we chose theAnalogListener
object because rotation is a continuous motion.private AnalogListener analogListener = new AnalogListener() { public void onAnalog(String name, float intensity, float tpf) { if (name.equals(MAPPING_ROTATE)) { // implement action here } } };
To identify what was clicked, we use methods from the
com.jme3.collision
package. Replace the implement action here comment with the following code; first we create an empty results list.CollisionResults results = new CollisionResults();
We aim at an invisible line (a so called
com.jme3.math.ray
) straight from the camera location forward in the camera direction.Ray ray = new Ray(cam.getLocation...