6821cb57613aabc8d4d3c8f92af1ac63cfeb961c
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / GridSpace.java
1 /*
2  * Sixth - System for data storage, computation, exploration and interaction.
3  * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.sixth.e3d.examples;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid3D;
19
20 class GridSpace {
21
22     private static void addRandomPolygon(final ShapeCollection geometryCollection) {
23         final Point3D polygonLocation = getRandomPoint(1000);
24
25         final double polygonAverageSize = 30;
26
27         final Point3D point1 = new Point3D(polygonLocation);
28         point1.add(getRandomPoint(polygonAverageSize));
29
30         final Point3D point2 = new Point3D(polygonLocation);
31         point2.add(getRandomPoint(polygonAverageSize));
32
33         final Point3D point3 = new Point3D(polygonLocation);
34         point3.add(getRandomPoint(polygonAverageSize));
35
36         final Color color = new Color(Math.random(), Math.random(),
37                 Math.random(), 0.5d);
38
39         final SolidPolygon polygon = new SolidPolygon(point1, point2, point3,
40                 color);
41         geometryCollection.addShape(polygon);
42     }
43
44     private static Point3D getRandomPoint(final double amplitude) {
45         return new Point3D((Math.random() * amplitude * 2d) - amplitude,
46                 (Math.random() * amplitude * 2d) - amplitude, (Math.random()
47                 * amplitude * 2d)
48                 - amplitude);
49     }
50
51     public static void main(final String[] args) {
52
53         final ViewFrame viewFrame = new ViewFrame();
54
55         final ShapeCollection shapeCollection = viewFrame.getView()
56                 .getContext().getRootShapeCollection();
57
58         // add grid
59         final LineAppearance appearance = new LineAppearance(5, new Color(100,
60                 100, 255, 60));
61
62         shapeCollection.addShape(new Grid3D(new Point3D(1000, -1000, -1000),
63                 new Point3D(-1000, 1000, 1000), 300, appearance));
64
65         // add random polygons
66         for (int i = 0; i < 3000; i++)
67             addRandomPolygon(shapeCollection);
68
69     }
70 }