Refactoring.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Jul 2018 00:36:08 +0000 (03:36 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Jul 2018 00:36:08 +0000 (03:36 +0300)
31 files changed:
src/main/java/eu/svjatoslav/sixth/e3d/geometry/GeometryCoordinate.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Orientation.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java
src/main/java/eu/svjatoslav/sixth/e3d/geometry/Transform.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/geometry/TransformPipe.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/gui/Avatar.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/GuiComponent.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/View.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateListener.java [deleted file]
src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputHandler.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/UserInputTracker.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/WorldNavigationTracker.java
src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java
src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/e3d/math/Orientation.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/e3d/math/Transform.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/sixth/e3d/math/TransformPipe.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/Camera.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/ShapeCollection.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractShape.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Galaxy.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Graph.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/TexturedRectangle.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/base/AbstractCompositeShape.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/wireframe/Grid2D.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/BorderLine.java

diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/GeometryCoordinate.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/GeometryCoordinate.java
deleted file mode 100644 (file)
index 48b72d2..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * 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.geometry;
-
-import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-
-public class GeometryCoordinate {
-
-    public Point3D coordinate;
-    public Point3D transformedCoordinate;
-    public Point2D onScreenCoordinate;
-
-    int lastTransformedFrame;
-
-    public GeometryCoordinate() {
-        coordinate = new Point3D();
-        transformedCoordinate = new Point3D();
-        onScreenCoordinate = new Point2D();
-    }
-
-    public GeometryCoordinate(final Point3D location) {
-        coordinate = location;
-        transformedCoordinate = new Point3D();
-        onScreenCoordinate = new Point2D();
-    }
-
-    public void transform(final TransformPipe transforms,
-                          final RenderingContext renderContext) {
-
-        if (lastTransformedFrame == renderContext.frameNumber)
-            return;
-
-        lastTransformedFrame = renderContext.frameNumber;
-
-        transforms.transform(coordinate, transformedCoordinate);
-
-        onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
-                + renderContext.xCenter;
-        onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
-                + renderContext.yCenter;
-    }
-}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Orientation.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Orientation.java
deleted file mode 100644 (file)
index 540c60b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * 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.geometry;
-
-public class Orientation implements Cloneable {
-
-    private double s1, c1, s2, c2;
-
-    private double angleXZ = 0;
-    private double angleYZ = 0;
-
-    public Orientation() {
-        computeMultipliers();
-    }
-
-    public Orientation(final double angleXZ, final double angleYZ) {
-        this.angleXZ = angleXZ;
-        this.angleYZ = angleYZ;
-        computeMultipliers();
-    }
-
-    @Override
-    public Orientation clone() {
-        return new Orientation(angleXZ, angleYZ);
-    }
-
-    private void computeMultipliers() {
-        s1 = Math.sin(angleXZ);
-        c1 = Math.cos(angleXZ);
-
-        s2 = Math.sin(angleYZ);
-        c2 = Math.cos(angleYZ);
-    }
-
-    public void rotate(final Point3D point3d) {
-        final double z1 = (point3d.z * c1) - (point3d.x * s1);
-        point3d.x = (point3d.z * s1) + (point3d.x * c1);
-
-        point3d.z = (z1 * c2) - (point3d.y * s2);
-        point3d.y = (z1 * s2) + (point3d.y * c2);
-    }
-
-    public void rotate(final double angleXZ, final double angleYZ) {
-        this.angleXZ += angleXZ;
-        this.angleYZ += angleYZ;
-        computeMultipliers();
-    }
-
-}
index f8fbef9..1cfd39c 100755 (executable)
@@ -9,6 +9,8 @@
 
 package eu.svjatoslav.sixth.e3d.geometry;
 
+import static java.lang.Math.sqrt;
+
 public class Point2D implements Cloneable {
 
     public double x, y;
@@ -32,6 +34,10 @@ public class Point2D implements Cloneable {
         return this;
     }
 
+    public boolean isZero(){
+        return (x == 0) && (y == 0);
+    }
+
     @Override
     public Point2D clone() {
         return new Point2D(this);
@@ -42,7 +48,7 @@ public class Point2D implements Cloneable {
         y = source.y;
     }
 
-    public Point2D computeMiddlePoint(final Point2D p1, final Point2D p2) {
+    public Point2D getMiddle(final Point2D p1, final Point2D p2) {
         x = (p1.x + p2.x) / 2d;
         y = (p1.y + p2.y) / 2d;
         return this;
@@ -52,11 +58,18 @@ public class Point2D implements Cloneable {
         return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
     }
 
+    /**
+     * Compute distance to another point.
+     */
     public double getDistanceTo(final Point2D anotherPoint) {
         final double xDiff = x - anotherPoint.x;
         final double yDiff = y - anotherPoint.y;
 
-        return Math.sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+        return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+    }
+
+    public double getVectorLength() {
+        return sqrt(((x * x) + (y * y)));
     }
 
     public Point2D invert() {
@@ -70,9 +83,9 @@ public class Point2D implements Cloneable {
         y = (int) y;
     }
 
-    public Point2D subtract(final Point2D direction) {
-        x -= direction.x;
-        y -= direction.y;
+    public Point2D subtract(final Point2D point) {
+        x -= point.x;
+        y -= point.y;
         return this;
     }
 
index 0b28de2..462f310 100755 (executable)
@@ -9,13 +9,16 @@
 
 package eu.svjatoslav.sixth.e3d.geometry;
 
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+import static java.lang.Math.sqrt;
+
 /**
- * Used to represent point in a 3D space, vector or speed.
+ * Used to represent point in a 3D space or vector.
  */
 
 public class Point3D extends Point2D implements Cloneable {
 
-    public static final Point3D ZERO = new Point3D();
     public double z;
 
     public Point3D() {
@@ -70,6 +73,11 @@ public class Point3D extends Point2D implements Cloneable {
         return this;
     }
 
+    @Override
+    public boolean isZero(){
+        return (x == 0) && (y == 0) && (z == 0);
+    }
+
     public double getAngleXZ(final Point3D anotherPoint) {
         return Math.atan2(x - anotherPoint.x, z - anotherPoint.z);
     }
@@ -86,8 +94,12 @@ public class Point3D extends Point2D implements Cloneable {
         final double yDelta = y - anotherPoint.y;
         final double zDelta = z - anotherPoint.z;
 
-        return Math
-                .sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
+        return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
+    }
+
+    @Override
+    public double getVectorLength() {
+        return sqrt(((x * x) + (y * y) + (z * z)));
     }
 
     @Override
@@ -100,11 +112,11 @@ public class Point3D extends Point2D implements Cloneable {
 
     public void rotate(final Point3D center, final double angleXZ,
                        final double angleYZ) {
-        final double s1 = Math.sin(angleXZ);
-        final double c1 = Math.cos(angleXZ);
+        final double s1 = sin(angleXZ);
+        final double c1 = cos(angleXZ);
 
-        final double s2 = Math.sin(angleYZ);
-        final double c2 = Math.cos(angleYZ);
+        final double s2 = sin(angleYZ);
+        final double c2 = cos(angleYZ);
 
         x -= center.x;
         y -= center.y;
@@ -174,7 +186,7 @@ public class Point3D extends Point2D implements Cloneable {
         return this;
     }
 
-    public boolean withinDrawingLimits() {
+    public boolean isVisible() {
 
         if (z > 0)
             return true;
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Transform.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Transform.java
deleted file mode 100755 (executable)
index 374880f..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * 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.geometry;
-
-public class Transform implements Cloneable {
-
-    private final Point3D translation;
-    private final Orientation orientation;
-
-    public Transform() {
-        translation = new Point3D();
-        orientation = new Orientation();
-    }
-
-    public Transform(final Point3D translation) {
-        this.translation = translation;
-        orientation = new Orientation();
-    }
-
-    public Transform(final Point3D translation, final double angleXZ,
-                     final double angleYZ) {
-
-        this.translation = translation;
-        orientation = new Orientation(angleXZ, angleYZ);
-    }
-
-    public Transform(final Point3D translation, final Orientation orientation) {
-        this.translation = translation;
-        this.orientation = orientation;
-    }
-
-    @Override
-    public Transform clone() {
-        return new Transform(translation, orientation);
-    }
-
-    public Orientation getOrientation() {
-        return orientation;
-    }
-
-    public Point3D getTranslation() {
-        return translation;
-    }
-
-    public void transform(final Point3D point) {
-        orientation.rotate(point);
-        point.add(translation);
-    }
-
-}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/TransformPipe.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/TransformPipe.java
deleted file mode 100644 (file)
index 7df7991..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * 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.geometry;
-
-public class TransformPipe {
-
-    private Transform[] transforms = new Transform[100];
-
-    private int transformsCount = 0;
-
-    public void addTransform(final Transform transform) {
-        transforms[transformsCount] = transform;
-        transformsCount++;
-    }
-
-    public void clear() {
-        transformsCount = 0;
-    }
-
-    public void dropTransform() {
-        transformsCount--;
-    }
-
-    public void transform(final Point3D source, final Point3D destination) {
-
-        destination.clone(source);
-
-        for (int i = transformsCount - 1; i >= 0; i--)
-            transforms[i].transform(destination);
-    }
-}
index 6e4c5ec..7f0f698 100755 (executable)
@@ -14,7 +14,7 @@ import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import static java.lang.Math.cos;
 import static java.lang.Math.sin;
 
-public class Avatar implements ViewUpdateListener {
+public class Avatar implements ViewRenderListener {
 
     public static final double SPEED_LIMIT = 30;
     /**
@@ -70,7 +70,7 @@ public class Avatar implements ViewUpdateListener {
     }
 
     @Override
-    public boolean beforeViewUpdate(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+    public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
 
         final Point3D locationBeforeUpdate = new Point3D(location);
         translateAvatarLocation(millisecondsSinceLastFrame);
@@ -84,8 +84,7 @@ public class Avatar implements ViewUpdateListener {
     }
 
     public void enforceSpeedLimit() {
-        final double currentSpeed = movementVector
-                .getDistanceTo(Point3D.ZERO);
+        final double currentSpeed = movementVector.getVectorLength();
 
         if (currentSpeed <= SPEED_LIMIT)
             return;
@@ -122,7 +121,7 @@ public class Avatar implements ViewUpdateListener {
     }
 
     public double getMovementSpeed() {
-        return movementVector.getDistanceTo(Point3D.ZERO);
+        return movementVector.getVectorLength();
     }
 
     private void applyFrictionToUserMovement(int millisecondsPassedSinceLastFrame) {
index 3eb7d8b..8ab5c90 100644 (file)
@@ -11,7 +11,7 @@ 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.geometry.Transform;
+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;
@@ -39,8 +39,8 @@ public class GuiComponent extends AbstractCompositeShape implements
     }
 
     @Override
-    public boolean beforeViewUpdate(final ViewContext viewContext,
-                                    final int millisecondsSinceLastFrame) {
+    public boolean beforeRender(final ViewContext viewContext,
+                                final int millisecondsSinceLastFrame) {
         return false;
     }
 
index d183325..175c10a 100644 (file)
 
 package eu.svjatoslav.sixth.e3d.gui;
 
-import eu.svjatoslav.sixth.e3d.geometry.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
 
 public class UserRelativityTracker {
 
-    public final static int minimalSliceFactor = 5;
+    private final static int minimalSliceFactor = 5;
     public GeometryCoordinate center = new GeometryCoordinate();
     public GeometryCoordinate right;
     public GeometryCoordinate down;
@@ -57,8 +57,7 @@ public class UserRelativityTracker {
     }
 
     public double getDistanceToUser() {
-        return center.transformedCoordinate
-                .getDistanceTo(Point3D.ZERO);
+        return center.transformedCoordinate.getVectorLength();
     }
 
     public double proposeSliceFactor() {
index 6f1b474..615c69b 100755 (executable)
@@ -23,7 +23,7 @@ public class View extends JPanel implements ComponentListener {
 
     private static final long serialVersionUID = 1683277888885045387L;
     private final List<ViewListener> viewListeners = new ArrayList<>();
-    private final List<ViewUpdateListener> viewUpdateListeners = new ArrayList<>();
+    private final List<ViewRenderListener> viewRenderListeners = new ArrayList<>();
     private final ViewContext context = new ViewContext(this);
     /**
      * Last time this view was updated
@@ -40,11 +40,11 @@ public class View extends JPanel implements ComponentListener {
     private boolean repaintDuringNextViewUpdate = true;
 
     public View() {
-        viewUpdateListeners.add(context.getAvatar());
+        viewRenderListeners.add(context.getAvatar());
 
         // initialize input tracker
         context.getUserInputTracker().bind(this);
-        viewUpdateListeners.add(context.getUserInputTracker());
+        viewRenderListeners.add(context.getUserInputTracker());
 
         initializePanelLayout();
 
@@ -57,8 +57,8 @@ public class View extends JPanel implements ComponentListener {
         getViewListeners().add(listener);
     }
 
-    public void addViewUpdateListener(final ViewUpdateListener listener) {
-        viewUpdateListeners.add(listener);
+    public void addViewUpdateListener(final ViewRenderListener listener) {
+        viewRenderListeners.add(listener);
     }
 
     @Override
@@ -237,8 +237,8 @@ public class View extends JPanel implements ComponentListener {
         // notify update listeners
         boolean reRenderFrame = false;
 
-        for (final ViewUpdateListener listener : viewUpdateListeners)
-            if (listener.beforeViewUpdate(context,
+        for (final ViewRenderListener listener : viewRenderListeners)
+            if (listener.beforeRender(context,
                     millisecondsPassedSinceLastUpdate))
                 reRenderFrame = true;
 
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewRenderListener.java
new file mode 100644 (file)
index 0000000..0977ef7
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.gui;
+
+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.
+     *
+     * @return <code>true</code> if underlying view shall be re-rendered. If at least one of the view update listeners
+     * returns <code>true</code>, view is re-rendered.
+     */
+    boolean beforeRender(ViewContext viewContext, final int millisecondsSinceLastFrame);
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateListener.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateListener.java
deleted file mode 100644 (file)
index 41a51f9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * 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.gui;
-
-public interface ViewUpdateListener {
-
-    /**
-     * Notifies that it is about time to render next frame. Update listener can determine if frame repaint is actually
-     * needed from its perspective. Frame will be rendered if at least one listener says yes.
-     *
-     * @return <code>true</code> if underlying view shall be re-rendered. If at least one of the view update listeners
-     * returns <code>true</code>, view is re-rendered.
-     */
-    boolean beforeViewUpdate(ViewContext viewContext, final int millisecondsSinceLastFrame);
-}
index e763a8e..ae9f8d9 100644 (file)
 package eu.svjatoslav.sixth.e3d.gui.humaninput;
 
 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
-import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
+import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
 
 import java.awt.event.KeyEvent;
 
-public interface UserInputHandler extends ViewUpdateListener {
+public interface UserInputHandler extends ViewRenderListener {
 
     void focusLost(ViewContext viewContext);
 
index dedfd78..105a582 100755 (executable)
@@ -13,7 +13,7 @@ import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.gui.Avatar;
 import eu.svjatoslav.sixth.e3d.gui.View;
 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
-import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
+import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
 
 import javax.swing.*;
 import java.awt.event.*;
@@ -23,7 +23,7 @@ import java.util.List;
 import java.util.Map;
 
 public class UserInputTracker
-        implements MouseMotionListener, KeyListener, MouseListener, MouseWheelListener, ViewUpdateListener {
+        implements MouseMotionListener, KeyListener, MouseListener, MouseWheelListener, ViewRenderListener {
 
     /**
      * <pre>
@@ -36,12 +36,12 @@ public class UserInputTracker
     private final Map<Integer, Long> pressedKeysToPressedTimeMap = new HashMap<>();
     private final List<MouseClick> detectedMouseClicks = new ArrayList<>();
     private final List<KeyEvent> detectedKeyEvents = new ArrayList<>();
-    public int wheelMovedDirection = 0;
-    Point2D mouseDraggedDirection = new Point2D();
-    Point2D oldMouseCoordinatesWhenDragging;
-    ViewContext viewContext;
-    Point2D currentMouseLocation;
-    boolean mouseMoved;
+    private int wheelMovedDirection = 0;
+    private Point2D mouseDraggedDirection = new Point2D();
+    private Point2D oldMouseCoordinatesWhenDragging;
+    private ViewContext viewContext;
+    private Point2D currentMouseLocation;
+    private boolean mouseMoved;
     private boolean mouseWithinWindow = false;
 
     public UserInputTracker(final ViewContext viewContext) {
@@ -52,14 +52,15 @@ public class UserInputTracker
      * {@inheritDoc}
      */
     @Override
-    public boolean beforeViewUpdate(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+    public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
 
         boolean viewUpdateNeeded = handleDetectedMouseClicks(viewContext.getView());
 
         viewUpdateNeeded |= handleDetectedKeyEvents();
 
-        viewContext.getKeyboardFocusTracker().getCurrentFocusOwner().beforeViewUpdate(viewContext,
+        viewContext.getKeyboardFocusTracker().getCurrentFocusOwner().beforeRender(viewContext,
                 millisecondsSinceLastFrame);
+
         viewUpdateNeeded |= trackMouse();
 
         return viewUpdateNeeded;
@@ -75,7 +76,7 @@ public class UserInputTracker
         panel.addMouseWheelListener(this);
     }
 
-    public boolean handleDetectedKeyEvents() {
+    private boolean handleDetectedKeyEvents() {
         boolean keyEventsHandled = false;
 
         final UserInputHandler currentFocusOwner = viewContext.getKeyboardFocusTracker().getCurrentFocusOwner();
@@ -107,10 +108,9 @@ public class UserInputTracker
     }
 
     /**
-     * Returns <code>true</code> if mouse events are detected and view needs to
-     * be repainted.
+     * @return <code>true</code> if view needs to be repainted.
      */
-    public synchronized boolean handleDetectedMouseClicks(final View view) {
+    private synchronized boolean handleDetectedMouseClicks(final View view) {
         if (detectedMouseClicks.isEmpty()) {
 
             if (currentMouseLocation != null)
@@ -128,7 +128,7 @@ public class UserInputTracker
         return true;
     }
 
-    public boolean isKeyPressed(final int keyCode) {
+    boolean isKeyPressed(final int keyCode) {
         return pressedKeysToPressedTimeMap.containsKey(keyCode);
     }
 
@@ -209,11 +209,27 @@ public class UserInputTracker
     /**
      * Interpret mouse movement
      */
-    public boolean trackMouse() {
+    private boolean trackMouse() {
         final Avatar avatar = viewContext.getAvatar();
+        trackDragging(avatar);
+        trackVerticalScrolling(avatar);
+
+        boolean repaintNeeded = !mouseDraggedDirection.isZero() || (wheelMovedDirection != 0);
 
-        // track mouse dragging
+        // reset movement counters
+        wheelMovedDirection = 0;
+        mouseDraggedDirection.zero();
+
+        return repaintNeeded;
+    }
+
+    private void trackVerticalScrolling(Avatar avatar) {
+        final double actualAcceleration = 50 * avatar.avatarAcceleration * (1 + (avatar.getMovementSpeed() / 10));
+        avatar.getMovementVector().y += (wheelMovedDirection * actualAcceleration);
+        avatar.enforceSpeedLimit();
+    }
 
+    private void trackDragging(Avatar avatar) {
         // TODO: need to detect whether user moved mouse or touch screen
 
         // for mouse
@@ -225,22 +241,6 @@ public class UserInputTracker
         // mouseDraggedDirection.x / 50));
         // avatar.setAngleYZ(avatar.getAngleYZ() + ((float)
         // mouseDraggedDirection.y / 50));
-
-        // track mouse wheel movements
-        final double actualAcceleration = 50 * avatar.avatarAcceleration * (1 + (avatar.getMovementSpeed() / 10));
-
-        avatar.getMovementVector().y += (wheelMovedDirection * actualAcceleration);
-        avatar.enforceSpeedLimit();
-
-        // check if view shall be repainted
-        boolean repaintNeeded;
-        repaintNeeded = (mouseDraggedDirection.x != 0) || (mouseDraggedDirection.y != 0) || (wheelMovedDirection != 0);
-
-        // reset movement counters
-        wheelMovedDirection = 0;
-        mouseDraggedDirection.zero();
-
-        return repaintNeeded;
     }
 
 }
index 59066a8..cc99c42 100644 (file)
@@ -18,8 +18,8 @@ import java.awt.event.KeyEvent;
 public class WorldNavigationTracker implements UserInputHandler {
 
     @Override
-    public boolean beforeViewUpdate(final ViewContext viewContext,
-                                    final int millisecondsSinceLastFrame) {
+    public boolean beforeRender(final ViewContext viewContext,
+                                final int millisecondsSinceLastFrame) {
 
         trackKeys(millisecondsSinceLastFrame, viewContext);
         return false;
index 4db49d5..b7c633f 100755 (executable)
@@ -10,7 +10,7 @@
 package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+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.ViewContext;
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java
new file mode 100644 (file)
index 0000000..d95717c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point2D;
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
+
+public class GeometryCoordinate {
+
+    public Point3D coordinate;
+    public Point3D transformedCoordinate;
+    public Point2D onScreenCoordinate;
+
+    private int lastTransformedFrame;
+
+    public GeometryCoordinate() {
+        coordinate = new Point3D();
+        transformedCoordinate = new Point3D();
+        onScreenCoordinate = new Point2D();
+    }
+
+    public GeometryCoordinate(final Point3D location) {
+        coordinate = location;
+        transformedCoordinate = new Point3D();
+        onScreenCoordinate = new Point2D();
+    }
+
+    public void transform(final TransformPipe transforms,
+                          final RenderingContext renderContext) {
+
+        if (lastTransformedFrame == renderContext.frameNumber)
+            return;
+
+        lastTransformedFrame = renderContext.frameNumber;
+
+        transforms.transform(coordinate, transformedCoordinate);
+
+        onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
+                + renderContext.xCenter;
+        onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
+                + renderContext.yCenter;
+    }
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/Orientation.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/Orientation.java
new file mode 100644 (file)
index 0000000..958286a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class Orientation implements Cloneable {
+
+    private double s1, c1, s2, c2;
+
+    private double angleXZ = 0;
+    private double angleYZ = 0;
+
+    public Orientation() {
+        computeMultipliers();
+    }
+
+    public Orientation(final double angleXZ, final double angleYZ) {
+        this.angleXZ = angleXZ;
+        this.angleYZ = angleYZ;
+        computeMultipliers();
+    }
+
+    @Override
+    public Orientation clone() {
+        return new Orientation(angleXZ, angleYZ);
+    }
+
+    private void computeMultipliers() {
+        s1 = Math.sin(angleXZ);
+        c1 = Math.cos(angleXZ);
+
+        s2 = Math.sin(angleYZ);
+        c2 = Math.cos(angleYZ);
+    }
+
+    public void rotate(final Point3D point3d) {
+        final double z1 = (point3d.z * c1) - (point3d.x * s1);
+        point3d.x = (point3d.z * s1) + (point3d.x * c1);
+
+        point3d.z = (z1 * c2) - (point3d.y * s2);
+        point3d.y = (z1 * s2) + (point3d.y * c2);
+    }
+
+    public void rotate(final double angleXZ, final double angleYZ) {
+        this.angleXZ += angleXZ;
+        this.angleYZ += angleYZ;
+        computeMultipliers();
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/Transform.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/Transform.java
new file mode 100755 (executable)
index 0000000..059ba39
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class Transform implements Cloneable {
+
+    private final Point3D translation;
+    private final Orientation orientation;
+
+    public Transform() {
+        translation = new Point3D();
+        orientation = new Orientation();
+    }
+
+    public Transform(final Point3D translation) {
+        this.translation = translation;
+        orientation = new Orientation();
+    }
+
+    public Transform(final Point3D translation, final double angleXZ,
+                     final double angleYZ) {
+
+        this.translation = translation;
+        orientation = new Orientation(angleXZ, angleYZ);
+    }
+
+    public Transform(final Point3D translation, final Orientation orientation) {
+        this.translation = translation;
+        this.orientation = orientation;
+    }
+
+    @Override
+    public Transform clone() {
+        return new Transform(translation, orientation);
+    }
+
+    public Orientation getOrientation() {
+        return orientation;
+    }
+
+    public Point3D getTranslation() {
+        return translation;
+    }
+
+    public void transform(final Point3D point) {
+        orientation.rotate(point);
+        point.add(translation);
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/TransformPipe.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/TransformPipe.java
new file mode 100644 (file)
index 0000000..b554953
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * 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.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class TransformPipe {
+
+    private Transform[] transforms = new Transform[100];
+
+    private int transformsCount = 0;
+
+    public void addTransform(final Transform transform) {
+        transforms[transformsCount] = transform;
+        transformsCount++;
+    }
+
+    public void clear() {
+        transformsCount = 0;
+    }
+
+    public void dropTransform() {
+        transformsCount--;
+    }
+
+    public void transform(final Point3D source, final Point3D destination) {
+
+        destination.clone(source);
+
+        for (int i = transformsCount - 1; i >= 0; i--)
+            transforms[i].transform(destination);
+    }
+}
index 02e2502..e4dd649 100755 (executable)
@@ -10,7 +10,7 @@
 package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
 import eu.svjatoslav.sixth.e3d.gui.Avatar;
 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
@@ -58,7 +58,7 @@ public class Camera extends TexturedRectangle {
     private void computeCameraCoordinates(final Avatar avatar) {
         initialize(CAMERA_SIZE, CAMERA_SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
 
-        camCenter = Point3D.ZERO.clone();
+        camCenter = new Point3D();
 
         topLeft.setValues(camCenter.x, camCenter.y, camCenter.z + CAMERA_SIZE);
 
@@ -75,10 +75,8 @@ public class Camera extends TexturedRectangle {
 
         topLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
         topRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
-        bottomLeft
-                .rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
-        bottomRight.rotate(camCenter, -avatar.getAngleXZ(),
-                -avatar.getAngleYZ());
+        bottomLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+        bottomRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
 
         final Color cameraColor = new Color(255, 255, 0, 255);
         final LineAppearance appearance = new LineAppearance(2, cameraColor);
index b453f74..2faf880 100755 (executable)
@@ -10,8 +10,8 @@
 package eu.svjatoslav.sixth.e3d.renderer.raster;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
 import eu.svjatoslav.sixth.e3d.gui.Avatar;
 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
index ed5c364..97ffc7b 100644 (file)
@@ -9,9 +9,9 @@
 
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
 
-import eu.svjatoslav.sixth.e3d.geometry.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
 import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
 
@@ -60,7 +60,7 @@ public abstract class AbstractCoordinateShape extends AbstractShape {
 
             accumulatedZ += geometryPoint.transformedCoordinate.z;
 
-            if (!geometryPoint.transformedCoordinate.withinDrawingLimits())
+            if (!geometryPoint.transformedCoordinate.isVisible())
                 paint = false;
         }
 
index 6aeb2eb..c33ceb7 100644 (file)
@@ -9,7 +9,7 @@
 
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
 
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+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.renderer.raster.RenderAggregator;
index 24bd64e..5a77288 100755 (executable)
@@ -10,7 +10,7 @@
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+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;
index cc68fc3..674c1e3 100644 (file)
@@ -11,7 +11,7 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+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.Line;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
index 183fe79..ea23bfc 100644 (file)
@@ -11,7 +11,7 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
index d9586ab..7d2ae4c 100644 (file)
@@ -10,8 +10,8 @@
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+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;
index 3f1f88b..956cf2c 100644 (file)
@@ -10,8 +10,8 @@
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+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.renderer.raster.Color;
index 6136e91..0156db2 100644 (file)
@@ -11,7 +11,7 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+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;
 
index 05c9a4a..2d4c661 100644 (file)
@@ -38,7 +38,7 @@ public class BorderLine implements Comparator<BorderLine> {
 
     public PolygonCoordinate getMiddlePoint() {
         return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.space,
-                c2.space), new Point2D().computeMiddlePoint(c1.texture,
+                c2.space), new Point2D().getMiddle(c1.texture,
                 c2.texture));
     }
 }