2 * Aukio 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.aukio.e3d.renderer.raster.shapes.composite.wireframe;
7 import eu.svjatoslav.aukio.e3d.geometry.Point3D;
8 import eu.svjatoslav.aukio.e3d.renderer.raster.shapes.basic.line.Line;
9 import eu.svjatoslav.aukio.e3d.renderer.raster.shapes.basic.line.LineAppearance;
10 import eu.svjatoslav.aukio.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
13 * A freeform polyline drawing tool that connects sequential points with line
14 * segments. Points are added one at a time via {@link #addPoint(Point3D)};
15 * each new point is connected to the previously added point by a line.
17 * <p>The first point added establishes the starting position without drawing
18 * a line. Each subsequent point creates a new line segment from the previous
19 * point to the new one.</p>
21 * <p>This shape is useful for drawing paths, trails, trajectories, or
22 * arbitrary wireframe shapes that are defined as a sequence of vertices.</p>
24 * <p><b>Usage example:</b></p>
26 * LineAppearance appearance = new LineAppearance(2, Color.YELLOW);
27 * WireframeDrawing drawing = new WireframeDrawing(appearance);
28 * drawing.addPoint(new Point3D(0, 0, 0));
29 * drawing.addPoint(new Point3D(100, 50, 0));
30 * drawing.addPoint(new Point3D(200, 0, 0));
31 * shapeCollection.addShape(drawing);
35 * @see AbstractCompositeShape
37 public class WireframeDrawing extends AbstractCompositeShape {
39 /** The line appearance used for all segments in this drawing. */
40 final private LineAppearance lineAppearance;
42 /** The most recently added point, used as the start of the next line segment. */
46 * Constructs a new empty wireframe drawing with the given line appearance.
48 * @param lineAppearance the line appearance (color, width) used for all
49 * line segments added to this drawing
51 public WireframeDrawing(final LineAppearance lineAppearance) {
53 this.lineAppearance = lineAppearance;
57 * Adds a new point to the drawing. If this is the first point, it sets the
58 * starting position. Otherwise, a line segment is created from the previous
59 * point to this new point.
61 * <p>The point is defensively copied, so subsequent modifications to the
62 * passed {@code point3d} object will not affect the drawing.</p>
64 * @param point3d the point to add to the polyline
66 public void addPoint(final Point3D point3d) {
67 if (currentPoint != null) {
68 final Line line = lineAppearance.getLine(currentPoint, point3d);
72 currentPoint = new Point3D(point3d);