From ff13a51ec53b3d2ee1c9309152ed2b40366218b9 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 3 Mar 2023 22:43:29 +0200 Subject: [PATCH] Updated readability of the code. --- .../sixth/e3d/geometry/Point3D.java | 4 +++ .../renderer/octree/raytracer/CameraView.java | 32 ++++++++++--------- 2 files changed, 21 insertions(+), 15 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 78efbda..8d72345 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -172,6 +172,10 @@ public class Point3D implements Cloneable { return this; } + public Point3D rotate(final double angleXZ, final double angleYZ) { + return rotate(new Point3D(0, 0, 0), angleXZ, angleYZ); + } + /** * Round current point coordinates to integer values. */ 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 ed0b037..b06f0c3 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 @@ -7,6 +7,8 @@ package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.gui.Avatar; +import static eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera.SIZE; + public class CameraView { Point3D cameraCenter; @@ -20,25 +22,25 @@ public class CameraView { } private void computeCameraCoordinates(final Avatar avatar, final double zoom) { - cameraCenter = new Point3D(avatar.getLocation()).scaleDown(zoom); - - topLeft = new Point3D(cameraCenter.x, cameraCenter.y, cameraCenter.z - + Camera.SIZE); - topRight = new Point3D(topLeft); - bottomLeft = new Point3D(topLeft); - bottomRight = new Point3D(topLeft); final float viewAngle = (float) .6; + 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); + bottomRight = new Point3D(0,0,SIZE).rotate(viewAngle, viewAngle); - topLeft.rotate(cameraCenter, -viewAngle, -viewAngle); - topRight.rotate(cameraCenter, viewAngle, -viewAngle); - bottomLeft.rotate(cameraCenter, -viewAngle, viewAngle); - bottomRight.rotate(cameraCenter, viewAngle, viewAngle); + topLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ()); + topRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ()); + 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); - topLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ()); - topRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ()); - bottomLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ()); - bottomRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ()); } } -- 2.20.1