2 * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
14 import eu.svjatoslav.sixth.e3d.geometry.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;
18 public class Grid2D extends AbstractCompositeShape {
20 public Grid2D(final Transform transform, final Rectangle rectangle,
21 final int divisionsX, final int divisionsY,
22 final LineAppearance appearance) {
26 final double stepY = rectangle.getHeight() / divisionsY;
27 final double stepX = rectangle.getWidth() / divisionsX;
29 for (int yslice = 0; yslice <= divisionsY; yslice++) {
30 final double y = (yslice * stepY) + rectangle.getLowerY();
32 for (int xslice = 0; xslice <= divisionsX; xslice++) {
33 final double x = (xslice * stepX) + rectangle.getLowerX();
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);
39 if (xslice < divisionsX)
40 addShape(appearance.getLine(p1, p2));
42 if (yslice < divisionsY)
43 addShape(appearance.getLine(p1, p3));