Changed license to Creative Commons Zero (CC0).
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / solid / SolidPolygonRectangularBox.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 *
6  */
7
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.solid;
9
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
14
15 public class SolidPolygonRectangularBox extends AbstractCompositeShape {
16
17     /**
18      * Draws solid rectangular box between using center and size.
19      *
20      * @param center center of the box
21      * @param size   size of the box
22      * @param color  box color
23      */
24     public SolidPolygonRectangularBox(final Point3D center, final double size, final Color color) {
25         this(//
26                 new Point3D(center.x - (size / 2), center.y - (size / 2), center.z - (size / 2)), //
27                 new Point3D(center.x + (size / 2), center.y + (size / 2), center.z + (size / 2)), //
28                 color);
29     }
30
31     /**
32      * Draws solid rectangular box between 2 given points in 3D space.
33      */
34     public SolidPolygonRectangularBox(final Point3D p1, final Point3D p7, final Color color) {
35         super();
36
37         final Point3D p2 = new Point3D(p7.x, p1.y, p1.z);
38         final Point3D p3 = new Point3D(p7.x, p1.y, p7.z);
39         final Point3D p4 = new Point3D(p1.x, p1.y, p7.z);
40
41         final Point3D p5 = new Point3D(p1.x, p7.y, p1.z);
42         final Point3D p6 = new Point3D(p7.x, p7.y, p1.z);
43         final Point3D p8 = new Point3D(p1.x, p7.y, p7.z);
44
45         addShape(new SolidPolygon(p1, p2, p3, color));
46         addShape(new SolidPolygon(p1, p4, p3, color));
47
48         addShape(new SolidPolygon(p5, p6, p7, color));
49         addShape(new SolidPolygon(p5, p8, p7, color));
50
51         addShape(new SolidPolygon(p4, p3, p8, color));
52         addShape(new SolidPolygon(p3, p7, p8, color));
53
54         addShape(new SolidPolygon(p1, p5, p4, color));
55         addShape(new SolidPolygon(p4, p5, p8, color));
56
57         addShape(new SolidPolygon(p1, p2, p5, color));
58         addShape(new SolidPolygon(p2, p6, p5, color));
59
60         addShape(new SolidPolygon(p2, p6, p3, color));
61         addShape(new SolidPolygon(p6, p7, p3, color));
62     }
63
64 }