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, CanvasCharacter, 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()
      Returns the average Z-depth of this shape in screen space.
      Returns:
      the average Z-depth value, used for depth sorting
    • 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 to draw pixels.

      Parameters:
      renderBuffer - the rendering context containing the pixel buffer and graphics context
    • 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. Computes the average Z-depth and, if all vertices are visible (in front of the camera), 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