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