Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / octree / OctreeVolume.java
index 4b483e0..a4f4382 100755 (executable)
@@ -1,17 +1,15 @@
 /*
- * Sixth - System for data storage, computation, exploration and interaction.
- * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
  */
-
 package eu.svjatoslav.sixth.e3d.renderer.octree;
 
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Ray;
 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
-import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
+
+import static java.lang.Integer.max;
+import static java.lang.Integer.min;
 
 /**
  * <pre>
@@ -31,21 +29,27 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
 
 public class OctreeVolume {
 
+    // cell is not hit by the ray
     public static final int TRACE_NO_HIT = -1;
-    /**
-     * Single solid color.
-     */
+
+    // solid cell (contains color and illumination)
     private static final int CELL_STATE_SOLID = -2;
+
+    // unused cell
     private static final int CELL_STATE_UNUSED = -1;
-    final LineAppearance factory = new LineAppearance();
-    public int ce1[];
-    public int ce2[];
-    public int ce3[];
-    public int ce4[];
-    public int ce5[];
-    public int ce6[];
-    public int ce7[];
-    public int ce8[];
+
+    public int[] cell1;
+    public int[] cell2;
+    public int[] cell3;
+    public int[] cell4;
+    public int[] cell5;
+    public int[] cell6;
+    public int[] cell7;
+    public int[] cell8;
+
+    /**
+     * Pointer to the first unused cell.
+     */
     public int cellAllocationPointer = 0;
     public int usedCellsCount = 0;
     public int masterCellSize;
@@ -58,31 +62,35 @@ public class OctreeVolume {
         final int color = getCellColor(pointer);
         final int illumination = getCellIllumination(pointer);
 
-        ce1[pointer] = makeNewCell(color, illumination);
-        ce2[pointer] = makeNewCell(color, illumination);
-        ce3[pointer] = makeNewCell(color, illumination);
-        ce4[pointer] = makeNewCell(color, illumination);
-        ce5[pointer] = makeNewCell(color, illumination);
-        ce6[pointer] = makeNewCell(color, illumination);
-        ce7[pointer] = makeNewCell(color, illumination);
-        ce8[pointer] = makeNewCell(color, illumination);
+        cell1[pointer] = makeNewCell(color, illumination);
+        cell2[pointer] = makeNewCell(color, illumination);
+        cell3[pointer] = makeNewCell(color, illumination);
+        cell4[pointer] = makeNewCell(color, illumination);
+        cell5[pointer] = makeNewCell(color, illumination);
+        cell6[pointer] = makeNewCell(color, illumination);
+        cell7[pointer] = makeNewCell(color, illumination);
+        cell8[pointer] = makeNewCell(color, illumination);
     }
 
+    /**
+     * Clears the cell.
+     * @param pointer Pointer to the cell.
+     */
     public void clearCell(final int pointer) {
-        ce1[pointer] = 0;
-        ce2[pointer] = 0;
-        ce3[pointer] = 0;
-        ce4[pointer] = 0;
-
-        ce5[pointer] = 0;
-        ce6[pointer] = 0;
-        ce7[pointer] = 0;
-        ce8[pointer] = 0;
+        cell1[pointer] = 0;
+        cell2[pointer] = 0;
+        cell3[pointer] = 0;
+        cell4[pointer] = 0;
+
+        cell5[pointer] = 0;
+        cell6[pointer] = 0;
+        cell7[pointer] = 0;
+        cell8[pointer] = 0;
     }
 
     public void deleteCell(final int cellPointer) {
         clearCell(cellPointer);
-        ce1[cellPointer] = CELL_STATE_UNUSED;
+        cell1[cellPointer] = CELL_STATE_UNUSED;
         usedCellsCount--;
     }
 
