From cad5276b56cfbd0b194dbacb894fea20b9dd5b15 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 3 Mar 2023 23:20:26 +0200 Subject: [PATCH] Updated readability of the code. --- .../renderer/octree/raytracer/CameraView.java | 17 +++++------ .../octree/raytracer/LightSource.java | 19 ++++++++---- .../renderer/octree/raytracer/RayTracer.java | 30 +++++++++---------- 3 files changed, 36 insertions(+), 30 deletions(-) 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 c53ae53..ce92787 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 @@ -9,20 +9,17 @@ import eu.svjatoslav.sixth.e3d.gui.Avatar; import static eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera.SIZE; +/** + * Represents camera view. Used to compute direction of rays during ray tracing. + */ public class CameraView { - Point3D cameraCenter; - Point3D topLeft; - Point3D topRight; - Point3D bottomLeft; - Point3D bottomRight; + /** + * Camera view coordinates. + */ + Point3D cameraCenter, topLeft, topRight, bottomLeft, bottomRight; public CameraView(final Avatar avatar, final double zoom) { - computeCameraCoordinates(avatar, zoom); - } - - 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(); diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/LightSource.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/LightSource.java index 0efe65b..3c963d6 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/LightSource.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/raytracer/LightSource.java @@ -7,20 +7,29 @@ package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; +/** + * Represents light source. + */ public class LightSource { - public int x, y, z; + /** + * Light source location. + */ + Point3D location; + /** + * Light source color. + */ public Color color; + /** + * Light source brightness. + */ public float brightness; public LightSource(final Point3D location, final Color color, final float Brightness) { - x = (int) location.x; - y = (int) location.y; - z = (int) location.z; - + this.location = location; this.color = color; brightness = Brightness; } 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 ed6c937..8f7923f 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 @@ -122,9 +122,9 @@ public class RayTracer implements Runnable { float red = 30, green = 30, blue = 30; for (final LightSource l : lights) { - final int xDist = (l.x - ray.hitCellX); - final int yDist = (l.y - ray.hitCellY); - final int zDist = (l.z - ray.hitCellZ); + final double xDist = (l.location.x - ray.hitCellX); + final double yDist = (l.location.y - ray.hitCellY); + final double zDist = (l.location.z - ray.hitCellZ); double newRed = 0, newGreen = 0, newBlue = 0; double tempRed, tempGreen, tempBlue; @@ -136,8 +136,8 @@ public class RayTracer implements Runnable { final Ray r1 = new Ray(ray.hitCellX, ray.hitCellY - (float) 1.5, ray.hitCellZ, - (float) l.x - (float) ray.hitCellX, l.y - - (ray.hitCellY - (float) 1.5), (float) l.z + (float) l.location.x - (float) ray.hitCellX, l.location.y + - (ray.hitCellY - (float) 1.5), (float) l.location.z - (float) ray.hitCellZ); final int rt1 = octreeVolume.traceCell(0, 0, 0, @@ -152,8 +152,8 @@ public class RayTracer implements Runnable { final Ray r2 = new Ray(ray.hitCellX - (float) 1.5, ray.hitCellY, ray.hitCellZ, - l.x - (ray.hitCellX - (float) 1.5), (float) l.y - - (float) ray.hitCellY, (float) l.z + l.location.x - (ray.hitCellX - (float) 1.5), (float) l.location.y + - (float) ray.hitCellY, (float) l.location.z - (float) ray.hitCellZ); final int rt2 = octreeVolume.traceCell(0, 0, 0, @@ -175,8 +175,8 @@ public class RayTracer implements Runnable { final Ray r3 = new Ray(ray.hitCellX, ray.hitCellY, ray.hitCellZ - (float) 1.5, - (float) l.x - (float) ray.hitCellX, (float) l.y - - (float) ray.hitCellY, l.z + (float) l.location.x - (float) ray.hitCellX, (float) l.location.y + - (float) ray.hitCellY, l.location.z - (ray.hitCellZ - (float) 1.5)); final int rt3 = octreeVolume.traceCell(0, 0, 0, @@ -197,8 +197,8 @@ public class RayTracer implements Runnable { final Ray r4 = new Ray(ray.hitCellX, ray.hitCellY + (float) 1.5, ray.hitCellZ, - (float) l.x - (float) ray.hitCellX, l.y - - (ray.hitCellY + (float) 1.5), (float) l.z + (float) l.location.x - (float) ray.hitCellX, l.location.y + - (ray.hitCellY + (float) 1.5), (float) l.location.z - (float) ray.hitCellZ); final int rt4 = octreeVolume.traceCell(0, 0, 0, @@ -219,8 +219,8 @@ public class RayTracer implements Runnable { final Ray r5 = new Ray(ray.hitCellX + (float) 1.5, ray.hitCellY, ray.hitCellZ, - l.x - (ray.hitCellX + (float) 1.5), (float) l.y - - (float) ray.hitCellY, (float) l.z + l.location.x - (ray.hitCellX + (float) 1.5), (float) l.location.y + - (float) ray.hitCellY, (float) l.location.z - (float) ray.hitCellZ); final int rt5 = octreeVolume.traceCell(0, 0, 0, @@ -241,8 +241,8 @@ public class RayTracer implements Runnable { final Ray r6 = new Ray(ray.hitCellX, ray.hitCellY, ray.hitCellZ + (float) 1.5, - (float) l.x - (float) ray.hitCellX, (float) l.y - - (float) ray.hitCellY, l.z + (float) l.location.x - (float) ray.hitCellX, (float) l.location.y + - (float) ray.hitCellY, l.location.z - (ray.hitCellZ + (float) 1.5)); final int rt6 = octreeVolume.traceCell(0, 0, 0, -- 2.20.1