Class TexturedTriangle
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.texturedpolygon.TexturedTriangle
- Direct Known Subclasses:
LightmappedTriangle
A textured triangle renderer with perspective-correct texture mapping.
Quake-style subdivided perspective correction: (u/z, v/z, 1/z) are interpolated linearly in screen space and the exact texture coordinate is recovered with one reciprocal per subdivision interval, with affine stepping in between. This makes screen-size tessellation unnecessary — triangles of any size render with correct perspective.
- See Also:
-
Field Summary
Fields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
shapeId, verticesFields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
cachedBoundingBox, mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionTexturedTriangle(Vertex p1, Vertex p2, Vertex p3, Texture texture) Creates a textured triangle with the specified vertices and texture. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current texture.booleanChecks if backface culling is enabled for this triangle.static booleanReturns whether perspective-correct texture mapping is enabled.voidpaint(RenderingContext renderBuffer) Paints this shape onto the rendering context's pixel buffer.protected final voidRecomputes the mipmap-selection metric after texture coordinates are replaced post-construction (used by generated-UV subclasses like lightmapped triangles).voidsetBackfaceCulling(boolean backfaceCulling) Enables or disables backface culling for this triangle.static voidsetPerspectiveCorrectionEnabled(boolean enabled) Enables or disables perspective-correct texture mapping.voidsetTexture(Texture texture) Atomically swaps the texture.Methods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape
clippedVertices, getBoundingBox, getBspRank, getScreenXMargin, getScreenYMargin, getZ, getZ, onScreenMaxX, onScreenMaxY, onScreenMinX, onScreenMinY, setBspRank, setZ, transform, translateMethods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
getTransformWeight, invalidateBounds, setMouseInteractionController
-
Constructor Details
-
TexturedTriangle
Creates a textured triangle with the specified vertices and texture.- Parameters:
p1- the first vertex (must have textureCoordinate set)p2- the second vertex (must have textureCoordinate set)p3- the third vertex (must have textureCoordinate set)texture- the texture to apply
-
-
Method Details
-
setPerspectiveCorrectionEnabled
public static void setPerspectiveCorrectionEnabled(boolean enabled) Enables or disables perspective-correct texture mapping. When disabled, rendering falls back to plain affine mapping, which visibly warps textures on large on-screen triangles at steep angles.- Parameters:
enabled-truefor perspective-correct mapping
-
isPerspectiveCorrectionEnabled
public static boolean isPerspectiveCorrectionEnabled()Returns whether perspective-correct texture mapping is enabled.- Returns:
truewhen perspective correction is active
-
getTexture
Returns the current texture.- Returns:
- the texture
-
setTexture
Atomically swaps the texture. Painters pick up the new texture at the next paint call; a triangle in flight finishes with the old one.- Parameters:
texture- the new texture
-
refreshTextureDistance
protected final void refreshTextureDistance()Recomputes the mipmap-selection metric after texture coordinates are replaced post-construction (used by generated-UV subclasses like lightmapped triangles). -
paint
Description copied from class:AbstractCoordinateShapePaints 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(eu.svjatoslav.sixth.e3d.gui.RenderingContext)to draw pixels.- Specified by:
paintin classAbstractCoordinateShape- Parameters:
renderBuffer- the rendering context containing the pixel buffer and graphics context
-
isBackfaceCullingEnabled
public boolean isBackfaceCullingEnabled()Checks if backface culling is enabled for this triangle.- Returns:
trueif backface culling is enabled
-
setBackfaceCulling
public void setBackfaceCulling(boolean backfaceCulling) Enables or disables backface culling for this triangle.- Parameters:
backfaceCulling-trueto enable backface culling
-