Ray ray = new Ray(target, dir);
PickInfo info = collisionSys.pickAllWorldRay(ray, true, false,
false, cameraComp);
for (int i = 0; i < info.size(); i++) {
// find the next picked object
PickDetails details = info.get(i);
// if the distance is less than the minimum, try the next
// info
if (details.getDistance() < MIN_DISTANCE) {
continue;
}
// if we are performing a collision check, see if the
// camera is closer than the collision
if (collisionCheck) {
if (target.distance(translation) <= details.getDistance()) {
// camera is closer than the nearest collision,
// re-enable collision
collisionEnabled = true;
}
// only check the first collision
break;
}
// if the collision is farther than where the camera would
// have been positioned or outside of range, we can stop and
// leave the camera as is
if (details.getDistance() >= MAX_DISTANCE ||
details.getDistance() >= target.distance(translation))
{
break;
}
// if we made it here, the collision is within range. Move
// the camera to the collision point
translation.set(details.getPosition());
break;
}
// we have checked the collision status -- don't check again until
// the user zooms in