From: Svjatoslav Agejenko Date: Tue, 17 Mar 2026 18:58:11 +0000 (+0200) Subject: refactor(examples): rename GraphDemo to SineHeightmap X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=de3d2d13c125027f526d2fbdf5cfb63a958e260c;p=sixth-3d-demos.git refactor(examples): rename GraphDemo to SineHeightmap --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java deleted file mode 100755 index b35160b..0000000 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/GraphDemo.java +++ /dev/null @@ -1,116 +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.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; - -/** - * Demo showing a sine heightmap surface with a central wireframe sphere. - * Two wobbly surfaces are positioned above and below the sphere. - */ -public class GraphDemo { - - /** - * Creates a new GraphDemo instance. - */ - public GraphDemo() { - } - - /** Frequency of the wave pattern in the wobbly surfaces. */ - private static final double WAVE_FREQUENCY = 50d; - /** Amplitude of the wave pattern in the wobbly surfaces. */ - private static final double WAVE_AMPLITUDE = 50d; - /** Color for the square plates in the wobbly surfaces. */ - private static final Color SQUARE_PLATE_COLOR = new Color("88F7"); - /** Scale factor for the graph rendering. */ - private static final double GRAPH_SCALE = 50d; - - /** - * Creates a single square plate at the specified position. - * @param shapeCollection the collection to add the plate to - * @param y the Y coordinate (elevation) - * @param x the X coordinate - * @param z the Z coordinate - */ - 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); - } - - /** - * Creates a wobbly surface composed of square plates arranged in a wave pattern. - * @param shapeCollection the collection to add plates to - * @param surfaceElevation the base Y elevation of the surface - */ - 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) { - - final double distanceFromCenter = Math.sqrt((x * x) + (z * z)); - - double plateElevation = Math.sin(distanceFromCenter / WAVE_FREQUENCY) * WAVE_AMPLITUDE; - - makeSquarePlate(shapeCollection, plateElevation + surfaceElevation, x, - z); - } - } - - /** - * Entry point for the graph demo. - * @param args command line arguments (ignored) - */ - public static void main(final String[] args) { - - final ViewFrame viewFrame = new ViewFrame(); - final ShapeCollection geometryCollection = viewFrame.getViewPanel() - .getRootShapeCollection(); - - addSphere(geometryCollection); - addWobblySurface(geometryCollection, 200); - addWobblySurface(geometryCollection, -200); - - setCameraLocation(viewFrame); - - viewFrame.getViewPanel().ensureRenderThreadStarted(); - } - - /** - * Adds a wireframe sphere at the center of the scene. - * @param geometryCollection the collection to add the sphere to - */ - private static void addSphere(ShapeCollection geometryCollection) { - geometryCollection.addShape(new WireframeSphere(new Point3D(0, 0, 0), - 100, - new LineAppearance( - 4, - new Color(255,0, 0, 30)) - )); - } - - /** - * Sets the camera to an initial viewing position. - * @param viewFrame the view frame whose camera to configure - */ - private static void setCameraLocation(ViewFrame viewFrame) { - viewFrame.getViewPanel().getCamera().getTransform().setTranslation(new Point3D(0, 0, -500)); - } - -} diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/SineHeightmap.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/SineHeightmap.java new file mode 100755 index 0000000..91993f9 --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/SineHeightmap.java @@ -0,0 +1,116 @@ +/* + * 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.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; + +/** + * Demo showing a sine heightmap surface with a central wireframe sphere. + * Two wobbly surfaces are positioned above and below the sphere. + */ +public class SineHeightmap { + + /** + * Creates a new GraphDemo instance. + */ + public SineHeightmap() { + } + + /** Frequency of the wave pattern in the wobbly surfaces. */ + private static final double WAVE_FREQUENCY = 50d; + /** Amplitude of the wave pattern in the wobbly surfaces. */ + private static final double WAVE_AMPLITUDE = 50d; + /** Color for the square plates in the wobbly surfaces. */ + private static final Color SQUARE_PLATE_COLOR = new Color("88F7"); + /** Scale factor for the graph rendering. */ + private static final double GRAPH_SCALE = 50d; + + /** + * Creates a single square plate at the specified position. + * @param shapeCollection the collection to add the plate to + * @param y the Y coordinate (elevation) + * @param x the X coordinate + * @param z the Z coordinate + */ + 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); + } + + /** + * Creates a wobbly surface composed of square plates arranged in a wave pattern. + * @param shapeCollection the collection to add plates to + * @param surfaceElevation the base Y elevation of the surface + */ + 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) { + + final double distanceFromCenter = Math.sqrt((x * x) + (z * z)); + + double plateElevation = Math.sin(distanceFromCenter / WAVE_FREQUENCY) * WAVE_AMPLITUDE; + + makeSquarePlate(shapeCollection, plateElevation + surfaceElevation, x, + z); + } + } + + /** + * Entry point for the graph demo. + * @param args command line arguments (ignored) + */ + public static void main(final String[] args) { + + final ViewFrame viewFrame = new ViewFrame(); + final ShapeCollection geometryCollection = viewFrame.getViewPanel() + .getRootShapeCollection(); + + addSphere(geometryCollection); + addWobblySurface(geometryCollection, 200); + addWobblySurface(geometryCollection, -200); + + setCameraLocation(viewFrame); + + viewFrame.getViewPanel().ensureRenderThreadStarted(); + } + + /** + * Adds a wireframe sphere at the center of the scene. + * @param geometryCollection the collection to add the sphere to + */ + private static void addSphere(ShapeCollection geometryCollection) { + geometryCollection.addShape(new WireframeSphere(new Point3D(0, 0, 0), + 100, + new LineAppearance( + 4, + new Color(255,0, 0, 30)) + )); + } + + /** + * Sets the camera to an initial viewing position. + * @param viewFrame the view frame whose camera to configure + */ + private static void setCameraLocation(ViewFrame viewFrame) { + viewFrame.getViewPanel().getCamera().getTransform().setTranslation(new Point3D(0, 0, -500)); + } + +} 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 3af0262..272261d 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 @@ -6,7 +6,7 @@ package eu.svjatoslav.sixth.e3d.examples.launcher; -import eu.svjatoslav.sixth.e3d.examples.GraphDemo; +import eu.svjatoslav.sixth.e3d.examples.SineHeightmap; import eu.svjatoslav.sixth.e3d.examples.MathGraphsDemo; import eu.svjatoslav.sixth.e3d.examples.MinimalExample; import eu.svjatoslav.sixth.e3d.examples.OctreeDemo; @@ -184,7 +184,7 @@ class ApplicationListPanel extends JPanel { @Override public void actionPerformed(final ActionEvent e) { - GraphDemo.main(null); + SineHeightmap.main(null); } }