Changed license to Creative Commons Zero (CC0).
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / wireframe / WireframeSphere.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 *
6  */
7
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe;
9
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
13
14 import java.util.ArrayList;
15
16 public class WireframeSphere extends AbstractCompositeShape {
17
18     ArrayList<Point3D> previousRing = new ArrayList<>();
19
20     public WireframeSphere(final Point3D location, final float radius,
21                            final LineAppearance lineFactory) {
22         super(location);
23
24         final double step = Math.PI / 10;
25
26         final Point3D center = new Point3D();
27
28         int ringIndex = 0;
29
30         for (double j = 0d; j <= (Math.PI * 2); j += step) {
31
32             Point3D oldPoint = null;
33             int pointIndex = 0;
34
35             for (double i = 0; i <= (Math.PI * 2); i += step) {
36                 final Point3D newPoint = new Point3D(0, 0, radius);
37                 newPoint.rotate(center, i, j);
38
39                 if (oldPoint != null)
40                     addShape(lineFactory.getLine(newPoint, oldPoint));
41
42                 if (ringIndex > 0) {
43                     final Point3D previousRingPoint = previousRing
44                             .get(pointIndex);
45                     addShape(lineFactory.getLine(newPoint, previousRingPoint));
46
47                     previousRing.set(pointIndex, newPoint);
48                 } else
49                     previousRing.add(newPoint);
50
51                 oldPoint = newPoint;
52                 pointIndex++;
53             }
54
55             ringIndex++;
56         }
57
58     }
59
60 }