Hi i spended few hours searching and googling but cant find anything. I want make terrain editor same like SceneComposer, but i have problem with mouse pick. Here you can see video… Ray cast always point to same position, but i want make cast ray directly straight from mouseCursor, so i shouldn’t se line, but just dot.
CrossHair picker working fine i want same behavior for mouse picket to, just set start point with mouse and not center of screen.
private Vector3f getTerrainIntersection() {
CollisionResults results = new CollisionResults();
Vector3f loc = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f dir = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
dir = dir.subtractLocal(loc).normalizeLocal();
Ray ray = new Ray(loc, dir);
terrain.getParent().collideWith(ray, results);
if (rootNode.hasChild(line)) {
line.removeFromParent();
}
line = new Geometry("Line", new Line(loc, dir));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Orange);
mat.getAdditionalRenderState().setWireframe(true);
line.setMaterial(mat);
rootNode.attachChild(line);
if (results.size() > 0) {
return results.getClosestCollision().getContactPoint();
}
return null;
}