Class AbstractCoordinateShape

java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
Direct Known Subclasses:
Billboard, Line, SolidPolygon, TexturedTriangle

public abstract class AbstractCoordinateShape extends AbstractShape
Base class for shapes defined by a list of vertex coordinates.

This is the foundation for all primitive renderable shapes such as lines, solid polygons, and textured polygons. Each shape has a list of vertices (Vertex objects) that define its geometry in 3D space.

During each render frame, the transform(eu.svjatoslav.sixth.e3d.math.TransformStack, eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator, eu.svjatoslav.sixth.e3d.gui.RenderingContext) method projects all vertices from world space to screen space. If all vertices are visible (in front of the camera), the shape is queued in the RenderAggregator for depth-sorted painting via the paint(eu.svjatoslav.sixth.e3d.gui.RenderingContext) method.

Creating a custom coordinate shape:


 public class Triangle extends AbstractCoordinateShape {
     private final Color color;

     public Triangle(Point3D p1, Point3D p2, Point3D p3, Color color) {
         super(new Vertex(p1), new Vertex(p2), new Vertex(p3));
         this.color = color;
     }

     public void paint(RenderingContext ctx) {
         // Custom painting logic using ctx.graphics and
         // vertices.get(i).transformedCoordinate for screen positions
     }
 }
 
See Also:
  • Field Details

  • Constructor Details

    • AbstractCoordinateShape

      public AbstractCoordinateShape(int vertexCount)
      Creates a shape with the specified number of vertices, each initialized to the origin (0, 0, 0).
      Parameters:
      vertexCount - the number of vertices in this shape
    • AbstractCoordinateShape

      public AbstractCoordinateShape(Vertex... vertices)
      Creates a shape from the given vertices.
      Parameters:
      vertices - the vertices defining this shape's geometry
    • AbstractCoordinateShape

      public AbstractCoordinateShape(List<Vertex> vertices)
      Creates a shape from a list of vertices.
      Parameters:
      vertices - the list of vertices defining this shape's geometry
  • Method Details

    • getZ

      public double getZ(RenderingContext renderingContext)
      Returns the average Z-depth of this shape in screen space for the context's buffer slot.
      Parameters:
      renderingContext - the rendering context (selects the buffer slot)
      Returns:
      the average Z-depth value, used for depth sorting
    • getZ

      public double getZ(int slot)
      Returns the average Z-depth of this shape for an explicit buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      Returns:
      the average Z-depth value, used for depth sorting
    • onScreenMinY

      public double onScreenMinY(int slot)
      Screen-space minimum Y bound (pixels) for the given buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      Returns:
      minimum Y this shape's paint can touch
    • onScreenMaxY

      public double onScreenMaxY(int slot)
      Screen-space maximum Y bound (pixels) for the given buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      Returns:
      maximum Y this shape's paint can touch
    • onScreenMinX

      public double onScreenMinX(int slot)
      Screen-space minimum X bound (pixels) for the given buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      Returns:
      minimum X this shape's paint can touch
    • onScreenMaxX

      public double onScreenMaxX(int slot)
      Screen-space maximum X bound (pixels) for the given buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      Returns:
      maximum X this shape's paint can touch
    • setZ

      public void setZ(int slot, double z)
      Sets the average Z-depth for the given buffer slot.
      Parameters:
      slot - buffer slot (0 or 1)
      z - average Z-depth value
    • getBspRank

      public int getBspRank(int slot)
      Returns the BSP painter's-order rank for the given buffer slot.
      Parameters:
      slot - buffer slot (0, 1 or 2)
      Returns:
      traversal rank (0 = farthest), or -1 if not BSP-ordered
    • setBspRank

      public void setBspRank(int slot, int rank)
      Sets the BSP painter's-order rank for the given buffer slot.
      Parameters:
      slot - buffer slot (0, 1 or 2)
      rank - traversal rank (0 = farthest), -1 to clear
    • getBoundingBox

      public Box getBoundingBox()
      Returns the axis-aligned bounding box computed from vertex coordinates.

      The bounding box encompasses all vertices in this shape, computed by finding the minimum and maximum coordinates along each axis.

      Caching: The bounding box is cached after first computation. If vertices change, call AbstractShape.invalidateBounds() before calling this method to trigger recomputation.

      Overrides:
      getBoundingBox in class AbstractShape
      Returns:
      the axis-aligned bounding box in local coordinates
    • translate

      public void translate(double dx, double dy, double dz)
      Translates all vertices by the specified offsets.

      This method moves the entire shape by modifying each vertex's world-space coordinate. It also invalidates the cached bounding box so that frustum culling uses the correct bounds after movement.

      Usage example:

      
       // Move shape 10 units up (Y decreases in Sixth 3D's coordinate system)
       shape.translate(0, -10, 0);
      
       // Move shape diagonally
       shape.translate(5, 0, 5);
       
      Parameters:
      dx - offset along the X axis (positive = right)
      dy - offset along the Y axis (positive = down, negative = up)
      dz - offset along the Z axis (positive = away from camera)
    • paint

      public abstract void paint(RenderingContext renderBuffer)
      Paints this shape onto the rendering context's pixel buffer.

      This method is called after all shapes have been transformed and sorted by depth. Implementations should use the transformed screen-space coordinates from Vertex.transformedCoordinate(eu.svjatoslav.sixth.e3d.gui.RenderingContext) to draw pixels.

      Parameters:
      renderBuffer - the rendering context containing the pixel buffer and graphics context
    • getScreenYMargin

      protected double getScreenYMargin(RenderingContext renderingContext)
      Extra screen-space Y distance beyond the vertex bounds that paint(eu.svjatoslav.sixth.e3d.gui.RenderingContext) can touch. Shapes whose paint output extends past the vertex positions (thick lines, billboards, text glyphs) must override this so tile binning does not drop them from tiles they partially overlap.
      Parameters:
      renderingContext - the rendering context (provides projection parameters for size computation)
      Returns:
      the Y margin in screen pixels (0 = vertex bounds are exact)
    • getScreenXMargin

      protected double getScreenXMargin(RenderingContext renderingContext)
      Extra screen-space X distance beyond the vertex bounds that paint(eu.svjatoslav.sixth.e3d.gui.RenderingContext) can touch. Same contract as getScreenYMargin(RenderingContext), for the X axis.
      Parameters:
      renderingContext - the rendering context (provides projection parameters for size computation)
      Returns:
      the X margin in screen pixels (0 = vertex bounds are exact)
    • transform

      public 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.

      Transforms all vertices to screen space by applying the current transform stack. If ALL vertices are behind the near plane the shape is culled; if SOME are, the vertex loop is clipped against the near plane (see clipToNearPlane(RenderingContext)) and the clipped loop — not the original vertices — is queued for rendering. Computes the average Z-depth and screen bounds from the active (possibly clipped) vertices and queues this shape for rendering.

      Specified by:
      transform in class AbstractShape
      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
    • clippedVertices

      public List<Vertex> clippedVertices(RenderingContext renderingContext)
      Returns the near-plane-clipped vertex loop for the context's buffer slot, or null if this shape was not clipped (or was culled) this frame. Paint implementations must use this list when non-null.
      Parameters:
      renderingContext - the rendering context (selects the buffer slot)
      Returns:
      the clipped vertex loop, or null