2 * Sixth 3D engine demos. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.sixth.e3d.examples;
9 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
10 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid3D;
17 public class RandomPolygonsDemo {
19 private static final double POLYGON_AVERAGE_SIZE = 130;
20 private static final int POLYGON_COUNT = 1000;
22 private static void addRandomPolygon(final ShapeCollection geometryCollection) {
23 final Point3D polygonLocation = getRandomPoint(1000);
25 final Point3D point1 = new Point3D(polygonLocation);
26 point1.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
28 final Point3D point2 = new Point3D(polygonLocation);
29 point2.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
31 final Point3D point3 = new Point3D(polygonLocation);
32 point3.add(getRandomPoint(POLYGON_AVERAGE_SIZE));
34 final Color color = new Color(
35 getColorChannelBrightness(),
36 getColorChannelBrightness(),
37 getColorChannelBrightness(),
40 final SolidPolygon polygon = new SolidPolygon(point1, point2, point3,
42 geometryCollection.addShape(polygon);
45 /* I don't want very dark polygons, so ensure there is at least some
46 * brightness present. */
47 private static double getColorChannelBrightness() {
48 return Math.random() * 0.7 + 0.3f;
51 private static Point3D getRandomPoint(final double amplitude) {
52 return new Point3D((Math.random() * amplitude * 2d) - amplitude,
53 (Math.random() * amplitude * 2d) - amplitude, (Math.random()
58 public static void main(final String[] args) {
60 final ViewFrame viewFrame = new ViewFrame();
62 final ShapeCollection shapeCollection = viewFrame.getViewPanel()
63 .getRootShapeCollection();
66 final LineAppearance appearance = new LineAppearance(5, new Color(100,
69 shapeCollection.addShape(new Grid3D(new Point3D(1000, -1000, -1000),
70 new Point3D(-1000, 1000, 1000), 300, appearance));
72 // add random polygons
73 for (int i = 0; i < POLYGON_COUNT; i++)
74 addRandomPolygon(shapeCollection);