2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
14 import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
15 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
18 import java.util.concurrent.atomic.AtomicInteger;
20 public abstract class AbstractCoordinateShape extends AbstractShape {
22 public static final AtomicInteger lastShapeId = new AtomicInteger();
23 public final int shapeId;
24 public final GeometryCoordinate[] coordinates;
25 public double onScreenZ;
27 public AbstractCoordinateShape(final int pointsCount) {
28 coordinates = new GeometryCoordinate[pointsCount];
29 for (int i = 0; i < pointsCount; i++)
30 coordinates[i] = new GeometryCoordinate();
32 shapeId = lastShapeId.getAndIncrement();
35 public AbstractCoordinateShape(final Point3D... locationPoints) {
36 coordinates = new GeometryCoordinate[locationPoints.length];
38 for (int i = 0; i < locationPoints.length; i++)
39 coordinates[i] = new GeometryCoordinate(locationPoints[i]);
41 shapeId = lastShapeId.getAndIncrement();
44 public double getZ() {
48 public abstract void paint(RenderingContext renderBuffer);
51 public void transform(final TransformPipe transforms,
52 final RenderAggregator aggregator,
53 final RenderingContext renderingContext) {
55 double accumulatedZ = 0;
58 for (final GeometryCoordinate geometryPoint : coordinates) {
59 geometryPoint.transform(transforms, renderingContext);
61 accumulatedZ += geometryPoint.transformedCoordinate.z;
63 if (!geometryPoint.transformedCoordinate.isVisible())
68 onScreenZ = accumulatedZ / coordinates.length;
69 aggregator.queueShapeForRendering(this);