* Calculates the ray to use for picking, based on the given screen coordinates.
*/
Ray calcPickRayWorld (int x, int y) {
Ray result = null;
// Get the world space coordinates of the eye position
Camera camera = cameraComp.getCamera();
Vector3f eyePosWorld = camera.getLocation();
// Convert the event from AWT coords to JME float screen space.
// Need to invert y because (0f, 0f) is at the button left corner.
eventPointScreen.setX((float)x);
eventPointScreen.setY((float)(canvas.getHeight()-1-y));
// Get the world space coordinates of the screen space point from the event
// (The glass plate of the screen is considered to be at at z = 0 in world space
try { // May fail if jME thinks the camera matrix is singular
camera.getWorldCoordinates(eventPointScreen, 0f, eventPointWorld);
// Compute the diff and create the ray
eventPointWorld.subtract(eyePosWorld, directionWorld);
result = new Ray(eyePosWorld, directionWorld.normalize());
} catch (ArithmeticException ex) {
logger.log(Level.SEVERE,"Problem getting world space coords for pick ray.", ex);