From e56f9b775bd49c31e8efab7204bee699036942b3 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 14 Jul 2018 03:11:01 +0300 Subject: [PATCH] Code cleanup and formatting. --- .../sixth/e3d/geometry/Point2D.java | 2 +- .../sixth/e3d/geometry/Point3D.java | 6 +- .../eu/svjatoslav/sixth/e3d/gui/Avatar.java | 11 +-- .../sixth/e3d/gui/GuiComponent.java | 2 +- .../sixth/e3d/gui/RenderingContext.java | 9 +- .../svjatoslav/sixth/e3d/gui/TextPointer.java | 6 +- .../sixth/e3d/gui/UserRelativityTracker.java | 2 +- .../svjatoslav/sixth/e3d/gui/ViewPanel.java | 45 ++++----- .../sixth/e3d/gui/ViewRenderListener.java | 4 +- .../gui/textEditorComponent/Character.java | 4 +- .../TextEditComponent.java | 5 +- .../e3d/gui/textEditorComponent/TextLine.java | 4 +- .../e3d/renderer/octree/package-info.java | 6 +- .../e3d/renderer/octree/raytracer/Camera.java | 2 +- .../renderer/octree/raytracer/RayTracer.java | 99 +++++++++---------- .../octree/raytracer/package-info.java | 4 +- .../sixth/e3d/renderer/package-info.java | 4 +- .../e3d/renderer/raster/package-info.java | 8 +- .../shapes/AbstractCoordinateShape.java | 6 +- .../renderer/raster/shapes/AbstractShape.java | 2 +- .../shapes/basic/ForwardOrientedTexture.java | 2 +- .../raster/shapes/basic/GlowingPoint.java | 2 +- .../basic/solidpolygon/LineInterpolator.java | 6 +- .../raster/shapes/composite/Graph.java | 14 ++- .../base/AbstractCompositeShape.java | 6 +- .../composite/textcanvas/TextCanvas.java | 4 +- 26 files changed, 109 insertions(+), 156 deletions(-) diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java index 1cfd39c..d650a9e 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java @@ -34,7 +34,7 @@ public class Point2D implements Cloneable { return this; } - public boolean isZero(){ + public boolean isZero() { return (x == 0) && (y == 0); } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java index 462f310..4cae6ae 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -9,9 +9,7 @@ package eu.svjatoslav.sixth.e3d.geometry; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; +import static java.lang.Math.*; /** * Used to represent point in a 3D space or vector. @@ -74,7 +72,7 @@ public class Point3D extends Point2D implements Cloneable { } @Override - public boolean isZero(){ + public boolean isZero() { return (x == 0) && (y == 0) && (z == 0); } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java index 8dae301..52d78b2 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java @@ -21,6 +21,10 @@ public class Avatar implements ViewRenderListener { * Just in case we want to adjust global speed for some reason. */ private static final double SPEED_MULTIPLIER = .02d; + /** + * Determines amount of friction user experiences every millisecond while moving around in space. + */ + private static final double MILLISECOND_FRICTION = 1.005; /** * Avatar movement speed, relative to avatar itself. When avatar coordinates * are updated within the world, avatar orientation relative to the world is @@ -32,23 +36,16 @@ public class Avatar implements ViewRenderListener { * Avatar location within the 3D world. */ private Point3D location = new Point3D(); - /** * Avatar orientation on the X-Z plane. It changes when turning left or * right. */ private double orientationXZ; - /** * Avatar orientation on the Y-Z plane. It changes when looking up or down. */ private double orientationYZ; - /** - * Determines amount of friction user experiences every millisecond while moving around in space. - */ - private static final double MILLISECOND_FRICTION = 1.005; - public Avatar() { } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/GuiComponent.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/GuiComponent.java index 15e2d77..64dc879 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/GuiComponent.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/GuiComponent.java @@ -11,10 +11,10 @@ package eu.svjatoslav.sixth.e3d.gui; import eu.svjatoslav.sixth.e3d.geometry.Box; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputHandler; import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper; +import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeBox; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java index 91b7376..afbe22d 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java @@ -20,21 +20,14 @@ import java.awt.image.WritableRaster; public class RenderingContext { public static final int bufferedImageType = BufferedImage.TYPE_4BYTE_ABGR; - - final BufferedImage bufferedImage; - public final Graphics2D graphics; - public final byte[] pixels; - public final int width; public final int height; - public final int xCenter; public final int yCenter; - public final double zoom; - + final BufferedImage bufferedImage; public int frameNumber = 0; /** diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java index 0cf3610..3dc7201 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java @@ -49,12 +49,8 @@ public class TextPointer implements Comparable { if (textPointer.row < row) return 1; - if (textPointer.column > column) - return -1; - if (textPointer.column < column) - return 1; + return Integer.compare(column, textPointer.column); - return 0; } public boolean isBetween(final TextPointer start, final TextPointer end) { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java index 175c10a..8708398 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java @@ -10,8 +10,8 @@ package eu.svjatoslav.sixth.e3d.gui; -import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate; import eu.svjatoslav.sixth.e3d.geometry.Point3D; +import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate; import eu.svjatoslav.sixth.e3d.math.TransformPipe; public class UserRelativityTracker { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java index f38d3c0..2c6afe2 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java @@ -23,33 +23,12 @@ import java.util.List; import java.util.Timer; public class ViewPanel extends JPanel implements ComponentListener { + private static final long serialVersionUID = 1683277888885045387L; private final UserInputTracker userInputTracker = new UserInputTracker(this); - private final KeyboardFocusTracker keyboardFocusTracker = new KeyboardFocusTracker( this); - private final Avatar avatar = new Avatar(); - private final ShapeCollection rootShapeCollection = new ShapeCollection(); - - - public Avatar getAvatar() { - return avatar; - } - - public KeyboardFocusTracker getKeyboardFocusTracker() { - return keyboardFocusTracker; - } - - public ShapeCollection getRootShapeCollection() { - return rootShapeCollection; - } - - public UserInputTracker getUserInputTracker() { - return userInputTracker; - } - - private static final long serialVersionUID = 1683277888885045387L; private final List viewRenderListeners = new ArrayList<>(); /** * Last time this view was updated. @@ -58,24 +37,20 @@ public class ViewPanel extends JPanel implements ComponentListener { private Timer canvasUpdateTimer; private ViewUpdateTimerTask canvasUpdateTimerTask; private RenderingContext renderingContext = null; - /** * UI component that mouse is currently hovering over. */ private MouseInteractionController currentMouseOverComponent; - /** * Currently target FPS for this view. It can be changed at runtime. Also when nothing * changes in the view, then frames are not really repainted. */ private int targetFPS = 30; - /** * Set to true if it is known than next frame reeds to be painted. Flag is cleared * immediately after frame got updated. */ private boolean viewRepaintNeeded = true; - public ViewPanel() { viewRenderListeners.add(avatar); viewRenderListeners.add(userInputTracker); @@ -87,6 +62,22 @@ public class ViewPanel extends JPanel implements ComponentListener { addComponentListener(this); } + public Avatar getAvatar() { + return avatar; + } + + public KeyboardFocusTracker getKeyboardFocusTracker() { + return keyboardFocusTracker; + } + + public ShapeCollection getRootShapeCollection() { + return rootShapeCollection; + } + + public UserInputTracker getUserInputTracker() { + return userInputTracker; + } + public void addViewUpdateListener(final ViewRenderListener listener) { viewRenderListeners.add(listener); } @@ -240,7 +231,7 @@ public class ViewPanel extends JPanel implements ComponentListener { * graphics is needed. */ public void updateView() { - if (renderingContext != null){ + if (renderingContext != null) { renderingContext.mouseClick = null; renderingContext.clickedItem = null; } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java index 5444852..a36b77b 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java @@ -14,9 +14,9 @@ public interface ViewRenderListener { /** * Notifies that it is about time to render next frame and * allows listener to do any related processing that it needs to. - * + *

* Each {@link ViewRenderListener} will be notified exactly once before every frame is rendered. - * + *

* {@link ViewRenderListener} can determine if frame repaint is actually * needed from its perspective. Frame will be rendered only if at least one listener says yes. * diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Character.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Character.java index f22995f..b7d96af 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Character.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Character.java @@ -19,7 +19,7 @@ public class Character { this.value = value; } - boolean isEmpty() { - return value == ' '; + boolean hasValue() { + return value != ' '; } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java index bba0717..ee4def7 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java @@ -10,10 +10,10 @@ package eu.svjatoslav.sixth.e3d.gui.textEditorComponent; import eu.svjatoslav.sixth.e3d.geometry.Point2D; -import eu.svjatoslav.sixth.e3d.gui.ViewPanel; -import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.gui.GuiComponent; import eu.svjatoslav.sixth.e3d.gui.TextPointer; +import eu.svjatoslav.sixth.e3d.gui.ViewPanel; +import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas; @@ -360,7 +360,6 @@ public class TextEditComponent extends GuiComponent implements ClipboardOwner { } cursorLocation.column = 0; - return; } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextLine.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextLine.java index a8a3de6..a8f2129 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextLine.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextLine.java @@ -107,7 +107,7 @@ public class TextLine { return 0; for (int i = 0; i < chars.size(); i++) - if (!chars.get(i).isEmpty()) + if (chars.get(i).hasValue()) return i; throw new RuntimeException("This code shall never execute"); @@ -172,7 +172,7 @@ public class TextLine { int newLength = 0; for (int i = chars.size() - 1; i >= 0; i--) - if (!chars.get(i).isEmpty()) { + if (chars.get(i).hasValue()) { newLength = i + 1; break; } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/package-info.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/package-info.java index 035c862..4ee1b48 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/package-info.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/package-info.java @@ -5,11 +5,9 @@ * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. * + * Realtime voxel renderer (in software). + * Uses octree for data compression. */ package eu.svjatoslav.sixth.e3d.renderer.octree; -/** - * Realtime voxel renderer (in software). - * Uses octree for data compression. - */ diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/Camera.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/Camera.java index e4dd649..84fbb6a 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/Camera.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/Camera.java @@ -10,8 +10,8 @@ package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.gui.Avatar; +import eu.svjatoslav.sixth.e3d.math.Transform; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java index 35ec06b..79ae21c 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/RayTracer.java @@ -107,36 +107,29 @@ public class RayTracer implements Runnable { texture.resetResampledBitmapCache(); viewPanel.repaintDuringNextViewUpdate(); - // System.out.println("Raytracing done."); - // System.out.println("New lights computed:" + computedLights); } - public int traceLight(final LightSource l, final int cubeX, - final int cubeY, final int cubeZ) { - return 0; - } - - public int traceRay(final Ray r) { + private int traceRay(final Ray ray) { - final int re = octreeVolume.traceCell(0, 0, 0, - octreeVolume.masterCellSize, 0, r); + final int intersectingCell = octreeVolume.traceCell(0, 0, 0, + octreeVolume.masterCellSize, 0, ray); - if (re != -1) { + if (intersectingCell != -1) { // if lightening not computed, compute it - if (octreeVolume.ce3[re] == -1) + if (octreeVolume.ce3[intersectingCell] == -1) // if cell is larger than 1 - if (r.hitCellSize > 1) { + if (ray.hitCellSize > 1) { // break it up - octreeVolume.breakSolidCell(re); - return traceRay(r); + octreeVolume.breakSolidCell(intersectingCell); + return traceRay(ray); } else { computedLights++; float red = 30, green = 30, blue = 30; for (final LightSource l : lights) { - final int xDist = (l.x - r.hitCellX); - final int yDist = (l.y - r.hitCellY); - final int zDist = (l.z - r.hitCellZ); + final int xDist = (l.x - ray.hitCellX); + final int yDist = (l.y - ray.hitCellY); + final int zDist = (l.z - ray.hitCellZ); double newRed = 0, newGreen = 0, newBlue = 0; double tempRed, tempGreen, tempBlue; @@ -145,12 +138,12 @@ public class RayTracer implements Runnable { + (yDist * yDist) + (zDist * zDist)); distance = (distance / 3) + 1; - final Ray r1 = new Ray(r.hitCellX, r.hitCellY - - (float) 1.5, r.hitCellZ, + final Ray r1 = new Ray(ray.hitCellX, ray.hitCellY + - (float) 1.5, ray.hitCellZ, - (float) l.x - (float) r.hitCellX, l.y - - (r.hitCellY - (float) 1.5), (float) l.z - - (float) r.hitCellZ); + (float) l.x - (float) ray.hitCellX, l.y + - (ray.hitCellY - (float) 1.5), (float) l.z + - (float) ray.hitCellZ); final int rt1 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r1); @@ -161,12 +154,12 @@ public class RayTracer implements Runnable { newBlue = (l.color.b * l.brightness) / distance; } - final Ray r2 = new Ray(r.hitCellX - (float) 1.5, - r.hitCellY, r.hitCellZ, + final Ray r2 = new Ray(ray.hitCellX - (float) 1.5, + ray.hitCellY, ray.hitCellZ, - l.x - (r.hitCellX - (float) 1.5), (float) l.y - - (float) r.hitCellY, (float) l.z - - (float) r.hitCellZ); + l.x - (ray.hitCellX - (float) 1.5), (float) l.y + - (float) ray.hitCellY, (float) l.z + - (float) ray.hitCellZ); final int rt2 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r2); @@ -184,12 +177,12 @@ public class RayTracer implements Runnable { newBlue = tempBlue; } - final Ray r3 = new Ray(r.hitCellX, r.hitCellY, - r.hitCellZ - (float) 1.5, + final Ray r3 = new Ray(ray.hitCellX, ray.hitCellY, + ray.hitCellZ - (float) 1.5, - (float) l.x - (float) r.hitCellX, (float) l.y - - (float) r.hitCellY, l.z - - (r.hitCellZ - (float) 1.5)); + (float) l.x - (float) ray.hitCellX, (float) l.y + - (float) ray.hitCellY, l.z + - (ray.hitCellZ - (float) 1.5)); final int rt3 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r3); @@ -206,12 +199,12 @@ public class RayTracer implements Runnable { newBlue = tempBlue; } - final Ray r4 = new Ray(r.hitCellX, r.hitCellY - + (float) 1.5, r.hitCellZ, + final Ray r4 = new Ray(ray.hitCellX, ray.hitCellY + + (float) 1.5, ray.hitCellZ, - (float) l.x - (float) r.hitCellX, l.y - - (r.hitCellY + (float) 1.5), (float) l.z - - (float) r.hitCellZ); + (float) l.x - (float) ray.hitCellX, l.y + - (ray.hitCellY + (float) 1.5), (float) l.z + - (float) ray.hitCellZ); final int rt4 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r4); @@ -228,12 +221,12 @@ public class RayTracer implements Runnable { newBlue = tempBlue; } - final Ray r5 = new Ray(r.hitCellX + (float) 1.5, - r.hitCellY, r.hitCellZ, + final Ray r5 = new Ray(ray.hitCellX + (float) 1.5, + ray.hitCellY, ray.hitCellZ, - l.x - (r.hitCellX + (float) 1.5), (float) l.y - - (float) r.hitCellY, (float) l.z - - (float) r.hitCellZ); + l.x - (ray.hitCellX + (float) 1.5), (float) l.y + - (float) ray.hitCellY, (float) l.z + - (float) ray.hitCellZ); final int rt5 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r5); @@ -250,12 +243,12 @@ public class RayTracer implements Runnable { newBlue = tempBlue; } - final Ray r6 = new Ray(r.hitCellX, r.hitCellY, - r.hitCellZ + (float) 1.5, + final Ray r6 = new Ray(ray.hitCellX, ray.hitCellY, + ray.hitCellZ + (float) 1.5, - (float) l.x - (float) r.hitCellX, (float) l.y - - (float) r.hitCellY, l.z - - (r.hitCellZ + (float) 1.5)); + (float) l.x - (float) ray.hitCellX, (float) l.y + - (float) ray.hitCellY, l.z + - (ray.hitCellZ + (float) 1.5)); final int rt6 = octreeVolume.traceCell(0, 0, 0, octreeVolume.masterCellSize, 0, r6); @@ -277,7 +270,7 @@ public class RayTracer implements Runnable { } - final int cellColor = octreeVolume.ce2[re]; + final int cellColor = octreeVolume.ce2[intersectingCell]; red = (red * ((cellColor & 0xFF0000) >> 16)) / 255; green = (green * ((cellColor & 0xFF00) >> 8)) / 255; @@ -290,13 +283,13 @@ public class RayTracer implements Runnable { if (blue > 255) blue = 255; - octreeVolume.ce3[re] = (((int) red) << 16) + octreeVolume.ce3[intersectingCell] = (((int) red) << 16) + (((int) green) << 8) + ((int) blue); } - if (octreeVolume.ce3[re] == 0) - return octreeVolume.ce2[re]; - return octreeVolume.ce3[re]; + if (octreeVolume.ce3[intersectingCell] == 0) + return octreeVolume.ce2[intersectingCell]; + return octreeVolume.ce3[intersectingCell]; } // return (200 << 16) + (200 << 8) + 255; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/package-info.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/package-info.java index b99cb5c..6dd7832 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/package-info.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/package-info.java @@ -5,10 +5,8 @@ * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. * + * Raytracer through voxel data. */ package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer; -/** - * Raytracer through voxel data. - */ diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/package-info.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/package-info.java index 5cfba3b..284685d 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/package-info.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/package-info.java @@ -5,10 +5,8 @@ * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. * + * Various 3D renderers utilizing different rendering approaches. */ package eu.svjatoslav.sixth.e3d.renderer; -/** - * Various 3D renderers utilizing different rendering approaches. - */ diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/package-info.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/package-info.java index 89d1c68..0af46f7 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/package-info.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/package-info.java @@ -5,11 +5,6 @@ * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. * - */ - -package eu.svjatoslav.sixth.e3d.renderer.raster; - -/** *

  * Realtime renderer (in software) using traditional approaches:
  *      Wireframe
@@ -17,3 +12,6 @@ package eu.svjatoslav.sixth.e3d.renderer.raster;
  *      Z-Buffer
  * 
*/ + +package eu.svjatoslav.sixth.e3d.renderer.raster; + diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java index 97ffc7b..4e36d2e 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java @@ -9,10 +9,10 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes; -import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; +import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate; +import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator; import java.util.concurrent.atomic.AtomicInteger; @@ -21,8 +21,8 @@ public abstract class AbstractCoordinateShape extends AbstractShape { public static final AtomicInteger lastShapeId = new AtomicInteger(); public final int shapeId; + public final GeometryCoordinate[] coordinates; public double onScreenZ; - public GeometryCoordinate[] coordinates; public AbstractCoordinateShape(final int pointsCount) { coordinates = new GeometryCoordinate[pointsCount]; diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractShape.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractShape.java index c33ceb7..fe44afc 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractShape.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractShape.java @@ -9,9 +9,9 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes; -import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; +import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator; public abstract class AbstractShape { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/ForwardOrientedTexture.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/ForwardOrientedTexture.java index 4d2bb1f..8cec310 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/ForwardOrientedTexture.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/ForwardOrientedTexture.java @@ -19,7 +19,7 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.texture.TextureBitmap; public class ForwardOrientedTexture extends AbstractCoordinateShape { private static final double SIZE_MULTIPLIER = 0.005; - public Texture texture; + public final Texture texture; private double scale; public ForwardOrientedTexture(final Point3D point, final double scale, diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java index 8b37068..2727a17 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java @@ -20,7 +20,7 @@ import java.util.WeakHashMap; public class GlowingPoint extends ForwardOrientedTexture { private static final int TEXTURE_SIZE = 50; - private static final Set glowingPoints = Collections.newSetFromMap(new WeakHashMap()); + private static final Set glowingPoints = Collections.newSetFromMap(new WeakHashMap<>()); private final Color color; public GlowingPoint(final Point3D point, final double pointSize, diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/solidpolygon/LineInterpolator.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/solidpolygon/LineInterpolator.java index 45d5b96..18058d8 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/solidpolygon/LineInterpolator.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/solidpolygon/LineInterpolator.java @@ -33,12 +33,8 @@ public class LineInterpolator implements Comparable { if (absoluteHeight > o.absoluteHeight) return -1; - if (width < o.width) - return 1; - if (width > o.width) - return -1; + return Integer.compare(o.width, width); - return 0; } @Override diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Graph.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Graph.java index 674c1e3..2c38a9a 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Graph.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Graph.java @@ -17,7 +17,6 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.Line; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas; -import java.io.IOException; import java.util.List; public class Graph extends AbstractCompositeShape { @@ -32,7 +31,7 @@ public class Graph extends AbstractCompositeShape { private final Color plotColor; public Graph(final double scale, final List data, - final String label, final Point3D location) throws IOException { + final String label, final Point3D location) { super(location); width = 20; @@ -49,7 +48,7 @@ public class Graph extends AbstractCompositeShape { plotColor = new Color(255, 0, 0, 100); addVerticalLines(scale); - addXlabels(scale); + addXLabels(scale); addHorizontalLinesAndLabels(scale); plotData(scale, data); @@ -62,8 +61,7 @@ public class Graph extends AbstractCompositeShape { addShape(labelCanvas); } - public void addHorizontalLinesAndLabels(final double scale) - throws IOException { + private void addHorizontalLinesAndLabels(final double scale) { for (double y = yMin; y <= yMax; y += verticalStep) { final Point3D p1 = new Point3D(0, y, 0).scaleUp(scale); @@ -86,7 +84,7 @@ public class Graph extends AbstractCompositeShape { } } - public void addVerticalLines(final double scale) { + private void addVerticalLines(final double scale) { for (double x = 0; x <= width; x += horizontalStep) { final Point3D p1 = new Point3D(x, yMin, 0).scaleUp(scale); @@ -99,7 +97,7 @@ public class Graph extends AbstractCompositeShape { } } - public void addXlabels(final double scale) throws IOException { + private void addXLabels(final double scale) { for (double x = 0; x <= width; x += horizontalStep * 2) { final Point3D labelLocation = new Point3D(x, yMin - 0.4, 0) .scaleUp(scale); @@ -112,7 +110,7 @@ public class Graph extends AbstractCompositeShape { } } - public void plotData(final double scale, final List data) { + private void plotData(final double scale, final List data) { Point3D previousPoint = null; for (final Point2D point : data) { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/base/AbstractCompositeShape.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/base/AbstractCompositeShape.java index 7d2ae4c..aa7c30e 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/base/AbstractCompositeShape.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/base/AbstractCompositeShape.java @@ -10,11 +10,11 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.math.Transform; -import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; import eu.svjatoslav.sixth.e3d.gui.UserRelativityTracker; import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; +import eu.svjatoslav.sixth.e3d.math.Transform; +import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape; @@ -153,7 +153,7 @@ public class AbstractCompositeShape extends AbstractShape { } public void setGroupForUngrouped(final String groupIdentifier) { - originalSubShapes.stream().filter(subShape -> subShape.isUngrouped()).forEach(subShape -> subShape.setGroup(groupIdentifier)); + originalSubShapes.stream().filter(SubShape::isUngrouped).forEach(subShape -> subShape.setGroup(groupIdentifier)); } @Override diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java index 956cf2c..737a5b8 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java @@ -10,10 +10,10 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas; import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.math.Transform; -import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; import eu.svjatoslav.sixth.e3d.gui.TextPointer; +import eu.svjatoslav.sixth.e3d.math.Transform; +import eu.svjatoslav.sixth.e3d.math.TransformPipe; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle; -- 2.20.1