2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.gui.Avatar;
9 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
10 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
11 import eu.svjatoslav.sixth.e3d.math.Transform;
12 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
19 public class ShapeCollection {
21 private final RenderAggregator aggregator = new RenderAggregator();
22 private final TransformPipe transformPipe = new TransformPipe();
23 private final List<AbstractShape> shapes = new ArrayList<>();
25 public synchronized void addShape(final AbstractShape shape) {
29 public Collection<AbstractShape> getShapes() {
37 public synchronized void paint(final ViewPanel viewPanel,
38 final RenderingContext renderingContext) {
40 renderingContext.frameNumber++;
43 transformPipe.clear();
45 // translate scene according to camera current location
46 final Avatar avatar = viewPanel.getAvatar();
48 // rotate scene according to avatar looking direction
49 transformPipe.addTransform(new Transform(new Point3D(), avatar
50 .getAngleXZ(), avatar.getAngleYZ()));
52 // translate scene according to avatar location in the world
53 final Point3D translation = new Point3D(-avatar.getLocation().x,
54 -avatar.getLocation().y, -avatar.getLocation().z);
56 transformPipe.addTransform(new Transform(translation, 0, 0));
58 for (final AbstractShape shape : shapes)
59 shape.transform(transformPipe, aggregator, renderingContext);
61 aggregator.paint(renderingContext);