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;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.math.Transform;
14 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
15 import eu.svjatoslav.sixth.e3d.gui.Avatar;
16 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
17 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
24 public class ShapeCollection {
26 private final RenderAggregator aggregator = new RenderAggregator();
27 private final TransformPipe transformPipe = new TransformPipe();
28 private final List<AbstractShape> shapes = new ArrayList<>();
30 public synchronized void addShape(final AbstractShape shape) {
34 public Collection<AbstractShape> getShapes() {
42 public synchronized void paint(final ViewContext viewContext,
43 final RenderingContext renderingContext) {
45 renderingContext.frameNumber++;
48 transformPipe.clear();
50 // translate scene according to camera current location
51 final Avatar avatar = viewContext.getAvatar();
53 // rotate scene according to avatar looking direction
54 transformPipe.addTransform(new Transform(new Point3D(), avatar
55 .getAngleXZ(), avatar.getAngleYZ()));
57 // translate scene according to avatar location in the world
58 final Point3D translation = new Point3D(-avatar.getLocation().x,
59 -avatar.getLocation().y, -avatar.getLocation().z);
61 transformPipe.addTransform(new Transform(translation, 0, 0));
63 for (final AbstractShape shape : shapes)
64 shape.transform(transformPipe, aggregator, renderingContext);
66 aggregator.paint(renderingContext);