Code cleanup and formatting.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / octree / raytracer / RayTracer.java
index 35ec06b..79ae21c 100755 (executable)
@@ -107,36 +107,29 @@ public class RayTracer implements Runnable {
 
         texture.resetResampledBitmapCache();
         viewPanel.repaintDuringNextViewUpdate();
-        // System.out.println("Raytracing done.");
-        // System.out.println("New lights computed:" + computedLights);
     }
 
-    public int traceLight(final LightSource l, final int cubeX,
-                          final int cubeY, final int cubeZ) {
-        return 0;
-    }
-
-    public int traceRay(final Ray r) {
+    private int traceRay(final Ray ray) {
 
-        final int re = octreeVolume.traceCell(0, 0, 0,
-                octreeVolume.masterCellSize, 0, r);
+        final int intersectingCell = octreeVolume.traceCell(0, 0, 0,
+                octreeVolume.masterCellSize, 0, ray);
 
-        if (re != -1) {
+        if (intersectingCell != -1) {
             // if lightening not computed, compute it
-            if (octreeVolume.ce3[re] == -1)
+            if (octreeVolume.ce3[intersectingCell] == -1)
                 // if cell is larger than 1
-                if (r.hitCellSize > 1) {
+                if (ray.hitCellSize > 1) {
                     // break it up
-                    octreeVolume.breakSolidCell(re);
-                    return traceRay(r);
+                    octreeVolume.breakSolidCell(intersectingCell);
+                    return traceRay(ray);
                 } else {
                     computedLights++;
                     float red = 30, green = 30, blue = 30;
 
                     for (final LightSource l : lights) {
-                        final int xDist = (l.x - r.hitCellX);
-                        final int yDist = (l.y - r.hitCellY);
-                        final int zDist = (l.z - r.hitCellZ);
+                        final int xDist = (l.x - ray.hitCellX);
+                        final int yDist = (l.y - ray.hitCellY);
+                        final int zDist = (l.z - ray.hitCellZ);
 
                         double newRed = 0, newGreen = 0, newBlue = 0;
                         double tempRed, tempGreen, tempBlue;
@@ -145,12 +138,12 @@ public class RayTracer implements Runnable {
                                 + (yDist * yDist) + (zDist * zDist));
                         distance = (distance / 3) + 1;
 
-                        final Ray r1 = new Ray(r.hitCellX, r.hitCellY
-                                - (float) 1.5, r.hitCellZ,
+                        final Ray r1 = new Ray(ray.hitCellX, ray.hitCellY
+                                - (float) 1.5, ray.hitCellZ,
 
-                                (float) l.x - (float) r.hitCellX, l.y
-                                - (r.hitCellY - (float) 1.5), (float) l.z
-                                - (float) r.hitCellZ);
+                                (float) l.x - (float) ray.hitCellX, l.y
+                                - (ray.hitCellY - (float) 1.5), (float) l.z
+                                - (float) ray.hitCellZ);
 
                         final int rt1 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r1);
@@ -161,12 +154,12 @@ public class RayTracer implements Runnable {
                             newBlue = (l.color.b * l.brightness) / distance;
                         }
 
-                        final Ray r2 = new Ray(r.hitCellX - (float) 1.5,
-                                r.hitCellY, r.hitCellZ,
+                        final Ray r2 = new Ray(ray.hitCellX - (float) 1.5,
+                                ray.hitCellY, ray.hitCellZ,
 
-                                l.x - (r.hitCellX - (float) 1.5), (float) l.y
-                                - (float) r.hitCellY, (float) l.z
-                                - (float) r.hitCellZ);
+                                l.x - (ray.hitCellX - (float) 1.5), (float) l.y
+                                - (float) ray.hitCellY, (float) l.z
+                                - (float) ray.hitCellZ);
 
                         final int rt2 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r2);
@@ -184,12 +177,12 @@ public class RayTracer implements Runnable {
                                 newBlue = tempBlue;
                         }
 
-                        final Ray r3 = new Ray(r.hitCellX, r.hitCellY,
-                                r.hitCellZ - (float) 1.5,
+                        final Ray r3 = new Ray(ray.hitCellX, ray.hitCellY,
+                                ray.hitCellZ - (float) 1.5,
 
-                                (float) l.x - (float) r.hitCellX, (float) l.y
-                                - (float) r.hitCellY, l.z
-                                - (r.hitCellZ - (float) 1.5));
+                                (float) l.x - (float) ray.hitCellX, (float) l.y
+                                - (float) ray.hitCellY, l.z
+                                - (ray.hitCellZ - (float) 1.5));
 
                         final int rt3 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r3);
@@ -206,12 +199,12 @@ public class RayTracer implements Runnable {
                                 newBlue = tempBlue;
                         }
 
-                        final Ray r4 = new Ray(r.hitCellX, r.hitCellY
-                                + (float) 1.5, r.hitCellZ,
+                        final Ray r4 = new Ray(ray.hitCellX, ray.hitCellY
+                                + (float) 1.5, ray.hitCellZ,
 
-                                (float) l.x - (float) r.hitCellX, l.y
-                                - (r.hitCellY + (float) 1.5), (float) l.z
-                                - (float) r.hitCellZ);
+                                (float) l.x - (float) ray.hitCellX, l.y
+                                - (ray.hitCellY + (float) 1.5), (float) l.z
+                                - (float) ray.hitCellZ);
 
                         final int rt4 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r4);
@@ -228,12 +221,12 @@ public class RayTracer implements Runnable {
                                 newBlue = tempBlue;
                         }
 
-                        final Ray r5 = new Ray(r.hitCellX + (float) 1.5,
-                                r.hitCellY, r.hitCellZ,
+                        final Ray r5 = new Ray(ray.hitCellX + (float) 1.5,
+                                ray.hitCellY, ray.hitCellZ,
 
-                                l.x - (r.hitCellX + (float) 1.5), (float) l.y
-                                - (float) r.hitCellY, (float) l.z
-                                - (float) r.hitCellZ);
+                                l.x - (ray.hitCellX + (float) 1.5), (float) l.y
+                                - (float) ray.hitCellY, (float) l.z
+                                - (float) ray.hitCellZ);
 
                         final int rt5 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r5);
@@ -250,12 +243,12 @@ public class RayTracer implements Runnable {
                                 newBlue = tempBlue;
                         }
 
-                        final Ray r6 = new Ray(r.hitCellX, r.hitCellY,
-                                r.hitCellZ + (float) 1.5,
+                        final Ray r6 = new Ray(ray.hitCellX, ray.hitCellY,
+                                ray.hitCellZ + (float) 1.5,
 
-                                (float) l.x - (float) r.hitCellX, (float) l.y
-                                - (float) r.hitCellY, l.z
-                                - (r.hitCellZ + (float) 1.5));
+                                (float) l.x - (float) ray.hitCellX, (float) l.y
+                                - (float) ray.hitCellY, l.z
+                                - (ray.hitCellZ + (float) 1.5));
 
                         final int rt6 = octreeVolume.traceCell(0, 0, 0,
                                 octreeVolume.masterCellSize, 0, r6);
@@ -277,7 +270,7 @@ public class RayTracer implements Runnable {
 
                     }
 
-                    final int cellColor = octreeVolume.ce2[re];
+                    final int cellColor = octreeVolume.ce2[intersectingCell];
 
                     red = (red * ((cellColor & 0xFF0000) >> 16)) / 255;
                     green = (green * ((cellColor & 0xFF00) >> 8)) / 255;
@@ -290,13 +283,13 @@ public class RayTracer implements Runnable {
                     if (blue > 255)
                         blue = 255;
 
-                    octreeVolume.ce3[re] = (((int) red) << 16)
+                    octreeVolume.ce3[intersectingCell] = (((int) red) << 16)
                             + (((int) green) << 8) + ((int) blue);
 
                 }
-            if (octreeVolume.ce3[re] == 0)
-                return octreeVolume.ce2[re];
-            return octreeVolume.ce3[re];
+            if (octreeVolume.ce3[intersectingCell] == 0)
+                return octreeVolume.ce2[intersectingCell];
+            return octreeVolume.ce3[intersectingCell];
         }
 
         // return (200 << 16) + (200 << 8) + 255;