Class DDATriangler
- All Implemented Interfaces:
Triangler
Triangler
implementation using the digital differential
analyzer algorithm for drawing slopes and drawing pixels one by one.
The algorithm separates the triangle into two (with flat side on max and/or min Y level), and then draws the slopes pixel by pixel with the triangle itself, using the scanline approach.
Uses floats for all calculations and converts the coordinates for rasterization to integers at the last stage - drawing horizontal lines. All floats at the convertion are floored (not rounded) for consistency.
Because of that, the triangles can be displaced to the start of the coordinate plane, and the gaps can be seen between the triangles, if this rasterization is used to draw triangulated polygons.
Sets pixels one by one with the
PixelWriter.setColor(int, int, javafx.scene.paint.Color)
call (the
rasterization is not buffered). It's very slow, so this implementation is not
recommended for fast rendering.
Algorithm documentation: Wikipedia.
The implementation is heavily based on this article.
- Since:
- 2.0.0
-
Constructor Summary
ConstructorDescriptionDDATriangler
(javafx.scene.canvas.GraphicsContext ctx) Creates a newDDATriangler
instance. -
Method Summary
-
Constructor Details
-
DDATriangler
public DDATriangler(javafx.scene.canvas.GraphicsContext ctx) Creates a newDDATriangler
instance.Anchores itself to the passed
GraphicsContext
: contains the reference to thePixelWriter
from the context.It's not a singleton class, so instances should be created and used separately.
- Parameters:
ctx
- graphics context to use for the rasterization- Since:
- 2.0.0
- See Also:
-
-
Method Details
-
filler
Description copied from interface:Triangler
Gets aFiller
currently used by this triangler. -
setFiller
Description copied from interface:Triangler
Sets theFiller
to use for the rasterization. -
draw
Description copied from interface:Triangler
Draws theTriangle
with the currently used filler.
-