Merged sphere demo and graph demo. Set default FPS to 60.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 21 May 2020 22:35:25 +0000 (01:35 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 21 May 2020 22:35:25 +0000 (01:35 +0300)
src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java [changed mode: 0644->0755]
src/main/java/eu/svjatoslav/sixth/e3d/examples/SphereDemo.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java

old mode 100644 (file)
new mode 100755 (executable)
index ce5f1c6..3639c10
@@ -9,8 +9,12 @@ package eu.svjatoslav.sixth.e3d.examples;
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
+import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
+import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
+import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Graph;
+import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeSphere;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -18,6 +22,40 @@ import java.util.List;
 
 public class GraphDemo {
 
+    private static final double WAVE_FREQUENCY = 50d;
+    private static final double WAVE_AMPLITUDE = 50d;
+    private static final Color SQUARE_PLATE_COLOR = new Color("88F7");
+
+    private static void makeSquarePlate(final ShapeCollection shapeCollection,
+                                        final double y, final double x, final double z) {
+        final Point3D p1 = new Point3D(x, y, z);
+        final Point3D p2 = new Point3D(x + 20, y, z);
+        final Point3D p3 = new Point3D(x, y, z + 20);
+        final Point3D p4 = new Point3D(x + 20, y, z + 20);
+        final SolidPolygon polygon1 = new SolidPolygon(p1, p2, p3, SQUARE_PLATE_COLOR);
+        final SolidPolygon polygon2 = new SolidPolygon(p4, p2, p3, SQUARE_PLATE_COLOR);
+        shapeCollection.addShape(polygon1);
+        shapeCollection.addShape(polygon2);
+    }
+
+    /**
+     * @param surfaceElevation surface total elevation
+     */
+    private static void addWobblySurface(final ShapeCollection shapeCollection,
+                                         final double surfaceElevation) {
+        for (double x = -500; x < 500; x += 20)
+            for (double z = -500; z < 500; z += 20) {
+
+                // use Pythagorean theorem to compute distance from the center
+                final double distanceFromCenter = Math.sqrt((x * x) + (z * z));
+
+                double plateElevation = Math.sin(distanceFromCenter / WAVE_FREQUENCY) * WAVE_AMPLITUDE;
+
+                makeSquarePlate(shapeCollection, plateElevation + surfaceElevation, x,
+                        z);
+            }
+    }
+
     private static final double scale = 50d;
 
     private static Graph getCosineGraph(final Point3D location) {
@@ -100,30 +138,51 @@ public class GraphDemo {
     public static void main(final String[] args) throws IOException {
 
         final ViewFrame viewFrame = new ViewFrame();
-
         final ShapeCollection geometryCollection = viewFrame.getViewPanel()
                 .getRootShapeCollection();
 
-        Point3D location = new Point3D(-600, -300, 0);
+        addMathFormulas(geometryCollection);
+        addSphere(geometryCollection);
+        addWobblySurface(geometryCollection, 200);
+        addWobblySurface(geometryCollection, -200);
+
+        setAvatarLocation(viewFrame);
+    }
+
+    private static void addSphere(ShapeCollection geometryCollection) {
+        // add sphere
+        geometryCollection.addShape(new WireframeSphere(new Point3D(0, 0, 0),
+                100,
+                new LineAppearance(
+                        4,
+                        new Color(255,0, 0, 30))
+        ));
+    }
+
+    private static void addMathFormulas(ShapeCollection geometryCollection) {
+        int z = 1000;
+        Point3D location = new Point3D(-600, -300, z);
         geometryCollection.addShape(getSineGraph(location));
 
-        location = new Point3D(600, -300, 0);
+        location = new Point3D(600, -300, z);
         geometryCollection.addShape(getFormula1Graph(location));
 
-        location = new Point3D(-600, 0, 0);
+        location = new Point3D(-600, 0, z);
         geometryCollection.addShape(getCosineGraph(location));
 
-        location = new Point3D(600, 0, 0);
+        location = new Point3D(600, 0, z);
         geometryCollection.addShape(getFormula2Graph(location));
 
-        location = new Point3D(-600, 300, 0);
+        location = new Point3D(-600, 300, z);
         geometryCollection.addShape(getTangentGraph(location));
 
-        location = new Point3D(600, 300, 0);
+        location = new Point3D(600, 300, z);
         geometryCollection.addShape(getFormula3Graph(location));
+    }
 
+    private static void setAvatarLocation(ViewFrame viewFrame) {
         viewFrame.getViewPanel().getAvatar()
                 .setLocation(new Point3D(0, 0, -500));
-
     }
+
 }
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/SphereDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/SphereDemo.java
deleted file mode 100755 (executable)
index 95be617..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Sixth 3D engine demos. Author: Svjatoslav Agejenko. 
- * This project is released under Creative Commons Zero (CC0) license.
- *
-*/
-
-package eu.svjatoslav.sixth.e3d.examples;
-
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
-import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
-import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
-import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
-import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
-import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon;
-import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeSphere;
-
-public class SphereDemo {
-
-    private static final double WAVE_FREQUENCY = 50d;
-    private static final double WAVE_AMPLITUDE = 50d;
-    private static final Color SQUARE_PLATE_COLOR = new Color("88F7");
-
-    private static void makeSquarePlate(final ShapeCollection shapeCollection,
-                                        final double y, final double x, final double z) {
-        final Point3D p1 = new Point3D(x, y, z);
-        final Point3D p2 = new Point3D(x + 20, y, z);
-        final Point3D p3 = new Point3D(x, y, z + 20);
-        final Point3D p4 = new Point3D(x + 20, y, z + 20);
-        final SolidPolygon polygon1 = new SolidPolygon(p1, p2, p3, SQUARE_PLATE_COLOR);
-        final SolidPolygon polygon2 = new SolidPolygon(p4, p2, p3, SQUARE_PLATE_COLOR);
-        shapeCollection.addShape(polygon1);
-        shapeCollection.addShape(polygon2);
-    }
-
-    /**
-     * @param surfaceElevation surface total elevation
-     */
-    private static void makeWobblySurface(final ShapeCollection shapeCollection,
-                                          final double surfaceElevation) {
-        for (double x = -500; x < 500; x += 20)
-            for (double z = -500; z < 500; z += 20) {
-
-                // use Pythagorean theorem to compute distance from the center
-                final double distanceFromCenter = Math.sqrt((x * x) + (z * z));
-
-                double plateElevation = Math.sin(distanceFromCenter / WAVE_FREQUENCY) * WAVE_AMPLITUDE;
-
-                makeSquarePlate(shapeCollection, plateElevation + surfaceElevation, x,
-                        z);
-            }
-    }
-
-    public static void main(final String[] args) {
-
-        final ViewFrame viewFrame = new ViewFrame();
-        final ViewPanel viewPanel = viewFrame.getViewPanel();
-
-        final ShapeCollection geometryCollection = viewPanel
-                .getRootShapeCollection();
-
-        final LineAppearance appearance = new LineAppearance(4, new Color(255,
-                0, 0, 30));
-
-        // add sphere
-        geometryCollection.addShape(new WireframeSphere(new Point3D(0, 0, 0),
-                100, appearance));
-
-        // create floor
-        makeWobblySurface(geometryCollection, 200);
-        makeWobblySurface(geometryCollection, -200);
-
-        viewPanel.getAvatar().setLocation(new Point3D(0, 0, -340));
-
-    }
-}
index 0590819..1499174 100644 (file)
@@ -23,7 +23,6 @@ class MenuPanel extends JPanel {
         sequentialGroup.addComponent(new JButton(new ShowMathGraphs()));
         sequentialGroup.addComponent(new JButton(new ShowPointCloud()));
         sequentialGroup.addComponent(new JButton(new ShowRain()));
-        sequentialGroup.addComponent(new JButton(new ShowSinusMap()));
         sequentialGroup.addComponent(new JButton(new ShowTextEditors()));
         sequentialGroup.addComponent(new JButton(new ShowGameOfLife()));
         sequentialGroup.addComponent(new JButton(new ShowRandomPolygons()));
@@ -40,16 +39,6 @@ class MenuPanel extends JPanel {
         }
     }
 
-    private class ShowSinusMap extends AbstractAction {
-        ShowSinusMap() {
-            putValue(NAME, "Wireframe sphere and ploygon landscape");
-        }
-
-        @Override
-        public void actionPerformed(final ActionEvent e) {
-            SphereDemo.main(null);
-        }
-    }
 
     private class ShowRain extends AbstractAction {
         ShowRain() {