Question: How to translate mouse’s on-screen position to world coordinates?
// Using Top-down view like in strategy games(Battle Realms, Warcraft, etc).
// Following code produces unexpected results - it should draw a line from world’s 0,0,0 to the mouse pointer on XZ-plane.
[java]results = new CollisionResults();
Ray ray = new Ray(new Vector3f(inputManager.getCursorPosition().getX(), 0f, inputManager.getCursorPosition().getY()), new Vector3f(0f, -1f, 0f));
terrain.collideWith(ray, results);
if(results.size() > 0)
{
System.out.println("Collision!");
line = new Line(Vector3f.ZERO, results.getClosestCollision().getContactPoint());
geom = new Geometry("Line", line);
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
geom.setMaterial(mat);
rootNode.attachChild(geom);
}[/java]