public class SolidPolygon extends AbstractCoordinateShape
A solid-color triangle renderer with mouse interaction support.

This class implements a high-performance triangle rasterizer using scanline algorithms. It handles: - Perspective-correct edge interpolation - Alpha blending with background pixels - Viewport clipping - Mouse hover detection via point-in-polygon tests - Optional flat shading based on light sources

The static drawPolygon method is designed for reuse by other polygon types.

  • Constructor Details

    • SolidPolygon

      public SolidPolygon(Point3D point1, Point3D point2, Point3D point3, Color color)
      Creates a solid triangle with the specified vertices and color.
      Parameters:
      point1 - the first vertex position
      point2 - the second vertex position
      point3 - the third vertex position
      color - the fill color of the triangle
  • Method Details

    • drawHorizontalLine

      public static void drawHorizontalLine(LineInterpolator line1, LineInterpolator line2, int y, RenderingContext renderBuffer, Color color)
      Draws a horizontal scanline between two edge interpolators with alpha blending.
      Parameters:
      line1 - the left edge interpolator
      line2 - the right edge interpolator
      y - the Y coordinate of the scanline
      renderBuffer - the rendering context to draw into
      color - the color to draw with
    • drawPolygon

      public static void drawPolygon(RenderingContext context, Point2D onScreenPoint1, Point2D onScreenPoint2, Point2D onScreenPoint3, MouseInteractionController mouseInteractionController, Color color)
      Renders a triangle with mouse interaction support and optional backface culling.

      This static method handles:

      • Rounding vertices to integer screen coordinates
      • Mouse hover detection via point-in-polygon test
      • Viewport clipping
      • Scanline rasterization with alpha blending
      Parameters:
      context - the rendering context
      onScreenPoint1 - the first vertex in screen coordinates
      onScreenPoint2 - the second vertex in screen coordinates
      onScreenPoint3 - the third vertex in screen coordinates
      mouseInteractionController - optional controller for mouse events, or null
      color - the fill color
    • getColor

      public Color getColor()
      Returns the fill color of this polygon.
      Returns:
      the polygon color
    • setColor

      public void setColor(Color color)
      Sets the fill color of this polygon.
      Parameters:
      color - the new color
    • isShadingEnabled

      public boolean isShadingEnabled()
      Checks if shading is enabled for this polygon.
      Returns:
      true if shading is enabled, false otherwise
    • setShadingEnabled

      public void setShadingEnabled(boolean shadingEnabled)
      Enables or disables shading for this polygon. When enabled, the polygon uses the global lighting manager from the rendering context to calculate flat shading based on light sources.
      Parameters:
      shadingEnabled - true to enable shading, false to disable
    • isBackfaceCullingEnabled

      public boolean isBackfaceCullingEnabled()
      Checks if backface culling is enabled for this polygon.
      Returns:
      true if backface culling is enabled
    • setBackfaceCulling

      public void setBackfaceCulling(boolean backfaceCulling)
      Enables or disables backface culling for this polygon.

      When enabled, polygons facing away from the camera (determined by screen-space winding order) are not rendered.

      Parameters:
      backfaceCulling - true to enable backface culling
    • paint

      public void paint(RenderingContext renderBuffer)
      Renders this triangle to the screen.

      This method performs:

      • Backface culling check (if enabled)
      • Flat shading calculation (if lighting is enabled)
      • Triangle rasterization using the static drawPolygon method
      Specified by:
      paint in class AbstractCoordinateShape
      Parameters:
      renderBuffer - the rendering context containing the pixel buffer