Class IntBresenhamTriangler
- All Implemented Interfaces:
Triangler
Triangler
implementation using the Bresenham
algorithm (on integers) 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 integers for all internal calculations. However, to make this work, all triangle vertices are converted to their integer counterparts at the inizialization phase. For the conversion, all coordinates are floored.
And, as an exception to the said above, barycentric coordinates for the color fill are operating on floats.
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
ConstructorDescriptionIntBresenhamTriangler
(javafx.scene.canvas.GraphicsContext ctx) Creates a newIntBresenhamTriangler
instance. -
Method Summary
-
Constructor Details
-
IntBresenhamTriangler
public IntBresenhamTriangler(javafx.scene.canvas.GraphicsContext ctx) Creates a newIntBresenhamTriangler
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.
-