2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
9 import eu.svjatoslav.sixth.e3d.math.Transform;
10 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
13 public class Grid2D extends AbstractCompositeShape {
16 * @param transform Grid location
17 * @param rectangle Grid dimensions
18 * @param xDivisionCount Division count along X axis
19 * @param yDivisionCount Division count along Y axis
20 * @param appearance Grid lines appearance
22 public Grid2D(final Transform transform, final Rectangle rectangle,
23 final int xDivisionCount, final int yDivisionCount,
24 final LineAppearance appearance) {
28 final double stepY = rectangle.getHeight() / yDivisionCount;
29 final double stepX = rectangle.getWidth() / xDivisionCount;
31 for (int ySlice = 0; ySlice <= yDivisionCount; ySlice++) {
32 final double y = (ySlice * stepY) + rectangle.getLowerY();
34 for (int xSlice = 0; xSlice <= xDivisionCount; xSlice++) {
35 final double x = (xSlice * stepX) + rectangle.getLowerX();
37 final Point3D p1 = new Point3D(x, y, 0);
38 final Point3D p2 = new Point3D(x + stepX, y, 0);
39 final Point3D p3 = new Point3D(x, y + stepY, 0);
41 if (xSlice < xDivisionCount)
42 addShape(appearance.getLine(p1, p2));
44 if (ySlice < yDivisionCount)
45 addShape(appearance.getLine(p1, p3));