Changed license to Creative Commons Zero (CC0).
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / wireframe / Grid3D.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 public class Grid3D extends AbstractCompositeShape {
15
16     public Grid3D(final Point3D p1t, final Point3D p2t, final double step,
17                   final LineAppearance appearance) {
18
19         super();
20
21         final Point3D p1 = new Point3D(p1t);
22         final Point3D p2 = new Point3D(p2t);
23
24         if (p1.x > p2.x) {
25             final double tmp = p1.x;
26             p1.x = p2.x;
27             p2.x = tmp;
28         }
29
30         if (p1.y > p2.y) {
31             final double tmp = p1.y;
32             p1.y = p2.y;
33             p2.y = tmp;
34         }
35
36         if (p1.z > p2.z) {
37             final double tmp = p1.z;
38             p1.z = p2.z;
39             p2.z = tmp;
40         }
41
42         for (double x = p1.x; x <= p2.x; x += step)
43             for (double y = p1.y; y <= p2.y; y += step)
44                 for (double z = p1.z; z <= p2.z; z += step) {
45
46                     final Point3D p3 = new Point3D(x, y, z);
47
48                     if ((x + step) <= p2.x) {
49                         final Point3D point3d2 = new Point3D(x + step, y, z);
50                         addShape(appearance.getLine(p3, point3d2));
51                     }
52
53                     if ((y + step) <= p2.y) {
54                         final Point3D point3d3 = new Point3D(x, y + step, z);
55                         addShape(appearance.getLine(p3, point3d3));
56                     }
57
58                     if ((z + step) <= p2.z) {
59                         final Point3D point3d4 = new Point3D(x, y, z + step);
60                         addShape(appearance.getLine(p3, point3d4));
61                     }
62
63                 }
64     }
65 }