From b8c0cce0cb4b7b9fc79da726c6595ab4060a3924 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 7 Mar 2023 20:11:43 +0200 Subject: [PATCH] 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