Better text resolution on texture
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / ShapeCollection.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.renderer.raster;
6
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;
14
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18
19 public class ShapeCollection {
20
21     private final RenderAggregator aggregator = new RenderAggregator();
22     private final TransformPipe transformPipe = new TransformPipe();
23     private final List<AbstractShape> shapes = new ArrayList<>();
24
25     public synchronized void addShape(final AbstractShape shape) {
26         shapes.add(shape);
27     }
28
29     public Collection<AbstractShape> getShapes() {
30         return shapes;
31     }
32
33     public void clear() {
34         shapes.clear();
35     }
36
37     public synchronized void paint(final ViewPanel viewPanel,
38                                    final RenderingContext renderingContext) {
39
40         renderingContext.frameNumber++;
41
42         aggregator.reset();
43         transformPipe.clear();
44
45         // translate scene according to camera current location
46         final Avatar avatar = viewPanel.getAvatar();
47
48         // rotate scene according to avatar looking direction
49         transformPipe.addTransform(new Transform(new Point3D(), avatar
50                 .getAngleXZ(), avatar.getAngleYZ()));
51
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);
55
56         transformPipe.addTransform(new Transform(translation, 0, 0));
57
58         for (final AbstractShape shape : shapes)
59             shape.transform(transformPipe, aggregator, renderingContext);
60
61         aggregator.paint(renderingContext);
62     }
63 }