From 6b9b5a6b70397f3cea7b965a54aaacc03cdae4f7 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 3 Mar 2023 23:01:38 +0200 Subject: [PATCH] Updated readability of the code. --- .../eu/svjatoslav/sixth/e3d/geometry/Point3D.java | 14 ++++++++++++++ .../e3d/renderer/octree/raytracer/CameraView.java | 11 ++++------- 2 files changed, 18 insertions(+), 7 deletions(-) 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 8d72345..6bf2dd3 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -58,6 +58,20 @@ public class Point3D implements Cloneable { return this; } + /** + * Add coordinates of current point to other point. Value of current point will not be changed. + * @return current point. + */ + public Point3D addTo(final Point3D ... otherPoints) { + for (final Point3D otherPoint : otherPoints) otherPoint.add(this); + return this; + } + + /** + * Create new point by cloning position of current point. + * + * @return newly created clone. + */ public Point3D clone() { return new Point3D(this); } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/CameraView.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/CameraView.java index b06f0c3..c53ae53 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/CameraView.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/CameraView.java @@ -23,7 +23,9 @@ public class CameraView { private void computeCameraCoordinates(final Avatar avatar, final double zoom) { + // compute camera view coordinates as if camera is at (0,0,0) and look at (0,0,1) final float viewAngle = (float) .6; + cameraCenter = new Point3D(); topLeft = new Point3D(0,0, SIZE).rotate(-viewAngle, -viewAngle); topRight = new Point3D(0,0, SIZE).rotate(viewAngle, -viewAngle); bottomLeft = new Point3D(0,0,SIZE).rotate(-viewAngle, viewAngle); @@ -34,13 +36,8 @@ public class CameraView { bottomLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ()); bottomRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ()); - // compute camera coordinates as if camera is at avatar's location and look - cameraCenter = new Point3D(avatar.getLocation()).scaleDown(zoom); - topLeft.add(cameraCenter); - topRight.add(cameraCenter); - bottomLeft.add(cameraCenter); - bottomRight.add(cameraCenter); - + // place camera view at avatar location + avatar.getLocation().clone().scaleDown(zoom).addTo(cameraCenter, topLeft, topRight, bottomLeft, bottomRight); } } -- 2.20.1