Class SolidPolygon
java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon
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.
-
Field Summary
Fields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
onScreenZ, shapeId, verticesFields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionSolidPolygon(Point3D point1, Point3D point2, Point3D point3, Color color) Creates a solid triangle with the specified vertices and color. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddrawHorizontalLine(LineInterpolator line1, LineInterpolator line2, int y, RenderingContext renderBuffer, Color color) Draws a horizontal scanline between two edge interpolators with alpha blending.static voiddrawPolygon(RenderingContext context, Point2D onScreenPoint1, Point2D onScreenPoint2, Point2D onScreenPoint3, MouseInteractionController mouseInteractionController, Color color) Renders a triangle with mouse interaction support and optional backface culling.getColor()Returns the fill color of this polygon.booleanChecks if backface culling is enabled for this polygon.booleanChecks if shading is enabled for this polygon.voidpaint(RenderingContext renderBuffer) Renders this triangle to the screen.voidsetBackfaceCulling(boolean backfaceCulling) Enables or disables backface culling for this polygon.voidSets the fill color of this polygon.voidsetShadingEnabled(boolean shadingEnabled) Enables or disables shading for this polygon.Methods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
getZ, transformMethods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
setMouseInteractionController
-
Constructor Details
-
SolidPolygon
Creates a solid triangle with the specified vertices and color.- Parameters:
point1- the first vertex positionpoint2- the second vertex positionpoint3- the third vertex positioncolor- 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 interpolatorline2- the right edge interpolatory- the Y coordinate of the scanlinerenderBuffer- the rendering context to draw intocolor- 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 contextonScreenPoint1- the first vertex in screen coordinatesonScreenPoint2- the second vertex in screen coordinatesonScreenPoint3- the third vertex in screen coordinatesmouseInteractionController- optional controller for mouse events, or nullcolor- the fill color
-
getColor
Returns the fill color of this polygon.- Returns:
- the polygon color
-
setColor
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:
trueif 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-trueto enable backface culling
-
paint
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:
paintin classAbstractCoordinateShape- Parameters:
renderBuffer- the rendering context containing the pixel buffer
-