Class Frustum

java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Frustum

public class Frustum extends Object
View frustum for frustum culling - eliminates objects outside the camera's view.

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Index for the bottom clipping plane.
    static final int
    Index for the far clipping plane.
    static final int
    Index for the left clipping plane.
    static final int
    Index for the near clipping plane.
    static final int
    Index for the right clipping plane.
    static final int
    Index for the top clipping plane.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new frustum with uninitialized planes.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the far clipping plane distance.
    double
    Returns the near clipping plane distance.
    getPlane(int planeIndex)
    Returns a specific frustum plane for debugging or advanced usage.
    boolean
    Tests whether an axis-aligned bounding box intersects the frustum.
    void
    setClipDistances(double near, double far)
    Sets the near and far clipping distances.
    void
    update(Camera camera, int width, int height)
    Updates the frustum planes in view space (camera at origin, looking along +Z).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • update

      public void update(Camera camera, int width, int height)
      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

      public boolean intersectsAABB(Box box)
      Tests whether an axis-aligned bounding box intersects the frustum.

      This is a conservative test: returns true if the box is potentially visible (inside or partially inside the frustum), and false only 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:
      true if the box intersects or is inside the frustum, false if 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

      public Plane getPlane(int planeIndex)
      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