2 * Sixth 3D engine demos. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
9 package eu.svjatoslav.sixth.e3d.examples;
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;
21 private static void addRandomPolygon(final ShapeCollection geometryCollection) {
22 final Point3D polygonLocation = getRandomPoint(1000);
24 final double polygonAverageSize = 30;
26 final Point3D point1 = new Point3D(polygonLocation);
27 point1.add(getRandomPoint(polygonAverageSize));
29 final Point3D point2 = new Point3D(polygonLocation);
30 point2.add(getRandomPoint(polygonAverageSize));
32 final Point3D point3 = new Point3D(polygonLocation);
33 point3.add(getRandomPoint(polygonAverageSize));
35 final Color color = new Color(Math.random(), Math.random(),
38 final SolidPolygon polygon = new SolidPolygon(point1, point2, point3,
40 geometryCollection.addShape(polygon);
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()
50 public static void main(final String[] args) {
52 final ViewFrame viewFrame = new ViewFrame();
54 final ShapeCollection shapeCollection = viewFrame.getView()
55 .getContext().getRootShapeCollection();
58 final LineAppearance appearance = new LineAppearance(5, new Color(100,
61 shapeCollection.addShape(new Grid3D(new Point3D(1000, -1000, -1000),
62 new Point3D(-1000, 1000, 1000), 300, appearance));
64 // add random polygons
65 for (int i = 0; i < 3000; i++)
66 addRandomPolygon(shapeCollection);