Class Frustum
The frustum is a truncated pyramid-shaped volume that represents everything the camera can see. Objects completely outside this volume can be skipped during rendering, significantly improving performance for large scenes.
Frustum planes:
- Left, Right, Top, Bottom - define the viewport edges
- Near - closest visible distance from camera
- Far - farthest visible distance from camera
Usage:
Frustum frustum = new Frustum();
frustum.update(camera, screenWidth, screenHeight);
Box objectBounds = shape.getBoundingBox();
if (frustum.intersectsAABB(objectBounds)) {
// Object is potentially visible - render it
} else {
// Object outside frustum - skip rendering
}
AABB intersection algorithm:
Uses the optimized "P-vertex" approach: for each plane, we test only the AABB corner most aligned with the plane normal. If this corner is behind the plane, the entire AABB is outside the frustum.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndex for the bottom clipping plane.static final intIndex for the far clipping plane.static final intIndex for the left clipping plane.static final intIndex for the near clipping plane.static final intIndex for the right clipping plane.static final intIndex for the top clipping plane. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the far clipping plane distance.doubleReturns the near clipping plane distance.getPlane(int planeIndex) Returns a specific frustum plane for debugging or advanced usage.booleanintersectsAABB(Box box) Tests whether an axis-aligned bounding box intersects the frustum.voidsetClipDistances(double near, double far) Sets the near and far clipping distances.voidUpdates the frustum planes in view space (camera at origin, looking along +Z).
-
Field Details
-
LEFT
public static final int LEFTIndex for the left clipping plane.- See Also:
-
RIGHT
public static final int RIGHTIndex for the right clipping plane.- See Also:
-
TOP
public static final int TOPIndex for the top clipping plane.- See Also:
-
BOTTOM
public static final int BOTTOMIndex for the bottom clipping plane.- See Also:
-
NEAR
public static final int NEARIndex for the near clipping plane.- See Also:
-
FAR
public static final int FARIndex for the far clipping plane.- See Also:
-
-
Constructor Details
-
Frustum
public Frustum()Creates a new frustum with uninitialized planes. Callupdate(eu.svjatoslav.sixth.e3d.gui.Camera, int, int)before using for culling.
-
-
Method Details
-
update
Updates the frustum planes in view space (camera at origin, looking along +Z).This method should be called once per frame before rendering, after the camera position and orientation have been updated.
View space coordinate system:
- Camera at origin (0, 0, 0)
- Forward = +Z axis (looking into the screen)
- Right = +X axis
- Up = -Y axis (since Y-down means smaller Y is higher visually)
Plane normals point INTO the frustum (toward the visible volume). A point is inside if dot(normal, point) >= distance for all planes.
FOV calculation: The Sixth 3D engine uses projectionScale = width/3. This means tan(halfHFOV) = (width/2) / projectionScale = 1.5, giving a horizontal FOV of approximately 112 degrees.
- Parameters:
camera- the camera (used only for aspect ratio derivation from width/height)width- the viewport width in pixels (defines projectionScale)height- the viewport height in pixels (used for vertical FOV)
-
intersectsAABB
Tests whether an axis-aligned bounding box intersects the frustum.This is a conservative test: returns
trueif the box is potentially visible (inside or partially inside the frustum), andfalseonly if the box is completely outside all frustum planes.Optimized algorithm:
For each plane, we test only the AABB corner most aligned with the plane normal (the "P-vertex"). If this corner is behind the plane, the entire AABB must be outside the frustum.
- Parameters:
box- the axis-aligned bounding box to test (in view space coordinates)- Returns:
trueif the box intersects or is inside the frustum,falseif completely outside
-
getNearDistance
public double getNearDistance()Returns the near clipping plane distance.- Returns:
- the near distance in world units
-
getFarDistance
public double getFarDistance()Returns the far clipping plane distance.- Returns:
- the far distance in world units
-
setClipDistances
public void setClipDistances(double near, double far) Sets the near and far clipping distances.- Parameters:
near- the near plane distance (objects closer are culled)far- the far plane distance (objects farther are culled)
-
getPlane
Returns a specific frustum plane for debugging or advanced usage.- Parameters:
planeIndex- one of LEFT, RIGHT, TOP, BOTTOM, NEAR, FAR- Returns:
- the plane at the specified index
-