0156db2087094ca7ca777a3639735b69a008b5ec
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / wireframe / Grid2D.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2018, 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.geometry.Rectangle;
14 import eu.svjatoslav.sixth.e3d.math.Transform;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
17
18 public class Grid2D extends AbstractCompositeShape {
19
20     public Grid2D(final Transform transform, final Rectangle rectangle,
21                   final int divisionsX, final int divisionsY,
22                   final LineAppearance appearance) {
23
24         super(transform);
25
26         final double stepY = rectangle.getHeight() / divisionsY;
27         final double stepX = rectangle.getWidth() / divisionsX;
28
29         for (int yslice = 0; yslice <= divisionsY; yslice++) {
30             final double y = (yslice * stepY) + rectangle.getLowerY();
31
32             for (int xslice = 0; xslice <= divisionsX; xslice++) {
33                 final double x = (xslice * stepX) + rectangle.getLowerX();
34
35                 final Point3D p1 = new Point3D(x, y, 0);
36                 final Point3D p2 = new Point3D(x + stepX, y, 0);
37                 final Point3D p3 = new Point3D(x, y + stepY, 0);
38
39                 if (xslice < divisionsX)
40                     addShape(appearance.getLine(p1, p2));
41
42                 if (yslice < divisionsY)
43                     addShape(appearance.getLine(p1, p3));
44             }
45
46         }
47
48     }
49
50 }