From: Svjatoslav Agejenko <svjatoslav@svjatoslav.eu> Date: Tue, 7 Mar 2023 18:11:43 +0000 (+0200) Subject: Updated readability of the code. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=163f1c4b65973edd8528f8619e88db7da2de5c47;p=sixth-3d.git Updated readability of the code. --- 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 120ea32..3b8ad22 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -4,6 +4,8 @@ */ package eu.svjatoslav.sixth.e3d.geometry; +import eu.svjatoslav.sixth.e3d.renderer.octree.IntegerPoint; + import static java.lang.Math.*; /** @@ -36,6 +38,13 @@ public class Point3D implements Cloneable { this.z = z; } + public Point3D(IntegerPoint point) { + this.x = point.x; + this.y = point.y; + this.z = point.z; + } + + /** * Creates new current point by cloning coordinates from parent point. */ diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/IntegerPoint.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/IntegerPoint.java new file mode 100644 index 0000000..2aa151c --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/IntegerPoint.java @@ -0,0 +1,17 @@ +package eu.svjatoslav.sixth.e3d.renderer.octree; + +public class IntegerPoint +{ + public int x, y, z = 0; + + public IntegerPoint() + { + } + + public IntegerPoint(final int x, final int y, final int z) + { + this.x = x; + this.y = y; + this.z = z; + } +} diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/OctreeVolume.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/OctreeVolume.java index 5cc17dd..a4f4382 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/OctreeVolume.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/octree/OctreeVolume.java @@ -8,6 +8,9 @@ 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 static java.lang.Integer.max; +import static java.lang.Integer.min; + /** * <pre> * There are 3 cell types: @@ -35,14 +38,18 @@ public class OctreeVolume { // unused cell private static final int CELL_STATE_UNUSED = -1; - 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; @@ -55,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--; } @@ -203,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; - } + public void fillRectangle(IntegerPoint p1, IntegerPoint p2, Color color) { - if (y1 > y2) { - t = y1; - y1 = y2; - y2 = t; - } - - 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) { @@ -245,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++; @@ -283,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) { @@ -328,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 { @@ -353,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; } } } @@ -376,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]; @@ -384,19 +392,19 @@ 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; } /** @@ -427,70 +435,70 @@ public class OctreeVolume { // 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; } @@ -498,71 +506,71 @@ 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; } @@ -571,68 +579,68 @@ public class OctreeVolume { } 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; @@ -641,69 +649,69 @@ 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; @@ -715,69 +723,69 @@ public class OctreeVolume { // 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; @@ -787,69 +795,69 @@ 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; @@ -860,66 +868,66 @@ public class OctreeVolume { // 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; } @@ -928,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; } 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 daeb417..52bec7d 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 @@ -116,7 +116,7 @@ public class RayTracer implements Runnable { if (intersectingCell != -1) { // if lightening not computed, compute it - if (octreeVolume.ce3[intersectingCell] == -1) + if (octreeVolume.cell3[intersectingCell] == -1) // if cell is larger than 1 if (ray.hitCellSize > 1) { // break it up @@ -294,7 +294,7 @@ public class RayTracer implements Runnable { } - final int cellColor = octreeVolume.ce2[intersectingCell]; + final int cellColor = octreeVolume.cell2[intersectingCell]; red = (red * ((cellColor & 0xFF0000) >> 16)) / 255; green = (green * ((cellColor & 0xFF00) >> 8)) / 255; @@ -307,13 +307,13 @@ public class RayTracer implements Runnable { if (blue > 255) blue = 255; - octreeVolume.ce3[intersectingCell] = (((int) red) << 16) + octreeVolume.cell3[intersectingCell] = (((int) red) << 16) + (((int) green) << 8) + ((int) blue); } - if (octreeVolume.ce3[intersectingCell] == 0) - return octreeVolume.ce2[intersectingCell]; - return octreeVolume.ce3[intersectingCell]; + if (octreeVolume.cell3[intersectingCell] == 0) + return octreeVolume.cell2[intersectingCell]; + return octreeVolume.cell3[intersectingCell]; } // return (200 << 16) + (200 << 8) + 255;