Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / octree / raytracer / CameraView.java
index b06f0c3..ce92787 100644 (file)
@@ -9,21 +9,20 @@ 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();
         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 +33,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);
     }
 
 }