Class AbstractShape

java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
Direct Known Subclasses:
AbstractCompositeShape, AbstractCoordinateShape

public abstract class AbstractShape extends Object
Base class for all renderable shapes in the Sixth 3D engine.

Every shape that can be rendered must extend this class and implement the transform(TransformStack, RenderAggregator, RenderingContext) method, which projects the shape from world space into screen space during each render frame.

Shapes can optionally have a MouseInteractionController attached to receive mouse click and hover events when the user interacts with the shape in the 3D view.

Shape hierarchy overview:

 AbstractShape
   +-- AbstractCoordinateShape   (shapes with vertex coordinates: lines, polygons)
   +-- AbstractCompositeShape    (groups of sub-shapes: boxes, grids, text canvases)
 
See Also:
  • Field Details

    • mouseInteractionController

      public MouseInteractionController mouseInteractionController
      Optional controller that receives mouse interaction events (click, enter, exit) when the user interacts with this shape in the 3D view. Set to null if mouse interaction is not needed.
    • cachedBoundingBox

      protected Box cachedBoundingBox
      Cached bounding box in local coordinates. Lazily computed on first call to getBoundingBox(). Subclasses should set this to null when geometry changes to trigger recomputation.
  • Constructor Details

    • AbstractShape

      public AbstractShape()
      Default constructor for abstract shape.
  • Method Details

    • getBoundingBox

      public Box getBoundingBox()
      Returns the axis-aligned bounding box for this shape in local coordinates.

      The bounding box is used for frustum culling to determine if the shape is potentially visible before expensive vertex transformations.

      Conservative default: Returns a very large box that ensures the shape is always considered visible. Subclasses should override to provide tight bounds computed from their geometry.

      Caching: The bounding box is cached after first computation. If geometry changes, call invalidateBounds() to trigger recomputation on next call.

      Returns:
      the axis-aligned bounding box in local coordinates
    • invalidateBounds

      public void invalidateBounds()
      Invalidates the cached bounding box, forcing recomputation on next call to getBoundingBox().

      Call this method whenever the shape's geometry changes to ensure frustum culling uses up-to-date bounds. This is critical for shapes that move or deform after creation.

      Usage example:

      
       // After modifying vertex coordinates directly:
       vertex.coordinate.translate(0, 10, 0);
       shape.invalidateBounds();
      
       // Or use translate() on AbstractCoordinateShape which handles this automatically
       
    • setMouseInteractionController

      public void setMouseInteractionController(MouseInteractionController mouseInteractionController)
      Assigns a mouse interaction controller to this shape.

      Example usage:

      
       shape.setMouseInteractionController(new MouseInteractionController() {
           public boolean mouseClicked(int button) {
               System.out.println("Shape clicked!");
               return true;
           }
           public boolean mouseEntered() { return false; }
           public boolean mouseExited() { return false; }
       });
       
      Parameters:
      mouseInteractionController - the controller to handle mouse events, or null to disable mouse interaction
    • transform

      public abstract void transform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext)
      Transforms this shape from world space to screen space and queues it for rendering.

      This method is called once per frame for each shape in the scene. Implementations should apply the current transform stack to their vertices, compute screen-space coordinates, and if the shape is visible, add it to the RenderAggregator for depth-sorted painting.

      Parameters:
      transforms - the current stack of transforms (world-to-camera transformations)
      aggregator - collects transformed shapes for depth-sorted rendering
      renderingContext - provides frame dimensions, graphics context, and frame metadata