Moved galaxy object to 3D engine demonstration project
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 22 Feb 2023 21:27:31 +0000 (23:27 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 22 Feb 2023 21:27:31 +0000 (23:27 +0200)
src/main/java/eu/svjatoslav/sixth/e3d/examples/PointCloudDemo.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java

diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/PointCloudDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/PointCloudDemo.java
deleted file mode 100644 (file)
index 8e36080..0000000
+++ /dev/null
@@ -1,30 +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.math.Transform;
-import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
-import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Galaxy;
-
-public class PointCloudDemo {
-
-    public static void main(final String[] args) {
-
-        final ViewFrame viewFrame = new ViewFrame();
-
-        final ShapeCollection geometryCollection = viewFrame.getViewPanel()
-                .getRootShapeCollection();
-
-        Transform transform = new Transform(new Point3D(0, -1000, 1000), 0, 0);
-
-        // add galaxy
-        geometryCollection.addShape(new Galaxy(500, 3, 10000, transform));
-
-    }
-}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java
new file mode 100755 (executable)
index 0000000..30ea58d
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.sixth.e3d.examples.galaxy_demo;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
+import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
+import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import static java.lang.Math.*;
+
+public class Galaxy extends AbstractCompositeShape {
+
+    private static List<Color> colors;
+
+    public Galaxy(final int galaxySize, final int tailCount, final int starsCount,
+                  Transform transform) {
+
+        super(transform);
+
+        ensureColorsAreInitialized();
+
+        final double angle1 = random() * 10;
+        final double angle2 = random() * 10;
+
+        final double angleSin1 = sin(angle1);
+        final double angleCos1 = cos(angle1);
+        final double angleSin2 = sin(angle2);
+        final double angleCos2 = cos(angle2);
+
+        Random random = new Random();
+
+        double starSize = galaxySize / 70d;
+
+        for (int i = 1; i < starsCount; i++) {
+            final double b = random() * 10;
+
+            final double s = (b * b) / 30;
+
+            final double v1 = (random() * (11.5 - b)) / 3;
+            final double v1p = v1 / 2;
+
+            final double ane = ((random() * (s / 2)) / tailCount) * 2;
+            final double sba = ((2 * PI) / tailCount)
+                    * random.nextInt(tailCount);
+
+            final double x = (((sin((b - sba) + ane) * s) + (random() * v1)) - v1p) * galaxySize;
+            final double z = (((cos((b - sba) + ane) * s) + (random() * v1)) - v1p) * galaxySize;
+            final double y = ((random() * v1) - v1p) * galaxySize;
+
+            final double x1 = (x * angleCos1) + (z * angleSin1);
+            final double z1 = (z * angleCos1) - (x * angleSin1);
+
+            final double y1 = (y * angleCos2) + (z1 * angleSin2);
+            final double z2 = (z1 * angleCos2) - (y * angleSin2);
+
+            addStar(new Point3D(x1, y1, z2), starSize);
+        }
+    }
+
+    private void addStar(final Point3D starLocation, double size) {
+        addShape(new GlowingPoint(starLocation, size, colors.get((int) (random() * colors.size()))));
+    }
+
+    private synchronized void ensureColorsAreInitialized() {
+        if (colors != null) return;
+
+        colors = new ArrayList<>();
+
+        for (int i = 0; i < 30; i++)
+            colors.add(
+                    new Color(
+                            random() + 0.5,
+                            random() + 0.5,
+                            random() + 0.5,
+                            255));
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java
new file mode 100644 (file)
index 0000000..6ce037b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Sixth 3D engine demos. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
+ *
+*/
+
+package eu.svjatoslav.sixth.e3d.examples.galaxy_demo;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
+
+public class PointCloudDemo {
+
+    public static void main(final String[] args) {
+
+        final ViewFrame viewFrame = new ViewFrame();
+
+        final ShapeCollection geometryCollection = viewFrame.getViewPanel()
+                .getRootShapeCollection();
+
+        Transform transform = new Transform(new Point3D(0, -1000, 1000), 0, 0);
+
+        // add galaxy
+        geometryCollection.addShape(new Galaxy(500, 3, 10000, transform));
+
+    }
+}
index 2b3b643..ab41bf3 100644 (file)
@@ -7,6 +7,7 @@
 package eu.svjatoslav.sixth.e3d.examples.launcher;
 
 import eu.svjatoslav.sixth.e3d.examples.*;
+import eu.svjatoslav.sixth.e3d.examples.galaxy_demo.PointCloudDemo;
 
 import javax.swing.*;
 import java.awt.event.ActionEvent;