Updated copyright
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / solid / SolidPolygonRectangularBox.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2019, 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.solid;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
16
17 public class SolidPolygonRectangularBox extends AbstractCompositeShape {
18
19     /**
20      * Draws solid rectangular box between using center and size.
21      *
22      * @param center center of the box
23      * @param size   size of the box
24      * @param color  box color
25      */
26     public SolidPolygonRectangularBox(final Point3D center, final double size, final Color color) {
27         this(//
28                 new Point3D(center.x - (size / 2), center.y - (size / 2), center.z - (size / 2)), //
29                 new Point3D(center.x + (size / 2), center.y + (size / 2), center.z + (size / 2)), //
30                 color);
31     }
32
33     /**
34      * Draws solid rectangular box between 2 given points in 3D space.
35      */
36     public SolidPolygonRectangularBox(final Point3D p1, final Point3D p7, final Color color) {
37         super();
38
39         final Point3D p2 = new Point3D(p7.x, p1.y, p1.z);
40         final Point3D p3 = new Point3D(p7.x, p1.y, p7.z);
41         final Point3D p4 = new Point3D(p1.x, p1.y, p7.z);
42
43         final Point3D p5 = new Point3D(p1.x, p7.y, p1.z);
44         final Point3D p6 = new Point3D(p7.x, p7.y, p1.z);
45         final Point3D p8 = new Point3D(p1.x, p7.y, p7.z);
46
47         addShape(new SolidPolygon(p1, p2, p3, color));
48         addShape(new SolidPolygon(p1, p4, p3, color));
49
50         addShape(new SolidPolygon(p5, p6, p7, color));
51         addShape(new SolidPolygon(p5, p8, p7, color));
52
53         addShape(new SolidPolygon(p4, p3, p8, color));
54         addShape(new SolidPolygon(p3, p7, p8, color));
55
56         addShape(new SolidPolygon(p1, p5, p4, color));
57         addShape(new SolidPolygon(p4, p5, p8, color));
58
59         addShape(new SolidPolygon(p1, p2, p5, color));
60         addShape(new SolidPolygon(p2, p6, p5, color));
61
62         addShape(new SolidPolygon(p2, p6, p3, color));
63         addShape(new SolidPolygon(p6, p7, p3, color));
64     }
65
66 }