@@ -90,120 +98,112 @@ public class OctreeVolume {
                              final int cubeSize, final Ray r) {
 
         // ray starts inside the cube
-        if ((cubeX - cubeSize) < r.x)
-            if ((cubeX + cubeSize) > r.x)
-                if ((cubeY - cubeSize) < r.y)
-                    if ((cubeY + cubeSize) > r.y)
-                        if ((cubeZ - cubeSize) < r.z)
-                            if ((cubeZ + cubeSize) > r.z) {
-                                r.hitX = r.x;
-                                r.hitY = r.y;
-                                r.hitZ = r.z;
+        if ((cubeX - cubeSize) < r.origin.x)
+            if ((cubeX + cubeSize) > r.origin.x)
+                if ((cubeY - cubeSize) < r.origin.y)
+                    if ((cubeY + cubeSize) > r.origin.y)
+                        if ((cubeZ - cubeSize) < r.origin.z)
+                            if ((cubeZ + cubeSize) > r.origin.z) {
+                                r.hitPoint = r.origin.clone();
                                 return 1;
                             }
         // back face
-        if (r.zp > 0)
-            if ((cubeZ - cubeSize) > r.z) {
-                final double mult = ((cubeZ - cubeSize) - r.z) / r.zp;
-                final double hitX = (r.xp * mult) + r.x;
+        if (r.direction.z > 0)
+            if ((cubeZ - cubeSize) > r.origin.z) {
+                final double mult = ((cubeZ - cubeSize) - r.origin.z) / r.direction.z;
+                final double hitX = (r.direction.x * mult) + r.origin.x;
                 if ((cubeX - cubeSize) < hitX)
                     if ((cubeX + cubeSize) > hitX) {
-                        final double hitY = (r.yp * mult) + r.y;
+                        final double hitY = (r.direction.y * mult) + r.origin.y;
                         if ((cubeY - cubeSize) < hitY)
                             if ((cubeY + cubeSize) > hitY) {
-                                r.hitX = hitX;
-                                r.hitY = hitY;
-                                r.hitZ = cubeZ - cubeSize;
+                                r.hitPoint = new Point3D(hitX, hitY, cubeZ
+                                        - cubeSize);
                                 return 2;
                             }
                     }
             }
 
         // up face
-        if (r.yp > 0)
-            if ((cubeY - cubeSize) > r.y) {
-                final double mult = ((cubeY - cubeSize) - r.y) / r.yp;
-                final double hitX = (r.xp * mult) + r.x;
+        if (r.direction.y > 0)
+            if ((cubeY - cubeSize) > r.origin.y) {
+                final double mult = ((cubeY - cubeSize) - r.origin.y) / r.direction.y;
+                final double hitX = (r.direction.x * mult) + r.origin.x;
                 if ((cubeX - cubeSize) < hitX)
                     if ((cubeX + cubeSize) > hitX) {
-                        final double hitZ = (r.zp * mult) + r.z;
+                        final double hitZ = (r.direction.z * mult) + r.origin.z;
                         if ((cubeZ - cubeSize) < hitZ)
                             if ((cubeZ + cubeSize) > hitZ) {
-                                r.hitX = hitX;
-                                r.hitY = cubeY - cubeSize;
-                                r.hitZ = hitZ;
+                                r.hitPoint = new Point3D(hitX, cubeY - cubeSize,
+                                        hitZ);
                                 return 3;
                             }
                     }
             }
 
         // left face
-        if (r.xp > 0)
-            if ((cubeX - cubeSize) > r.x) {
-                final double mult = ((cubeX - cubeSize) - r.x) / r.xp;
-                final double hitY = (r.yp * mult) + r.y;
+        if (r.direction.x > 0)
+            if ((cubeX - cubeSize) > r.origin.x) {
+                final double mult = ((cubeX - cubeSize) - r.origin.x) / r.direction.x;
+                final double hitY = (r.direction.y * mult) + r.origin.y;
                 if ((cubeY - cubeSize) < hitY)
                     if ((cubeY + cubeSize) > hitY) {
-                        final double hitZ = (r.zp * mult) + r.z;
+                        final double hitZ = (r.direction.z * mult) + r.origin.z;
                         if ((cubeZ - cubeSize) < hitZ)
                             if ((cubeZ + cubeSize) > hitZ) {
-                                r.hitX = cubeX - cubeSize;
-                                r.hitY = hitY;
-                                r.hitZ = hitZ;
+                                r.hitPoint = new Point3D(cubeX - cubeSize, hitY,
+                                        hitZ);
                                 return 4;
                             }
                     }
             }
 
         // front face
-        if (r.zp < 0)
-            if ((cubeZ + cubeSize) < r.z) {
-                final double mult = ((cubeZ + cubeSize) - r.z) / r.zp;
-                final double hitX = (r.xp * mult) + r.x;
+        if (r.direction.z < 0)
+            if ((cubeZ + cubeSize) < r.origin.z) {
+                final double mult = ((cubeZ + cubeSize) - r.origin.z) / r.direction.z;
+                final double hitX = (r.direction.x * mult) + r.origin.x;
                 if ((cubeX - cubeSize) < hitX)
                     if ((cubeX + cubeSize) > hitX) {
-                        final double hitY = (r.yp * mult) + r.y;
+                        final double hitY = (r.direction.y * mult) + r.origin.y;
                         if ((cubeY - cubeSize) < hitY)
                             if ((cubeY + cubeSize) > hitY) {
-                                r.hitX = hitX;
-                                r.hitY = hitY;
-                                r.hitZ = cubeZ + cubeSize;
+                                r.hitPoint = new Point3D(hitX, hitY, cubeZ
+                                        + cubeSize);
                                 return 5;
                             }
                     }
             }
 
         // down face
-        if (r.yp < 0)
-            if ((cubeY + cubeSize) < r.y) {
-                final double mult = ((cubeY + cubeSize) - r.y) / r.yp;
-                final double hitX = (r.xp * mult) + r.x;
+        if (r.direction.y < 0)
+            if ((cubeY + cubeSize) < r.origin.y) {
+                final double mult = ((cubeY + cubeSize) - r.origin.y) / r.direction.y;
+                final double hitX = (r.direction.x * mult) + r.origin.x;
                 if ((cubeX - cubeSize) < hitX)
                     if ((cubeX + cubeSize) > hitX) {
-                        final double hitZ = (r.zp * mult) + r.z;
+                        final double hitZ = (r.direction.z * mult) + r.origin.z;
                         if ((cubeZ - cubeSize) < hitZ)
                             if ((cubeZ + cubeSize) > hitZ) {
-                                r.hitX = hitX;
-                                r.hitY = cubeY + cubeSize;
-                                r.hitZ = hitZ;
+                                r.hitPoint = new Point3D(hitX, cubeY + cubeSize,
+                                        hitZ);
                                 return 6;
                             }
                     }
             }
 
         // right face
-        if (r.xp < 0)
-            if ((cubeX + cubeSize) < r.x) {
-                final double mult = ((cubeX + cubeSize) - r.x) / r.xp;
-                final double hitY = (r.yp * mult) + r.y;
+        if (r.direction.x < 0)
+            if ((cubeX + cubeSize) < r.origin.x) {
+                final double mult = ((cubeX + cubeSize) - r.origin.x) / r.direction.x;
+                final double hitY = (r.direction.y * mult) + r.origin.y;
                 if ((cubeY - cubeSize) < hitY)
                     if ((cubeY + cubeSize) > hitY) {
-                        final double hitZ = (r.zp * mult) + r.z;
+                        final double hitZ = (r.direction.z * mult) + r.origin.z;
                         if ((cubeZ - cubeSize) < hitZ)
                             if ((cubeZ + cubeSize) > hitZ) {
-                                r.hitX = cubeX + cubeSize;
-                                r.hitY = hitY;
-                                r.hitZ = hitZ;
+                                r.hitPoint = new Point3D(cubeX + cubeSize, hitY,
+                                        hitZ);
                                 return 7;
                             }
                     }
@@ -214,40 +214,27 @@ public class OctreeVolume {
     /**
      * Fill 3D rectangle.
      */
-    public void fillRect3D(int x1, int y1, int z1, int x2, int y2, int z2,
-                           final Color color) {
-        int t;
-        if (x1 > x2) {
-            t = x1;
-            x1 = x2;
-            x2 = t;
-        }
-
-        if (y1 > y2) {
-            t = y1;
-            y1 = y2;
-            y2 = t;
-        }
+    public void fillRectangle(IntegerPoint p1, IntegerPoint p2, Color color) {
 
-        if (z1 > z2) {
-            t = z1;
-            z1 = z2;
-            z2 = t;
-        }
+        int x1 = min(p1.x, p2.x);
+        int x2 = max(p1.x, p2.x);
+        int y1 = min(p1.y, p2.y);
+        int y2 = max(p1.y, p2.y);
+        int z1 = min(p1.z, p2.z);
+        int z2 = max(p1.z, p2.z);
 
         for (int x = x1; x <= x2; x++)
             for (int y = y1; y <= y2; y++)
                 for (int z = z1; z <= z2; z++)
                     putCell(x, y, z, 0, 0, 0, masterCellSize, 0, color);
-
     }
 
     public int getCellColor(final int pointer) {
-        return ce2[pointer];
+        return cell2[pointer];
     }
 
     public int getCellIllumination(final int pointer) {
-        return ce3[pointer];
+        return cell3[pointer];
     }
 
     public void initWorld(final int bufferLength, final int masterCellSize) {
@@ -256,34 +243,39 @@ public class OctreeVolume {
         // initialize world storage buffer
         this.masterCellSize = masterCellSize;
 
-        ce1 = new int[bufferLength];
-        ce2 = new int[bufferLength];
-        ce3 = new int[bufferLength];
-        ce4 = new int[bufferLength];
+        cell1 = new int[bufferLength];
+        cell2 = new int[bufferLength];
+        cell3 = new int[bufferLength];
+        cell4 = new int[bufferLength];
 
-        ce5 = new int[bufferLength];
-        ce6 = new int[bufferLength];
-        ce7 = new int[bufferLength];
-        ce8 = new int[bufferLength];
+        cell5 = new int[bufferLength];
+        cell6 = new int[bufferLength];
+        cell7 = new int[bufferLength];
+        cell8 = new int[bufferLength];
 
         for (int i = 0; i < bufferLength; i++)
-            ce1[i] = CELL_STATE_UNUSED;
+            cell1[i] = CELL_STATE_UNUSED;
 
         // initialize master cell
         clearCell(0);
     }
 
     public boolean isCellSolid(final int pointer) {
-        return ce1[pointer] == CELL_STATE_SOLID;
+        return cell1[pointer] == CELL_STATE_SOLID;
     }
 
-    public int makeNewCell() {
-        for (; ; ) {
-            if (cellAllocationPointer >= ce1.length)
+    /**
+     * Scans cells arrays and returns pointer to found unused cell.
+     * @return pointer to found unused cell
+     */
+    public int getNewCellPointer() {
+        while (true) {
+            // ensure that cell allocation pointer is in bounds
+            if (cellAllocationPointer >= cell1.length)
                 cellAllocationPointer = 0;
 
-            if (ce1[cellAllocationPointer] == CELL_STATE_UNUSED) {
-
+            if (cell1[cellAllocationPointer] == CELL_STATE_UNUSED) {
+                // unused cell found
                 clearCell(cellAllocationPointer);
 
                 usedCellsCount++;
@@ -294,15 +286,20 @@ public class OctreeVolume {
     }
 
     public int makeNewCell(final int color, final int illumination) {
-        final int pointer = makeNewCell();
+        final int pointer = getNewCellPointer();
         markCellAsSolid(pointer);
         setCellColor(pointer, color);
         setCellIllumination(pointer, illumination);
         return pointer;
     }
 
+    /**
+     * Mark cell as solid.
+     *
+     * @param pointer pointer to cell
+     */
     public void markCellAsSolid(final int pointer) {
-        ce1[pointer] = CELL_STATE_SOLID;
+        cell1[pointer] = CELL_STATE_SOLID;
     }
 
     public void putCell(final int x, final int y, final int z, final Color color) {
@@ -329,7 +326,7 @@ public class OctreeVolume {
             }
 
             // decide witch subcube to use
-            int subCubeArray[];
+            int[] subCubeArray;
             int subX, subY, subZ;
 
             if (x > cellX) {
@@ -339,22 +336,22 @@ public class OctreeVolume {
                     if (z > cellZ) {
                         subZ = (cellSize / 2) + cellZ;
                         // 7
-                        subCubeArray = ce7;
+                        subCubeArray = cell7;
                     } else {
                         subZ = (-cellSize / 2) + cellZ;
                         // 3
-                        subCubeArray = ce3;
+                        subCubeArray = cell3;
                     }
                 } else {
                     subY = (-cellSize / 2) + cellY;
                     if (z > cellZ) {
                         subZ = (cellSize / 2) + cellZ;
                         // 6
-                        subCubeArray = ce6;
+                        subCubeArray = cell6;
                     } else {
                         subZ = (-cellSize / 2) + cellZ;
                         // 2
-                        subCubeArray = ce2;
+                        subCubeArray = cell2;
                     }
                 }
             } else {
@@ -364,22 +361,22 @@ public class OctreeVolume {
                     if (z > cellZ) {
                         subZ = (cellSize / 2) + cellZ;
                         // 8
-                        subCubeArray = ce8;
+                        subCubeArray = cell8;
                     } else {
                         subZ = (-cellSize / 2) + cellZ;
                         // 4
-                        subCubeArray = ce4;
+                        subCubeArray = cell4;
                     }
                 } else {
                     subY = (-cellSize / 2) + cellY;
                     if (z > cellZ) {
                         subZ = (cellSize / 2) + cellZ;
                         // 5
-                        subCubeArray = ce5;
+                        subCubeArray = cell5;
                     } else {
                         subZ = (-cellSize / 2) + cellZ;
                         // 1
-                        subCubeArray = ce1;
+                        subCubeArray = cell1;
                     }
                 }
             }
@@ -387,7 +384,7 @@ public class OctreeVolume {
             int subCubePointer;
             if (subCubeArray[cellPointer] == 0) {
                 // create empty cluster
-                subCubePointer = makeNewCell();
+                subCubePointer = getNewCellPointer();
                 subCubeArray[cellPointer] = subCubePointer;
             } else
                 subCubePointer = subCubeArray[cellPointer];
@@ -395,24 +392,25 @@ public class OctreeVolume {
             putCell(x, y, z, subX, subY, subZ, cellSize / 2, subCubePointer,
                     color);
         } else {
-            ce1[cellPointer] = CELL_STATE_SOLID;
-            ce2[cellPointer] = color.toInt();
-            ce3[cellPointer] = CELL_STATE_UNUSED;
+            cell1[cellPointer] = CELL_STATE_SOLID;
+            cell2[cellPointer] = color.toInt();
+            cell3[cellPointer] = CELL_STATE_UNUSED;
             // System.out.println("Cell written!");
         }
     }
 
     public void setCellColor(final int pointer, final int color) {
-        ce2[pointer] = color;
+        cell2[pointer] = color;
     }
 
     public void setCellIllumination(final int pointer, final int illumination) {
-        ce3[pointer] = illumination;
+        cell3[pointer] = illumination;
     }
 
     /**
-     * @return intersecting cell pointer or -1 if no cell in intersecting this
-     * ray.
+     * Trace ray through the world and return pointer to intersecting cell.
+     *
+     * @return pointer to intersecting cell or TRACE_NO_HIT if no intersection.
      */
     public int traceCell(final int cellX, final int cellY, final int cellZ,
                          final int cellSize, final int pointer, final Ray ray) {
@@ -431,76 +429,76 @@ public class OctreeVolume {
                 final int halfOfCellSize = cellSize / 2;
                 int rayIntersectionResult;
 
-                if (ray.x > cellX) {
-                    if (ray.y > cellY) {
-                        if (ray.z > cellZ) {
+                if (ray.origin.x > cellX) {
+                    if (ray.origin.y > cellY) {
+                        if (ray.origin.z > cellZ) {
                             // 7
                             // 6 8 3 5 2 4 1
 
-                            if (ce7[pointer] != 0) {
+                            if (cell7[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce7[pointer], ray);
+                                        cell7[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce6[pointer] != 0) {
+                            if (cell6[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce6[pointer], ray);
+                                        cell6[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce8[pointer] != 0) {
+                            if (cell8[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce8[pointer], ray);
+                                        cell8[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce3[pointer] != 0) {
+                            if (cell3[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce3[pointer], ray);
+                                        cell3[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce2[pointer] != 0) {
+                            if (cell2[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce2[pointer], ray);
+                                        cell2[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce4[pointer] != 0) {
+                            if (cell4[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce4[pointer], ray);
+                                        cell4[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce5[pointer] != 0) {
+                            if (cell5[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce5[pointer], ray);
+                                        cell5[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce1[pointer] != 0) {
+                            if (cell1[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce1[pointer], ray);
+                                        cell1[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
@@ -508,141 +506,141 @@ public class OctreeVolume {
                         } else {
                             // 3
                             // 2 4 7 1 6 8 5
-                            if (ce3[pointer] != 0) {
+                            if (cell3[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce3[pointer], ray);
+                                        cell3[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce2[pointer] != 0) {
+                            if (cell2[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce2[pointer], ray);
+                                        cell2[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce4[pointer] != 0) {
+                            if (cell4[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce4[pointer], ray);
+                                        cell4[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce7[pointer] != 0) {
+                            if (cell7[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce7[pointer], ray);
+                                        cell7[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce6[pointer] != 0) {
+                            if (cell6[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 + halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce6[pointer], ray);
+                                        cell6[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
-                            if (ce8[pointer] != 0) {
+                            if (cell8[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY + halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce8[pointer], ray);
+                                        cell8[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce1[pointer] != 0) {
+                            if (cell1[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ - halfOfCellSize, halfOfCellSize,
-                                        ce1[pointer], ray);
+                                        cell1[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
-                            if (ce5[pointer] != 0) {
+                            if (cell5[pointer] != 0) {
                                 rayIntersectionResult = traceCell(cellX
                                                 - halfOfCellSize, cellY - halfOfCellSize,
                                         cellZ + halfOfCellSize, halfOfCellSize,
-                                        ce5[pointer], ray);
+                                        cell5[pointer], ray);
                                 if (rayIntersectionResult >= 0)
                                     return rayIntersectionResult;
                             }
 
                         }
-                    } else if (ray.z > cellZ) {
+                    } else if (ray.origin.z > cellZ) {
                         // 6
                         // 5 2 7 8 1 3 4
-                        if (ce6[pointer] != 0) {
+                        if (cell6[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce6[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell6[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce7[pointer] != 0) {
+                        if (cell7[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce7[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell7[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce2[pointer] != 0) {
+                        if (cell2[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce2[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell2[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce5[pointer] != 0) {
+                        if (cell5[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce5[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell5[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce8[pointer] != 0) {
+                        if (cell8[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce8[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell8[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce3[pointer] != 0) {
+                        if (cell3[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce3[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell3[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce1[pointer] != 0) {
+                        if (cell1[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce1[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell1[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce4[pointer] != 0) {
+                        if (cell4[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce4[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell4[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
@@ -651,143 +649,143 @@ public class OctreeVolume {
                     } else {
                         // 2
                         // 1 3 6 5 4 7 8
-                        if (ce2[pointer] != 0) {
+                        if (cell2[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce2[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell2[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce3[pointer] != 0) {
+                        if (cell3[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce3[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell3[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce1[pointer] != 0) {
+                        if (cell1[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce1[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell1[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce6[pointer] != 0) {
+                        if (cell6[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce6[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell6[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce7[pointer] != 0) {
+                        if (cell7[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce7[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell7[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce5[pointer] != 0) {
+                        if (cell5[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce5[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell5[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce4[pointer] != 0) {
+                        if (cell4[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce4[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell4[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce8[pointer] != 0) {
+                        if (cell8[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce8[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell8[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
                     }
-                } else if (ray.y > cellY) {
-                    if (ray.z > cellZ) {
+                } else if (ray.origin.y > cellY) {
+                    if (ray.origin.z > cellZ) {
                         // 8
                         // 5 7 4 1 6 3 2
 
-                        if (ce8[pointer] != 0) {
+                        if (cell8[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce8[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell8[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce7[pointer] != 0) {
+                        if (cell7[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce7[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell7[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce5[pointer] != 0) {
+                        if (cell5[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce5[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell5[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce4[pointer] != 0) {
+                        if (cell4[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce4[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell4[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce3[pointer] != 0) {
+                        if (cell3[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce3[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell3[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce1[pointer] != 0) {
+                        if (cell1[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce1[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell1[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce6[pointer] != 0) {
+                        if (cell6[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce6[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell6[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce2[pointer] != 0) {
+                        if (cell2[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce2[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell2[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
@@ -797,139 +795,139 @@ public class OctreeVolume {
                         // 4
                         // 1 3 8 5 7 2 6
 
-                        if (ce4[pointer] != 0) {
+                        if (cell4[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce4[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell4[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce8[pointer] != 0) {
+                        if (cell8[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce8[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell8[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce3[pointer] != 0) {
+                        if (cell3[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce3[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell3[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce1[pointer] != 0) {
+                        if (cell1[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce1[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell1[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce7[pointer] != 0) {
+                        if (cell7[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY + halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce7[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell7[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce5[pointer] != 0) {
+                        if (cell5[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             - halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce5[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell5[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
-                        if (ce2[pointer] != 0) {
+                        if (cell2[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            - halfOfCellSize, halfOfCellSize, ce2[pointer],
+                                            - halfOfCellSize, halfOfCellSize, cell2[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
-                        if (ce6[pointer] != 0) {
+                        if (cell6[pointer] != 0) {
                             rayIntersectionResult = traceCell(cellX
                                             + halfOfCellSize, cellY - halfOfCellSize, cellZ
-                                            + halfOfCellSize, halfOfCellSize, ce6[pointer],
+                                            + halfOfCellSize, halfOfCellSize, cell6[pointer],
                                     ray);
                             if (rayIntersectionResult >= 0)
                                 return rayIntersectionResult;
                         }
 
                     }
-                } else if (ray.z > cellZ) {
+                } else if (ray.origin.z > cellZ) {
                     // 5
                     // 1 6 8 4 2 7 3
 
-                    if (ce5[pointer] != 0) {
+                    if (cell5[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce5[pointer], ray);
+                                halfOfCellSize, cell5[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce1[pointer] != 0) {
+                    if (cell1[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce1[pointer], ray);
+                                halfOfCellSize, cell1[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce6[pointer] != 0) {
+                    if (cell6[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce6[pointer], ray);
+                                halfOfCellSize, cell6[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce8[pointer] != 0) {
+                    if (cell8[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce8[pointer], ray);
+                                halfOfCellSize, cell8[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce4[pointer] != 0) {
+                    if (cell4[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce4[pointer], ray);
+                                halfOfCellSize, cell4[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce7[pointer] != 0) {
+                    if (cell7[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce7[pointer], ray);
+                                halfOfCellSize, cell7[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce2[pointer] != 0) {
+                    if (cell2[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce2[pointer], ray);
+                                halfOfCellSize, cell2[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce3[pointer] != 0) {
+                    if (cell3[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce3[pointer], ray);
+                                halfOfCellSize, cell3[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
@@ -938,64 +936,64 @@ public class OctreeVolume {
                     // 1
                     // 5 2 4 8 6 3 7
 
-                    if (ce1[pointer] != 0) {
+                    if (cell1[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce1[pointer], ray);
+                                halfOfCellSize, cell1[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce5[pointer] != 0) {
+                    if (cell5[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce5[pointer], ray);
+                                halfOfCellSize, cell5[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
-                    if (ce2[pointer] != 0) {
+                    if (cell2[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce2[pointer], ray);
+                                halfOfCellSize, cell2[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce4[pointer] != 0) {
+                    if (cell4[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce4[pointer], ray);
+                                halfOfCellSize, cell4[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce6[pointer] != 0) {
+                    if (cell6[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY - halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce6[pointer], ray);
+                                halfOfCellSize, cell6[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce8[pointer] != 0) {
+                    if (cell8[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX - halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce8[pointer], ray);
+                                halfOfCellSize, cell8[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
 
-                    if (ce3[pointer] != 0) {
+                    if (cell3[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ - halfOfCellSize,
-                                halfOfCellSize, ce3[pointer], ray);
+                                halfOfCellSize, cell3[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }
-                    if (ce7[pointer] != 0) {
+                    if (cell7[pointer] != 0) {
                         rayIntersectionResult = traceCell(cellX + halfOfCellSize,
                                 cellY + halfOfCellSize, cellZ + halfOfCellSize,
-                                halfOfCellSize, ce7[pointer], ray);
+                                halfOfCellSize, cell7[pointer], ray);
                         if (rayIntersectionResult >= 0)
                             return rayIntersectionResult;
                     }