Class AbstractCoordinateShape
- Direct Known Subclasses:
Billboard,CanvasCharacter,Line,SolidPolygon,TexturedTriangle
This is the foundation for all primitive renderable shapes such as lines,
solid polygons, and textured polygons. Each shape has a list of vertices
(Vertex objects) that define its geometry in 3D space.
During each render frame, the transform(eu.svjatoslav.sixth.e3d.math.TransformStack, eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator, eu.svjatoslav.sixth.e3d.gui.RenderingContext) method projects all vertices
from world space to screen space. If all vertices are visible (in front of the camera),
the shape is queued in the RenderAggregator for depth-sorted painting via
the paint(eu.svjatoslav.sixth.e3d.gui.RenderingContext) method.
Creating a custom coordinate shape:
public class Triangle extends AbstractCoordinateShape {
private final Color color;
public Triangle(Point3D p1, Point3D p2, Point3D p3, Color color) {
super(new Vertex(p1), new Vertex(p2), new Vertex(p3));
this.color = color;
}
public void paint(RenderingContext ctx) {
// Custom painting logic using ctx.graphics and
// vertices.get(i).transformedCoordinate for screen positions
}
}
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptiondoubleAverage Z-depth of this shape in screen space after transformation.final intUnique identifier for this shape instance, used as a tiebreaker when sorting shapes with identical Z-depth values.The vertex coordinates that define this shape's geometry.Fields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
cachedBoundingBox, mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCoordinateShape(int vertexCount) Creates a shape with the specified number of vertices, each initialized to the origin (0, 0, 0).AbstractCoordinateShape(Vertex... vertices) Creates a shape from the given vertices.AbstractCoordinateShape(List<Vertex> vertices) Creates a shape from a list of vertices. -
Method Summary
Modifier and TypeMethodDescriptionReturns the axis-aligned bounding box computed from vertex coordinates.doublegetZ()Returns the average Z-depth of this shape in screen space.abstract voidpaint(RenderingContext renderBuffer) Paints this shape onto the rendering context's pixel buffer.voidtransform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms this shape from world space to screen space and queues it for rendering.voidtranslate(double dx, double dy, double dz) Translates all vertices by the specified offsets.Methods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
invalidateBounds, setMouseInteractionController
-
Field Details
-
shapeId
public final int shapeIdUnique identifier for this shape instance, used as a tiebreaker when sorting shapes with identical Z-depth values. -
vertices
The vertex coordinates that define this shape's geometry. Each vertex contains both the original world-space coordinate and a transformed screen-space coordinate computed duringtransform(eu.svjatoslav.sixth.e3d.math.TransformStack, eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator, eu.svjatoslav.sixth.e3d.gui.RenderingContext).Stored as a mutable list to support CSG operations that modify polygon vertices in place (splitting, flipping).
-
onScreenZ
public double onScreenZAverage Z-depth of this shape in screen space after transformation. Used by theRenderAggregatorto sort shapes back-to-front for correct painter's algorithm rendering.
-
-
Constructor Details
-
AbstractCoordinateShape
public AbstractCoordinateShape(int vertexCount) Creates a shape with the specified number of vertices, each initialized to the origin (0, 0, 0).- Parameters:
vertexCount- the number of vertices in this shape
-
AbstractCoordinateShape
Creates a shape from the given vertices.- Parameters:
vertices- the vertices defining this shape's geometry
-
AbstractCoordinateShape
Creates a shape from a list of vertices.- Parameters:
vertices- the list of vertices defining this shape's geometry
-
-
Method Details
-
getZ
public double getZ()Returns the average Z-depth of this shape in screen space.- Returns:
- the average Z-depth value, used for depth sorting
-
getBoundingBox
Returns the axis-aligned bounding box computed from vertex coordinates.The bounding box encompasses all vertices in this shape, computed by finding the minimum and maximum coordinates along each axis.
Caching: The bounding box is cached after first computation. If vertices change, call
AbstractShape.invalidateBounds()before calling this method to trigger recomputation.- Overrides:
getBoundingBoxin classAbstractShape- Returns:
- the axis-aligned bounding box in local coordinates
-
translate
public void translate(double dx, double dy, double dz) Translates all vertices by the specified offsets.This method moves the entire shape by modifying each vertex's world-space coordinate. It also invalidates the cached bounding box so that frustum culling uses the correct bounds after movement.
Usage example:
// Move shape 10 units up (Y decreases in Sixth 3D's coordinate system) shape.translate(0, -10, 0); // Move shape diagonally shape.translate(5, 0, 5);- Parameters:
dx- offset along the X axis (positive = right)dy- offset along the Y axis (positive = down, negative = up)dz- offset along the Z axis (positive = away from camera)
-
paint
Paints 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.transformedCoordinateto draw pixels.- Parameters:
renderBuffer- the rendering context containing the pixel buffer and graphics context
-
transform
public void transform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms this shape from world space to screen space and queues it for rendering.This method is called once per frame for each shape in the scene. Implementations should apply the current transform stack to their vertices, compute screen-space coordinates, and if the shape is visible, add it to the
RenderAggregatorfor depth-sorted painting.Transforms all vertices to screen space by applying the current transform stack. Computes the average Z-depth and, if all vertices are visible (in front of the camera), queues this shape for rendering.
- Specified by:
transformin classAbstractShape- Parameters:
transforms- the current stack of transforms (world-to-camera transformations)aggregator- collects transformed shapes for depth-sorted renderingrenderingContext- provides frame dimensions, graphics context, and frame metadata
-