From f0ebc20d0438fc46be1d98fb3643bd4196cb64c9 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 29 May 2021 05:09:09 +0300 Subject: [PATCH 01/11] updated development scripts --- tools/commit and push | 4 +++- tools/debug | 46 ------------------------------------------- tools/update web site | 2 +- 3 files changed, 4 insertions(+), 48 deletions(-) delete mode 100755 tools/debug diff --git a/tools/commit and push b/tools/commit and push index 057b511..5931849 100755 --- a/tools/commit and push +++ b/tools/commit and push @@ -1,5 +1,7 @@ #!/bin/bash -cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi; + +cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -- "$0" T; exit; fi; + cd .. diff --git a/tools/debug b/tools/debug deleted file mode 100755 index 5640906..0000000 --- a/tools/debug +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi - -# -# This is a helper bash script that starts current Java project in debug mode -# with JRebel attached. It also opens its own terminal window, so you can run -# this script by simply clicking on it in file navigator. -# -# -# Script assumes: -# -# + GNU OS -# + Gnome workspace -# + JRebel is installed in /opt/jrebel -# - - -cd "${0%/*}" -cd .. - - -while true; do - - # clear screen - printf "\033c" - - # enable debugging - export DEBUG_OPTIONS="-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000,server=y,suspend=n" - - # enable JRebel - export REBEL_BASE="$HOME/.jrebel" - export JREBEL_OPTS="-agentpath:/opt/jrebel/libjrebel64.so -Drebel.project.path=`pwd`" - - # enable LWJGL native libraries - export LWJGL_OPTS="-Djava.library.path=target/natives" - - # define Maven options - export MAVEN_OPTS="-Xmx4000m $DEBUG_OPTIONS $JREBEL_OPTS $LWJGL_OPTS" - - mvn compile exec:java -Dexec.mainClass="eu.svjatoslav.sixth.e3d.examples.launcher.Main" - - echo "press ENTER to reload application" - read - -done diff --git a/tools/update web site b/tools/update web site index 7442ab6..49d31e4 100755 --- a/tools/update web site +++ b/tools/update web site @@ -1,5 +1,5 @@ #!/bin/bash -cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi; +cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -- "$0" T; exit; fi; cd .. -- 2.20.1 From 08719db537fae3645ca86f9ee6f8deba4dadf4f4 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 11 Jul 2022 22:14:30 +0300 Subject: [PATCH 02/11] Code refactoring. --- ...nuPanel.java => ApplicationListPanel.java} | 8 ++--- .../sixth/e3d/examples/launcher/Main.java | 33 ++++++++----------- .../examples/{life => life_demo}/Cell.java | 2 +- .../examples/{life => life_demo}/Main.java | 2 +- .../examples/{life => life_demo}/Matrix.java | 2 +- .../examples/{life => life_demo}/Star.java | 4 +-- 6 files changed, 23 insertions(+), 28 deletions(-) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/{MenuPanel.java => ApplicationListPanel.java} (94%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Cell.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Main.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Matrix.java (98%) rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{life => life_demo}/Star.java (95%) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java similarity index 94% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java index e620649..2b3b643 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/MenuPanel.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java @@ -11,10 +11,10 @@ import eu.svjatoslav.sixth.e3d.examples.*; import javax.swing.*; import java.awt.event.ActionEvent; -class MenuPanel extends JPanel { +class ApplicationListPanel extends JPanel { private static final long serialVersionUID = 2012721856427052560L; - MenuPanel() { + ApplicationListPanel() { final GroupLayout groupLayout = new GroupLayout(this); GroupLayout.SequentialGroup sequentialGroup = groupLayout.createSequentialGroup(); sequentialGroup.addComponent(new JLabel("Choose an example to launch:")); @@ -64,7 +64,7 @@ class MenuPanel extends JPanel { private static class ShowPointCloud extends AbstractAction { ShowPointCloud() { - putValue(NAME, "Pointcloud galaxy"); + putValue(NAME, "Point cloud galaxy"); } @Override @@ -113,7 +113,7 @@ class MenuPanel extends JPanel { @Override public void actionPerformed(final ActionEvent e) { - eu.svjatoslav.sixth.e3d.examples.life.Main.main(null); + eu.svjatoslav.sixth.e3d.examples.life_demo.Main.main(null); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java index 4d090f8..07e5c39 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java @@ -9,29 +9,24 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; import javax.swing.*; import java.awt.*; -class Main extends javax.swing.JFrame { - - private static final long serialVersionUID = -3679656169594556137L; - - private Main() { - super(); - initGUI(); - } +class Main { public static void main(final String[] args) { - SwingUtilities.invokeLater(() -> { - final Main inst = new Main(); - final BorderLayout instLayout = new BorderLayout(); - inst.setLocationRelativeTo(null); - inst.setVisible(true); - inst.getContentPane().setLayout(instLayout); - }); + buildAndShowGuiWindow(); } - private void initGUI() { - getContentPane().add(new MenuPanel()); - pack(); - setSize(390, 300); + private static void buildAndShowGuiWindow() { + JFrame frame = new JFrame("Sixth 3D engine demos"); + + // Keep application running until last frame is closed. + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + frame.getContentPane().setLayout(new BorderLayout()); + frame.getContentPane().add(new ApplicationListPanel(), BorderLayout.CENTER); + frame.setSize(400, 300); + + frame.setLocationRelativeTo(null); // center frame on screen + frame.setVisible(true); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java index fb78e4b..6b1ee8e 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java index afc0e1c..cf47e7f 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Main.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.geometry.Rectangle; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java similarity index 98% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java index ee7b0aa..8736b96 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Matrix.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Matrix.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java similarity index 95% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java index ad242d0..6f5edaa 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.sixth.e3d.examples.life; +package eu.svjatoslav.sixth.e3d.examples.life_demo; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; @@ -14,7 +14,7 @@ class Star extends GlowingPoint { private static final List uniqueStarColors = new ArrayList<>(); - /** + /* * A little hack to save RAM. We are going to have potentially lot of stars. * Instead of creating new individual texture for each star, Sixth 3D engine * uses internal optimization and reuses existing star textures, if star with -- 2.20.1 From 2f8d8ec0413d16c760140342b0207d5816fde0f5 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 13 Jul 2022 04:16:51 +0300 Subject: [PATCH 03/11] Fixed Maven repository URL. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f2ceeb..96ce3fb 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ svjatoslav.eu Svjatoslav repository - https://www2.svjatoslav.eu/maven/ + https://www3.svjatoslav.eu/maven/ -- 2.20.1 From 480d59637200df8010fe08533b8a1e4e4a651347 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 22 Feb 2023 23:27:31 +0200 Subject: [PATCH 04/11] Moved galaxy object to 3D engine demonstration project --- .../e3d/examples/galaxy_demo/Galaxy.java | 86 +++++++++++++++++++ .../{ => galaxy_demo}/PointCloudDemo.java | 3 +- .../launcher/ApplicationListPanel.java | 1 + 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100755 src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java rename src/main/java/eu/svjatoslav/sixth/e3d/examples/{ => galaxy_demo}/PointCloudDemo.java (87%) 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 index 0000000..30ea58d --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/Galaxy.java @@ -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 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/PointCloudDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java similarity index 87% rename from src/main/java/eu/svjatoslav/sixth/e3d/examples/PointCloudDemo.java rename to src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java index 8e36080..6ce037b 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/PointCloudDemo.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/galaxy_demo/PointCloudDemo.java @@ -4,13 +4,12 @@ * */ -package eu.svjatoslav.sixth.e3d.examples; +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; -import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.Galaxy; public class PointCloudDemo { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java index 2b3b643..ab41bf3 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/ApplicationListPanel.java @@ -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; -- 2.20.1 From 006585b5853331fe4e78699b5cdc70fd5fdccbc9 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 23 Feb 2023 00:12:04 +0200 Subject: [PATCH 05/11] Improved code readability --- .../sixth/e3d/examples/galaxy_demo/Galaxy.java | 15 ++++++++++++++- .../sixth/e3d/examples/launcher/Main.java | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 index 30ea58d..73764a9 100755 --- 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 @@ -18,6 +18,15 @@ import static java.lang.Math.*; public class Galaxy extends AbstractCompositeShape { + /** + * The number of unique colors used in the galaxy. + */ + public static final int UNIQUE_COLORS_COUNT = 30; + + /** + * A list of all colors used in the galaxy. + * Used to reuse textures of glowing points of the same color. + */ private static List colors; public Galaxy(final int galaxySize, final int tailCount, final int starsCount, @@ -69,12 +78,16 @@ public class Galaxy extends AbstractCompositeShape { addShape(new GlowingPoint(starLocation, size, colors.get((int) (random() * colors.size())))); } + /** + * Initializes the list of colors used in the galaxy. + * Used to reuse textures of glowing points of the same color. + */ private synchronized void ensureColorsAreInitialized() { if (colors != null) return; colors = new ArrayList<>(); - for (int i = 0; i < 30; i++) + for (int i = 0; i < UNIQUE_COLORS_COUNT; i++) colors.add( new Color( random() + 0.5, diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java index 07e5c39..f972085 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java @@ -9,12 +9,16 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; import javax.swing.*; import java.awt.*; + class Main { public static void main(final String[] args) { buildAndShowGuiWindow(); } + /** + * Builds and shows the main window of the application. + */ private static void buildAndShowGuiWindow() { JFrame frame = new JFrame("Sixth 3D engine demos"); -- 2.20.1 From 1caf289a151c0b20df3fc22c2662241145f0cddd Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 24 Feb 2023 23:57:39 +0200 Subject: [PATCH 06/11] Improved code readability. Components now aware of what mouse button was clicked. --- .../java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java index 6b1ee8e..6df2b59 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java @@ -98,7 +98,7 @@ class Cell extends AbstractCompositeShape implements } @Override - public boolean mouseClicked() { + public boolean mouseClicked(int button) { setActive(!isActive()); return true; } -- 2.20.1 From b55174d5b7de316ed8a6e2d5099ff0bf802b6375 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 1 Mar 2023 00:11:43 +0200 Subject: [PATCH 07/11] Updated readability of the code. --- .../java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java index 6df2b59..4faa448 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Cell.java @@ -73,7 +73,7 @@ class Cell extends AbstractCompositeShape implements } /** - * Compute cell color depending if cell is active and if mouse is over the + * Compute cell color depending on if cell is active and if mouse is over the * cell. */ private Color computeCellColor() { -- 2.20.1 From b8c0cce0cb4b7b9fc79da726c6595ab4060a3924 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 7 Mar 2023 20:11:43 +0200 Subject: [PATCH 08/11] Updated readability of the code. --- .../sixth/e3d/examples/OctreeDemo.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/OctreeDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/OctreeDemo.java index 7b733cb..e9979dc 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/OctreeDemo.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/OctreeDemo.java @@ -11,6 +11,7 @@ import eu.svjatoslav.sixth.e3d.gui.ViewFrame; import eu.svjatoslav.sixth.e3d.gui.ViewPanel; import eu.svjatoslav.sixth.e3d.gui.humaninput.WorldNavigationUserInputTracker; import eu.svjatoslav.sixth.e3d.math.Transform; +import eu.svjatoslav.sixth.e3d.renderer.octree.IntegerPoint; import eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume; import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera; import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.LightSource; @@ -75,7 +76,9 @@ public class OctreeDemo extends WorldNavigationUserInputTracker { final double c2 = (Math.cos(x / 10f) * 100f) + 127; final double c3 = (Math.cos(z / 12f) * 100f) + 127; - putRect(x - size, y - size, z - size, x + size, y + size, z + size, + putRect( + new IntegerPoint( x - size, y - size, z - size), + new IntegerPoint( x + size, y + size, z + size), new Color((int) c1, (int) c2, (int) c3, 100)); if (size > 1) { @@ -109,16 +112,24 @@ public class OctreeDemo extends WorldNavigationUserInputTracker { dotSpiral(); // arbitrary rectangles - putRect(-10, -10, -10, 10, 10, -20, new Color(200, 255, 200, 100)); - putRect(-3, 0, -30, 12, 3, 300, new Color(255, 200, 200, 100)); - putRect(-20, 20, -20, 20, 80, 20, new Color(255, 200, 255, 100)); + putRect(new IntegerPoint(-10, -10, -10), + new IntegerPoint(10, 10, -20), + new Color(200, 255, 200, 100)); + + putRect(new IntegerPoint(-3, 0, -30), + new IntegerPoint( 12, 3, 300), + new Color(255, 200, 200, 100)); + + putRect(new IntegerPoint(-20, 20, -20), + new IntegerPoint(20, 80, 20), + new Color(255, 200, 255, 100)); tiledFloor(); fractal(-50, 20, 100, 32, 1); final TextCanvas message = new TextCanvas(new Transform(new Point3D( - -10, 20, -180)), "Press \"r\" to raytrace current wiew", + -10, 20, -180)), "Press \"r\" to raytrace current view", Color.WHITE, Color.PURPLE); shapeCollection.addShape(message); @@ -144,15 +155,14 @@ public class OctreeDemo extends WorldNavigationUserInputTracker { } - private void putRect(final int x1, final int y1, final int z1, final int x2, - final int y2, final int z2, final Color color) { + private void putRect(IntegerPoint p1, IntegerPoint p2, final Color color) { shapeCollection .addShape(new SolidPolygonRectangularBox( - new Point3D(x1, y1, z1).scaleUp(magnification), - new Point3D(x2, y2, z2).scaleUp(magnification), color)); + new Point3D(p1).scaleUp(magnification), + new Point3D(p2).scaleUp(magnification), color)); - octreeVolume.fillRect3D(x1, y1, z1, x2, y2, z2, color); + octreeVolume.fillRectangle(p1, p2, color); } private void raytrace() { @@ -170,10 +180,13 @@ public class OctreeDemo extends WorldNavigationUserInputTracker { private void tiledFloor() { final int step = 40; final int size = step - 15; + Color color = new Color(255, 255, 255, 100); for (int x = -200; x < 200; x += step) for (int z = -200; z < 200; z += step) - putRect(x, 100, z, x + size, 110, z + size, new Color(255, 255, - 255, 100)); + putRect( + new IntegerPoint(x, 100, z), + new IntegerPoint(x + size, 110, z + size), + color); } } -- 2.20.1 From 2ae3d9cc65b75b3759ad733219eec0ccd60f70d5 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 21 Jun 2023 00:45:13 +0300 Subject: [PATCH 09/11] Improved code readability --- tools/open with IntelliJ IDEA | 60 ++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/tools/open with IntelliJ IDEA b/tools/open with IntelliJ IDEA index de9bae5..304bf94 100755 --- a/tools/open with IntelliJ IDEA +++ b/tools/open with IntelliJ IDEA @@ -1,18 +1,54 @@ #!/bin/bash -# -# This is a helper bash script that starts IntelliJ with the current project. -# Script is written is such a way that you can simply click on it in file -# navigator to run it. -# -# -# Script assumes: -# -# + GNU operating system -# + IntelliJ is installed and commandline launcher "idea" is enabled. -# +# This script launches IntelliJ IDEA with the current project +# directory. The script is designed to be run by double-clicking it in +# the GNOME Nautilus file manager. + +# First, we change the current working directory to the directory of +# the script. + +# "${0%/*}" gives us the path of the script itself, without the +# script's filename. + +# This command basically tells the system "change the current +# directory to the directory containing this script". cd "${0%/*}" + +# Then, we move up one directory level. +# The ".." tells the system to go to the parent directory of the current directory. +# This is done because we assume that the project directory is one level up from the script. cd .. -setsid idea . &>/dev/null +# Now, we use the 'setsid' command to start a new session and run +# IntelliJ IDEA in the background. 'setsid' is a UNIX command that +# runs a program in a new session. + +# The command 'idea .' opens IntelliJ IDEA with the current directory +# as the project directory. The '&' at the end is a UNIX command that +# runs the process in the background. The '> /dev/null' part tells +# the system to redirect all output (both stdout and stderr, denoted +# by '&') that would normally go to the terminal to go to /dev/null +# instead, which is a special file that discards all data written to +# it. + +setsid idea . &>/dev/null & + +# The 'disown' command is a shell built-in that removes a shell job +# from the shell's active list. Therefore, the shell will not send a +# SIGHUP to this particular job when the shell session is terminated. + +# '-h' option specifies that if the shell receives a SIGHUP, it also +# doesn't send a SIGHUP to the job. + +# '$!' is a shell special parameter that expands to the process ID of +# the most recent background job. +disown -h $! + + +sleep 2 + +# Finally, we use the 'exit' command to terminate the shell script. +# This command tells the system to close the terminal window after +# IntelliJ IDEA has been opened. +exit -- 2.20.1 From d5fe10f330481170112c7cc7576d181c982194e1 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 22 Jun 2023 00:19:36 +0300 Subject: [PATCH 10/11] Improved code readability --- .../eu/svjatoslav/sixth/e3d/examples/launcher/Main.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java index f972085..0d15f43 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/launcher/Main.java @@ -9,6 +9,9 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; import javax.swing.*; import java.awt.*; +import static java.awt.BorderLayout.CENTER; +import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; + class Main { @@ -23,10 +26,10 @@ class Main { JFrame frame = new JFrame("Sixth 3D engine demos"); // Keep application running until last frame is closed. - frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout()); - frame.getContentPane().add(new ApplicationListPanel(), BorderLayout.CENTER); + frame.getContentPane().add(new ApplicationListPanel(), CENTER); frame.setSize(400, 300); frame.setLocationRelativeTo(null); // center frame on screen -- 2.20.1 From 50fc2369de58d6430ec932a6877b88f9f70cf0da Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 27 Jul 2023 09:51:33 +0300 Subject: [PATCH 11/11] Improved code readability --- .../svjatoslav/sixth/e3d/examples/GraphDemo.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java index f644c3a..3dd9303 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java @@ -24,6 +24,7 @@ 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 final double GRAPH_SCALE = 50d; private static void makeSquarePlate(final ShapeCollection shapeCollection, final double y, final double x, final double z) { @@ -55,8 +56,6 @@ public class GraphDemo { } } - private static final double scale = 50d; - private static Graph getCosineGraph(final Point3D location) { final List data = new ArrayList<>(); for (double x = 0; x < 20; x += 0.25) { @@ -66,7 +65,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "Cosine", location); + return new Graph(GRAPH_SCALE, data, "Cosine", location); } private static Graph getFormula1Graph(final Point3D location) { @@ -78,7 +77,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "y = sin(tan(x))", location); + return new Graph(GRAPH_SCALE, data, "y = sin(tan(x))", location); } private static Graph getFormula2Graph(final Point3D location) { @@ -90,7 +89,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "y = ( (10-x)^2 ) / 30", location); + return new Graph(GRAPH_SCALE, data, "y = ( (10-x)^2 ) / 30", location); } private static Graph getFormula3Graph(final Point3D location) { @@ -102,7 +101,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "y = sin(x/2) + sin(x/1.26)", location); + return new Graph(GRAPH_SCALE, data, "y = sin(x/2) + sin(x/1.26)", location); } private static Graph getSineGraph(final Point3D location) { @@ -114,7 +113,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "Sine", location); + return new Graph(GRAPH_SCALE, data, "Sine", location); } private static Graph getTangentGraph(final Point3D location) { @@ -131,7 +130,7 @@ public class GraphDemo { data.add(p); } - return new Graph(scale, data, "Tangent", location); + return new Graph(GRAPH_SCALE, data, "Tangent", location); } public static void main(final String[] args) { -- 2.20.1