private void doPicking() { Point mouse = canvas.getMousePosition(); if (mouse == null) { clearLabel(); } else { vec2.x = mouse.x; vec2.y = canvas.getHeight() - mouse.y; // create ray Vector3f end = scene.getCamera().getWorldCoordinates(vec2, 0.2f); Vector3f start = scene.getCamera().getLocation(); Ray ray = new Ray(start, end.subtractLocal(start).normalizeLocal()); // do collision checking CollisionResults results = new CollisionResults(); scene.getRootNode().collideWith(ray, results); CollisionResult result = results.getClosestCollision(); if (result != null) { Vector3f contactPoint = result.getContactPoint(); setLabel(contactPoint); } else { clearLabel(); } } }
private void activate(LevelScene scene, Component canvas) { this.scene = scene; this.canvas = canvas; scene.getRootNode().addControl(pickingControl); }