2 * Sixth 3D engine demos. Copyright ©2012-2018, 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;
19 public class RandomPolygonsDemo {
21 private static final double POLYGON_AVERAGE_SIZE = 130;
22 private static final int POLYGON_COUNT = 1000;
24 private static void addRandomPolygon(final ShapeCollection geometryCollection) {
25 final Point3D polygonLocation = getRandomPoint(1000);
27 final Point3D point1 = new Point3D(polygonLocation);
28 point1.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
30 final Point3D point2 = new Point3D(polygonLocation);
31 point2.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
33 final Point3D point3 = new Point3D(polygonLocation);
34 point3.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
36 final Color color = new Color(
37 getColorChannelBrightness(),
38 getColorChannelBrightness(),
39 getColorChannelBrightness(),
42 final SolidPolygon polygon = new SolidPolygon(point1, point2, point3,
44 geometryCollection.addShape(polygon);
47 /* I don't want very dark polygons, so ensure there is at least some
48 * brightness present. */
49 private static double getColorChannelBrightness() {
50 return Math.random() * 0.7 + 0.3f;
53 private static Point3D getRandomPoint(final double amplitude) {
54 return new Point3D((Math.random() * amplitude * 2d) - amplitude,
55 (Math.random() * amplitude * 2d) - amplitude, (Math.random()
60 public static void main(final String[] args) {
62 final ViewFrame viewFrame = new ViewFrame();
64 final ShapeCollection shapeCollection = viewFrame.getViewPanel()
65 .getContext().getRootShapeCollection();
68 final LineAppearance appearance = new LineAppearance(5, new Color(100,
71 shapeCollection.addShape(new Grid3D(new Point3D(1000, -1000, -1000),
72 new Point3D(-1000, 1000, 1000), 300, appearance));
74 // add random polygons
75 for (int i = 0; i < POLYGON_COUNT; i++)
76 addRandomPolygon(shapeCollection);