final Camera camera = _canvas.getCanvasRenderer().getCamera();
// Make sure camera is above terrain
pickRay.setOrigin(camera.getLocation());
pickRay.setDirection(Vector3.NEG_UNIT_Z);
final PrimitivePickResults pickResultsCam = new PrimitivePickResults();
pickResultsCam.setCheckDistance(true);
PickingUtil.findPick(terrain, pickRay, pickResultsCam);
if (pickResultsCam.getNumber() != 0) {
final Vector3 intersectionPoint = pickResultsCam.getPickData(0).getIntersectionRecord()
.getIntersectionPoint(0);
final double height = intersectionPoint.getZ();
if (height > -Float.MAX_VALUE && (groundCamera || camera.getLocation().getZ() < height + 5)) {
camera.setLocation(new Vector3(camera.getLocation().getX(), camera.getLocation().getY(), height + 5));
}
}
if (updateTerrain) {
terrainCamera.set(camera);
}
skybox.setTranslation(camera.getLocation());
// if we're picking...
if (sphere.getSceneHints().getCullHint() == CullHint.Dynamic) {
// Set up our pick ray
pickRay.setOrigin(camera.getLocation());
pickRay.setDirection(camera.getDirection());
// do pick and move the sphere
final PrimitivePickResults pickResults = new PrimitivePickResults();
pickResults.setCheckDistance(true);
PickingUtil.findPick(_root, pickRay, pickResults);
if (pickResults.getNumber() != 0) {
final Vector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord()
.getIntersectionPoint(0);
sphere.setTranslation(intersectionPoint);
// XXX: maybe change the color of the ball for valid vs. invalid?
}
}