Game Development Reference
In-Depth Information
Now, you can run the scene and navigate. You will find that the number of cars will
change according to the position of the camera.
In the preceding isVisible() function, we check whether the position of the car
is inside. What if only a part of the car is within the frustum? In order to check this,
LibGDX provides a function, boundsInFrustum , to check whether the bounding box
is completely within the frustum. A bounding box is a box that contains the entire
model/instance. The following screenshot will give you a clear picture of this:
So, we can update our isVisible() function to check the bounding box in the
following way:
private boolean isVisible(PerspectiveCamera cam, ModelInstance
instance) {
instance.transform.getTranslation(position);
BoundingBox box = instance.calculateBoundingBox(new BoundingBox());
return cam.frustum.boundsInFrustum(position, box.getDimensions());
}
The calculateBoundingBox method will return the bounding box of that particular
instance. Note, this function is a slow operation; hence, it would be better if you
cache the result.
 
Search WWH ::




Custom Search