d918ce95d3487c8c878b149bfaf96ae9a5e3f0c3
[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 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
9 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
10
11 public class Grid3D extends AbstractCompositeShape {
12
13     public Grid3D(final Point3D p1t, final Point3D p2t, final double step,
14                   final LineAppearance appearance) {
15
16         super();
17
18         final Point3D p1 = new Point3D(p1t);
19         final Point3D p2 = new Point3D(p2t);
20
21         if (p1.x > p2.x) {
22             final double tmp = p1.x;
23             p1.x = p2.x;
24             p2.x = tmp;
25         }
26
27         if (p1.y > p2.y) {
28             final double tmp = p1.y;
29             p1.y = p2.y;
30             p2.y = tmp;
31         }
32
33         if (p1.z > p2.z) {
34             final double tmp = p1.z;
35             p1.z = p2.z;
36             p2.z = tmp;
37         }
38
39         for (double x = p1.x; x <= p2.x; x += step)
40             for (double y = p1.y; y <= p2.y; y += step)
41                 for (double z = p1.z; z <= p2.z; z += step) {
42
43                     final Point3D p3 = new Point3D(x, y, z);
44
45                     if ((x + step) <= p2.x) {
46                         final Point3D point3d2 = new Point3D(x + step, y, z);
47                         addShape(appearance.getLine(p3, point3d2));
48                     }
49
50                     if ((y + step) <= p2.y) {
51                         final Point3D point3d3 = new Point3D(x, y + step, z);
52                         addShape(appearance.getLine(p3, point3d3));
53                     }
54
55                     if ((z + step) <= p2.z) {
56                         final Point3D point3d4 = new Point3D(x, y, z + step);
57                         addShape(appearance.getLine(p3, point3d4));
58                     }
59
60                 }
61     }
62 }