5e9b53ba4da51b80b3a5334e23e3432ec9c48ca8
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / GridSpace.java
1 /*
2  * Sixth 3D engine demos. Copyright ©2012-2016, 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 package eu.svjatoslav.sixth.e3d.examples;
10
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid3D;
18
19 class GridSpace {
20
21     private static void addRandomPolygon(final ShapeCollection geometryCollection) {
22         final Point3D polygonLocation = getRandomPoint(1000);
23
24         final double polygonAverageSize = 30;
25
26         final Point3D point1 = new Point3D(polygonLocation);
27         point1.add(getRandomPoint(polygonAverageSize));
28
29         final Point3D point2 = new Point3D(polygonLocation);
30         point2.add(getRandomPoint(polygonAverageSize));
31
32         final Point3D point3 = new Point3D(polygonLocation);
33         point3.add(getRandomPoint(polygonAverageSize));
34
35         final Color color = new Color(Math.random(), Math.random(),
36                 Math.random(), 0.5d);
37
38         final SolidPolygon polygon = new SolidPolygon(point1, point2, point3,
39                 color);
40         geometryCollection.addShape(polygon);
41     }
42
43     private static Point3D getRandomPoint(final double amplitude) {
44         return new Point3D((Math.random() * amplitude * 2d) - amplitude,
45                 (Math.random() * amplitude * 2d) - amplitude, (Math.random()
46                 * amplitude * 2d)
47                 - amplitude);
48     }
49
50     public static void main(final String[] args) {
51
52         final ViewFrame viewFrame = new ViewFrame();
53
54         final ShapeCollection shapeCollection = viewFrame.getView()
55                 .getContext().getRootShapeCollection();
56
57         // add grid
58         final LineAppearance appearance = new LineAppearance(5, new Color(100,
59                 100, 255, 60));
60
61         shapeCollection.addShape(new Grid3D(new Point3D(1000, -1000, -1000),
62                 new Point3D(-1000, 1000, 1000), 300, appearance));
63
64         // add random polygons
65         for (int i = 0; i < 3000; i++)
66             addRandomPolygon(shapeCollection);
67
68     }
69 }