2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.renderer.octree;
10 import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Ray;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
16 * There are 3 cell types:
23 * visible color, after being illuminated by nearby light sources
26 * contains pointers to 8 sub cells
30 public class OctreeVolume {
32 public static final int TRACE_NO_HIT = -1;
36 private static final int CELL_STATE_SOLID = -2;
37 private static final int CELL_STATE_UNUSED = -1;
38 final LineAppearance factory = new LineAppearance();
47 public int cellAllocationPointer = 0;
48 public int usedCellsCount = 0;
49 public int masterCellSize;
51 public OctreeVolume() {
52 initWorld(1500000, 256 * 64);
55 public void breakSolidCell(final int pointer) {
56 final int color = getCellColor(pointer);
57 final int illumination = getCellIllumination(pointer);
59 ce1[pointer] = makeNewCell(color, illumination);
60 ce2[pointer] = makeNewCell(color, illumination);
61 ce3[pointer] = makeNewCell(color, illumination);
62 ce4[pointer] = makeNewCell(color, illumination);
63 ce5[pointer] = makeNewCell(color, illumination);
64 ce6[pointer] = makeNewCell(color, illumination);
65 ce7[pointer] = makeNewCell(color, illumination);
66 ce8[pointer] = makeNewCell(color, illumination);
69 public void clearCell(final int pointer) {
81 public void deleteCell(final int cellPointer) {
82 clearCell(cellPointer);
83 ce1[cellPointer] = CELL_STATE_UNUSED;
87 public int doesIntersect(final int cubeX, final int cubeY, final int cubeZ,
88 final int cubeSize, final Ray r) {
90 // ray starts inside the cube
91 if ((cubeX - cubeSize) < r.x)
92 if ((cubeX + cubeSize) > r.x)
93 if ((cubeY - cubeSize) < r.y)
94 if ((cubeY + cubeSize) > r.y)
95 if ((cubeZ - cubeSize) < r.z)
96 if ((cubeZ + cubeSize) > r.z) {
104 if ((cubeZ - cubeSize) > r.z) {
105 final double mult = ((cubeZ - cubeSize) - r.z) / r.zp;
106 final double hitX = (r.xp * mult) + r.x;
107 if ((cubeX - cubeSize) < hitX)
108 if ((cubeX + cubeSize) > hitX) {
109 final double hitY = (r.yp * mult) + r.y;
110 if ((cubeY - cubeSize) < hitY)
111 if ((cubeY + cubeSize) > hitY) {
114 r.hitZ = cubeZ - cubeSize;
122 if ((cubeY - cubeSize) > r.y) {
123 final double mult = ((cubeY - cubeSize) - r.y) / r.yp;
124 final double hitX = (r.xp * mult) + r.x;
125 if ((cubeX - cubeSize) < hitX)
126 if ((cubeX + cubeSize) > hitX) {
127 final double hitZ = (r.zp * mult) + r.z;
128 if ((cubeZ - cubeSize) < hitZ)
129 if ((cubeZ + cubeSize) > hitZ) {
131 r.hitY = cubeY - cubeSize;
140 if ((cubeX - cubeSize) > r.x) {
141 final double mult = ((cubeX - cubeSize) - r.x) / r.xp;
142 final double hitY = (r.yp * mult) + r.y;
143 if ((cubeY - cubeSize) < hitY)
144 if ((cubeY + cubeSize) > hitY) {
145 final double hitZ = (r.zp * mult) + r.z;
146 if ((cubeZ - cubeSize) < hitZ)
147 if ((cubeZ + cubeSize) > hitZ) {
148 r.hitX = cubeX - cubeSize;
158 if ((cubeZ + cubeSize) < r.z) {
159 final double mult = ((cubeZ + cubeSize) - r.z) / r.zp;
160 final double hitX = (r.xp * mult) + r.x;
161 if ((cubeX - cubeSize) < hitX)
162 if ((cubeX + cubeSize) > hitX) {
163 final double hitY = (r.yp * mult) + r.y;
164 if ((cubeY - cubeSize) < hitY)
165 if ((cubeY + cubeSize) > hitY) {
168 r.hitZ = cubeZ + cubeSize;
176 if ((cubeY + cubeSize) < r.y) {
177 final double mult = ((cubeY + cubeSize) - r.y) / r.yp;
178 final double hitX = (r.xp * mult) + r.x;
179 if ((cubeX - cubeSize) < hitX)
180 if ((cubeX + cubeSize) > hitX) {
181 final double hitZ = (r.zp * mult) + r.z;
182 if ((cubeZ - cubeSize) < hitZ)
183 if ((cubeZ + cubeSize) > hitZ) {
185 r.hitY = cubeY + cubeSize;
194 if ((cubeX + cubeSize) < r.x) {
195 final double mult = ((cubeX + cubeSize) - r.x) / r.xp;
196 final double hitY = (r.yp * mult) + r.y;
197 if ((cubeY - cubeSize) < hitY)
198 if ((cubeY + cubeSize) > hitY) {
199 final double hitZ = (r.zp * mult) + r.z;
200 if ((cubeZ - cubeSize) < hitZ)
201 if ((cubeZ + cubeSize) > hitZ) {
202 r.hitX = cubeX + cubeSize;
215 public void fillRect3D(int x1, int y1, int z1, int x2, int y2, int z2,
236 for (int x = x1; x <= x2; x++)
237 for (int y = y1; y <= y2; y++)
238 for (int z = z1; z <= z2; z++)
239 putCell(x, y, z, 0, 0, 0, masterCellSize, 0, color);
243 public int getCellColor(final int pointer) {
247 public int getCellIllumination(final int pointer) {
251 public void initWorld(final int bufferLength, final int masterCellSize) {
252 // System.out.println("Initializing new world");
254 // initialize world storage buffer
255 this.masterCellSize = masterCellSize;
257 ce1 = new int[bufferLength];
258 ce2 = new int[bufferLength];
259 ce3 = new int[bufferLength];
260 ce4 = new int[bufferLength];
262 ce5 = new int[bufferLength];
263 ce6 = new int[bufferLength];
264 ce7 = new int[bufferLength];
265 ce8 = new int[bufferLength];
267 for (int i = 0; i < bufferLength; i++)
268 ce1[i] = CELL_STATE_UNUSED;
270 // initialize master cell
274 public boolean isCellSolid(final int pointer) {
275 return ce1[pointer] == CELL_STATE_SOLID;
278 public int makeNewCell() {
280 if (cellAllocationPointer >= ce1.length)
281 cellAllocationPointer = 0;
283 if (ce1[cellAllocationPointer] == CELL_STATE_UNUSED) {
285 clearCell(cellAllocationPointer);
288 return cellAllocationPointer;
290 cellAllocationPointer++;
294 public int makeNewCell(final int color, final int illumination) {
295 final int pointer = makeNewCell();
296 markCellAsSolid(pointer);
297 setCellColor(pointer, color);
298 setCellIllumination(pointer, illumination);
302 public void markCellAsSolid(final int pointer) {
303 ce1[pointer] = CELL_STATE_SOLID;
306 public void putCell(final int x, final int y, final int z, final Color color) {
307 putCell(x, y, z, 0, 0, 0, masterCellSize, 0, color);
310 private void putCell(final int x, final int y, final int z,
311 final int cellX, final int cellY, final int cellZ,
312 final int cellSize, final int cellPointer, final Color color) {
316 // if case of big cell
317 if (isCellSolid(cellPointer)) {
319 // if cell is already a needed color, do notheing
320 if (getCellColor(cellPointer) == color.toInt())
323 // otherwise break cell up
324 breakSolidCell(cellPointer);
326 // continue, as if it is cluster now
329 // decide witch subcube to use
331 int subX, subY, subZ;
334 subX = (cellSize / 2) + cellX;
336 subY = (cellSize / 2) + cellY;
338 subZ = (cellSize / 2) + cellZ;
342 subZ = (-cellSize / 2) + cellZ;
347 subY = (-cellSize / 2) + cellY;
349 subZ = (cellSize / 2) + cellZ;
353 subZ = (-cellSize / 2) + cellZ;
359 subX = (-cellSize / 2) + cellX;
361 subY = (cellSize / 2) + cellY;
363 subZ = (cellSize / 2) + cellZ;
367 subZ = (-cellSize / 2) + cellZ;
372 subY = (-cellSize / 2) + cellY;
374 subZ = (cellSize / 2) + cellZ;
378 subZ = (-cellSize / 2) + cellZ;
386 if (subCubeArray[cellPointer] == 0) {
387 // create empty cluster
388 subCubePointer = makeNewCell();
389 subCubeArray[cellPointer] = subCubePointer;
391 subCubePointer = subCubeArray[cellPointer];
393 putCell(x, y, z, subX, subY, subZ, cellSize / 2, subCubePointer,
396 ce1[cellPointer] = CELL_STATE_SOLID;
397 ce2[cellPointer] = color.toInt();
398 ce3[cellPointer] = CELL_STATE_UNUSED;
399 // System.out.println("Cell written!");
403 public void setCellColor(final int pointer, final int color) {
404 ce2[pointer] = color;
407 public void setCellIllumination(final int pointer, final int illumination) {
408 ce3[pointer] = illumination;
412 * @return intersecting cell pointer or -1 if no cell in intersecting this
415 public int traceCell(final int cellX, final int cellY, final int cellZ,
416 final int cellSize, final int pointer, final Ray ray) {
417 if (isCellSolid(pointer)) {
419 if (doesIntersect(cellX, cellY, cellZ, cellSize, ray) != 0) {
420 ray.hitCellSize = cellSize;
421 ray.hitCellX = cellX;
422 ray.hitCellY = cellY;
423 ray.hitCellZ = cellZ;
428 if (doesIntersect(cellX, cellY, cellZ, cellSize, ray) != 0) {
429 final int halfOfCellSize = cellSize / 2;
430 int rayIntersectionResult;
438 if (ce7[pointer] != 0) {
439 rayIntersectionResult = traceCell(cellX
440 + halfOfCellSize, cellY + halfOfCellSize,
441 cellZ + halfOfCellSize, halfOfCellSize,
443 if (rayIntersectionResult >= 0)
444 return rayIntersectionResult;
446 if (ce6[pointer] != 0) {
447 rayIntersectionResult = traceCell(cellX
448 + halfOfCellSize, cellY - halfOfCellSize,
449 cellZ + halfOfCellSize, halfOfCellSize,
451 if (rayIntersectionResult >= 0)
452 return rayIntersectionResult;
454 if (ce8[pointer] != 0) {
455 rayIntersectionResult = traceCell(cellX
456 - halfOfCellSize, cellY + halfOfCellSize,
457 cellZ + halfOfCellSize, halfOfCellSize,
459 if (rayIntersectionResult >= 0)
460 return rayIntersectionResult;
462 if (ce3[pointer] != 0) {
463 rayIntersectionResult = traceCell(cellX
464 + halfOfCellSize, cellY + halfOfCellSize,
465 cellZ - halfOfCellSize, halfOfCellSize,
467 if (rayIntersectionResult >= 0)
468 return rayIntersectionResult;
471 if (ce2[pointer] != 0) {
472 rayIntersectionResult = traceCell(cellX
473 + halfOfCellSize, cellY - halfOfCellSize,
474 cellZ - halfOfCellSize, halfOfCellSize,
476 if (rayIntersectionResult >= 0)
477 return rayIntersectionResult;
479 if (ce4[pointer] != 0) {
480 rayIntersectionResult = traceCell(cellX
481 - halfOfCellSize, cellY + halfOfCellSize,
482 cellZ - halfOfCellSize, halfOfCellSize,
484 if (rayIntersectionResult >= 0)
485 return rayIntersectionResult;
488 if (ce5[pointer] != 0) {
489 rayIntersectionResult = traceCell(cellX
490 - halfOfCellSize, cellY - halfOfCellSize,
491 cellZ + halfOfCellSize, halfOfCellSize,
493 if (rayIntersectionResult >= 0)
494 return rayIntersectionResult;
497 if (ce1[pointer] != 0) {
498 rayIntersectionResult = traceCell(cellX
499 - halfOfCellSize, cellY - halfOfCellSize,
500 cellZ - halfOfCellSize, halfOfCellSize,
502 if (rayIntersectionResult >= 0)
503 return rayIntersectionResult;
509 if (ce3[pointer] != 0) {
510 rayIntersectionResult = traceCell(cellX
511 + halfOfCellSize, cellY + halfOfCellSize,
512 cellZ - halfOfCellSize, halfOfCellSize,
514 if (rayIntersectionResult >= 0)
515 return rayIntersectionResult;
518 if (ce2[pointer] != 0) {
519 rayIntersectionResult = traceCell(cellX
520 + halfOfCellSize, cellY - halfOfCellSize,
521 cellZ - halfOfCellSize, halfOfCellSize,
523 if (rayIntersectionResult >= 0)
524 return rayIntersectionResult;
526 if (ce4[pointer] != 0) {
527 rayIntersectionResult = traceCell(cellX
528 - halfOfCellSize, cellY + halfOfCellSize,
529 cellZ - halfOfCellSize, halfOfCellSize,
531 if (rayIntersectionResult >= 0)
532 return rayIntersectionResult;
535 if (ce7[pointer] != 0) {
536 rayIntersectionResult = traceCell(cellX
537 + halfOfCellSize, cellY + halfOfCellSize,
538 cellZ + halfOfCellSize, halfOfCellSize,
540 if (rayIntersectionResult >= 0)
541 return rayIntersectionResult;
543 if (ce6[pointer] != 0) {
544 rayIntersectionResult = traceCell(cellX
545 + halfOfCellSize, cellY - halfOfCellSize,
546 cellZ + halfOfCellSize, halfOfCellSize,
548 if (rayIntersectionResult >= 0)
549 return rayIntersectionResult;
551 if (ce8[pointer] != 0) {
552 rayIntersectionResult = traceCell(cellX
553 - halfOfCellSize, cellY + halfOfCellSize,
554 cellZ + halfOfCellSize, halfOfCellSize,
556 if (rayIntersectionResult >= 0)
557 return rayIntersectionResult;
560 if (ce1[pointer] != 0) {
561 rayIntersectionResult = traceCell(cellX
562 - halfOfCellSize, cellY - halfOfCellSize,
563 cellZ - halfOfCellSize, halfOfCellSize,
565 if (rayIntersectionResult >= 0)
566 return rayIntersectionResult;
569 if (ce5[pointer] != 0) {
570 rayIntersectionResult = traceCell(cellX
571 - halfOfCellSize, cellY - halfOfCellSize,
572 cellZ + halfOfCellSize, halfOfCellSize,
574 if (rayIntersectionResult >= 0)
575 return rayIntersectionResult;
579 } else if (ray.z > cellZ) {
582 if (ce6[pointer] != 0) {
583 rayIntersectionResult = traceCell(cellX
584 + halfOfCellSize, cellY - halfOfCellSize, cellZ
585 + halfOfCellSize, halfOfCellSize, ce6[pointer],
587 if (rayIntersectionResult >= 0)
588 return rayIntersectionResult;
591 if (ce7[pointer] != 0) {
592 rayIntersectionResult = traceCell(cellX
593 + halfOfCellSize, cellY + halfOfCellSize, cellZ
594 + halfOfCellSize, halfOfCellSize, ce7[pointer],
596 if (rayIntersectionResult >= 0)
597 return rayIntersectionResult;
599 if (ce2[pointer] != 0) {
600 rayIntersectionResult = traceCell(cellX
601 + halfOfCellSize, cellY - halfOfCellSize, cellZ
602 - halfOfCellSize, halfOfCellSize, ce2[pointer],
604 if (rayIntersectionResult >= 0)
605 return rayIntersectionResult;
607 if (ce5[pointer] != 0) {
608 rayIntersectionResult = traceCell(cellX
609 - halfOfCellSize, cellY - halfOfCellSize, cellZ
610 + halfOfCellSize, halfOfCellSize, ce5[pointer],
612 if (rayIntersectionResult >= 0)
613 return rayIntersectionResult;
615 if (ce8[pointer] != 0) {
616 rayIntersectionResult = traceCell(cellX
617 - halfOfCellSize, cellY + halfOfCellSize, cellZ
618 + halfOfCellSize, halfOfCellSize, ce8[pointer],
620 if (rayIntersectionResult >= 0)
621 return rayIntersectionResult;
623 if (ce3[pointer] != 0) {
624 rayIntersectionResult = traceCell(cellX
625 + halfOfCellSize, cellY + halfOfCellSize, cellZ
626 - halfOfCellSize, halfOfCellSize, ce3[pointer],
628 if (rayIntersectionResult >= 0)
629 return rayIntersectionResult;
632 if (ce1[pointer] != 0) {
633 rayIntersectionResult = traceCell(cellX
634 - halfOfCellSize, cellY - halfOfCellSize, cellZ
635 - halfOfCellSize, halfOfCellSize, ce1[pointer],
637 if (rayIntersectionResult >= 0)
638 return rayIntersectionResult;
640 if (ce4[pointer] != 0) {
641 rayIntersectionResult = traceCell(cellX
642 - halfOfCellSize, cellY + halfOfCellSize, cellZ
643 - halfOfCellSize, halfOfCellSize, ce4[pointer],
645 if (rayIntersectionResult >= 0)
646 return rayIntersectionResult;
652 if (ce2[pointer] != 0) {
653 rayIntersectionResult = traceCell(cellX
654 + halfOfCellSize, cellY - halfOfCellSize, cellZ
655 - halfOfCellSize, halfOfCellSize, ce2[pointer],
657 if (rayIntersectionResult >= 0)
658 return rayIntersectionResult;
661 if (ce3[pointer] != 0) {
662 rayIntersectionResult = traceCell(cellX
663 + halfOfCellSize, cellY + halfOfCellSize, cellZ
664 - halfOfCellSize, halfOfCellSize, ce3[pointer],
666 if (rayIntersectionResult >= 0)
667 return rayIntersectionResult;
670 if (ce1[pointer] != 0) {
671 rayIntersectionResult = traceCell(cellX
672 - halfOfCellSize, cellY - halfOfCellSize, cellZ
673 - halfOfCellSize, halfOfCellSize, ce1[pointer],
675 if (rayIntersectionResult >= 0)
676 return rayIntersectionResult;
678 if (ce6[pointer] != 0) {
679 rayIntersectionResult = traceCell(cellX
680 + halfOfCellSize, cellY - halfOfCellSize, cellZ
681 + halfOfCellSize, halfOfCellSize, ce6[pointer],
683 if (rayIntersectionResult >= 0)
684 return rayIntersectionResult;
687 if (ce7[pointer] != 0) {
688 rayIntersectionResult = traceCell(cellX
689 + halfOfCellSize, cellY + halfOfCellSize, cellZ
690 + halfOfCellSize, halfOfCellSize, ce7[pointer],
692 if (rayIntersectionResult >= 0)
693 return rayIntersectionResult;
695 if (ce5[pointer] != 0) {
696 rayIntersectionResult = traceCell(cellX
697 - halfOfCellSize, cellY - halfOfCellSize, cellZ
698 + halfOfCellSize, halfOfCellSize, ce5[pointer],
700 if (rayIntersectionResult >= 0)
701 return rayIntersectionResult;
703 if (ce4[pointer] != 0) {
704 rayIntersectionResult = traceCell(cellX
705 - halfOfCellSize, cellY + halfOfCellSize, cellZ
706 - halfOfCellSize, halfOfCellSize, ce4[pointer],
708 if (rayIntersectionResult >= 0)
709 return rayIntersectionResult;
711 if (ce8[pointer] != 0) {
712 rayIntersectionResult = traceCell(cellX
713 - halfOfCellSize, cellY + halfOfCellSize, cellZ
714 + halfOfCellSize, halfOfCellSize, ce8[pointer],
716 if (rayIntersectionResult >= 0)
717 return rayIntersectionResult;
721 } else if (ray.y > cellY) {
726 if (ce8[pointer] != 0) {
727 rayIntersectionResult = traceCell(cellX
728 - halfOfCellSize, cellY + halfOfCellSize, cellZ
729 + halfOfCellSize, halfOfCellSize, ce8[pointer],
731 if (rayIntersectionResult >= 0)
732 return rayIntersectionResult;
734 if (ce7[pointer] != 0) {
735 rayIntersectionResult = traceCell(cellX
736 + halfOfCellSize, cellY + halfOfCellSize, cellZ
737 + halfOfCellSize, halfOfCellSize, ce7[pointer],
739 if (rayIntersectionResult >= 0)
740 return rayIntersectionResult;
742 if (ce5[pointer] != 0) {
743 rayIntersectionResult = traceCell(cellX
744 - halfOfCellSize, cellY - halfOfCellSize, cellZ
745 + halfOfCellSize, halfOfCellSize, ce5[pointer],
747 if (rayIntersectionResult >= 0)
748 return rayIntersectionResult;
750 if (ce4[pointer] != 0) {
751 rayIntersectionResult = traceCell(cellX
752 - halfOfCellSize, cellY + halfOfCellSize, cellZ
753 - halfOfCellSize, halfOfCellSize, ce4[pointer],
755 if (rayIntersectionResult >= 0)
756 return rayIntersectionResult;
759 if (ce3[pointer] != 0) {
760 rayIntersectionResult = traceCell(cellX
761 + halfOfCellSize, cellY + halfOfCellSize, cellZ
762 - halfOfCellSize, halfOfCellSize, ce3[pointer],
764 if (rayIntersectionResult >= 0)
765 return rayIntersectionResult;
768 if (ce1[pointer] != 0) {
769 rayIntersectionResult = traceCell(cellX
770 - halfOfCellSize, cellY - halfOfCellSize, cellZ
771 - halfOfCellSize, halfOfCellSize, ce1[pointer],
773 if (rayIntersectionResult >= 0)
774 return rayIntersectionResult;
776 if (ce6[pointer] != 0) {
777 rayIntersectionResult = traceCell(cellX
778 + halfOfCellSize, cellY - halfOfCellSize, cellZ
779 + halfOfCellSize, halfOfCellSize, ce6[pointer],
781 if (rayIntersectionResult >= 0)
782 return rayIntersectionResult;
785 if (ce2[pointer] != 0) {
786 rayIntersectionResult = traceCell(cellX
787 + halfOfCellSize, cellY - halfOfCellSize, cellZ
788 - halfOfCellSize, halfOfCellSize, ce2[pointer],
790 if (rayIntersectionResult >= 0)
791 return rayIntersectionResult;
798 if (ce4[pointer] != 0) {
799 rayIntersectionResult = traceCell(cellX
800 - halfOfCellSize, cellY + halfOfCellSize, cellZ
801 - halfOfCellSize, halfOfCellSize, ce4[pointer],
803 if (rayIntersectionResult >= 0)
804 return rayIntersectionResult;
807 if (ce8[pointer] != 0) {
808 rayIntersectionResult = traceCell(cellX
809 - halfOfCellSize, cellY + halfOfCellSize, cellZ
810 + halfOfCellSize, halfOfCellSize, ce8[pointer],
812 if (rayIntersectionResult >= 0)
813 return rayIntersectionResult;
815 if (ce3[pointer] != 0) {
816 rayIntersectionResult = traceCell(cellX
817 + halfOfCellSize, cellY + halfOfCellSize, cellZ
818 - halfOfCellSize, halfOfCellSize, ce3[pointer],
820 if (rayIntersectionResult >= 0)
821 return rayIntersectionResult;
824 if (ce1[pointer] != 0) {
825 rayIntersectionResult = traceCell(cellX
826 - halfOfCellSize, cellY - halfOfCellSize, cellZ
827 - halfOfCellSize, halfOfCellSize, ce1[pointer],
829 if (rayIntersectionResult >= 0)
830 return rayIntersectionResult;
832 if (ce7[pointer] != 0) {
833 rayIntersectionResult = traceCell(cellX
834 + halfOfCellSize, cellY + halfOfCellSize, cellZ
835 + halfOfCellSize, halfOfCellSize, ce7[pointer],
837 if (rayIntersectionResult >= 0)
838 return rayIntersectionResult;
840 if (ce5[pointer] != 0) {
841 rayIntersectionResult = traceCell(cellX
842 - halfOfCellSize, cellY - halfOfCellSize, cellZ
843 + halfOfCellSize, halfOfCellSize, ce5[pointer],
845 if (rayIntersectionResult >= 0)
846 return rayIntersectionResult;
849 if (ce2[pointer] != 0) {
850 rayIntersectionResult = traceCell(cellX
851 + halfOfCellSize, cellY - halfOfCellSize, cellZ
852 - halfOfCellSize, halfOfCellSize, ce2[pointer],
854 if (rayIntersectionResult >= 0)
855 return rayIntersectionResult;
857 if (ce6[pointer] != 0) {
858 rayIntersectionResult = traceCell(cellX
859 + halfOfCellSize, cellY - halfOfCellSize, cellZ
860 + halfOfCellSize, halfOfCellSize, ce6[pointer],
862 if (rayIntersectionResult >= 0)
863 return rayIntersectionResult;
867 } else if (ray.z > cellZ) {
871 if (ce5[pointer] != 0) {
872 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
873 cellY - halfOfCellSize, cellZ + halfOfCellSize,
874 halfOfCellSize, ce5[pointer], ray);
875 if (rayIntersectionResult >= 0)
876 return rayIntersectionResult;
879 if (ce1[pointer] != 0) {
880 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
881 cellY - halfOfCellSize, cellZ - halfOfCellSize,
882 halfOfCellSize, ce1[pointer], ray);
883 if (rayIntersectionResult >= 0)
884 return rayIntersectionResult;
887 if (ce6[pointer] != 0) {
888 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
889 cellY - halfOfCellSize, cellZ + halfOfCellSize,
890 halfOfCellSize, ce6[pointer], ray);
891 if (rayIntersectionResult >= 0)
892 return rayIntersectionResult;
895 if (ce8[pointer] != 0) {
896 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
897 cellY + halfOfCellSize, cellZ + halfOfCellSize,
898 halfOfCellSize, ce8[pointer], ray);
899 if (rayIntersectionResult >= 0)
900 return rayIntersectionResult;
903 if (ce4[pointer] != 0) {
904 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
905 cellY + halfOfCellSize, cellZ - halfOfCellSize,
906 halfOfCellSize, ce4[pointer], ray);
907 if (rayIntersectionResult >= 0)
908 return rayIntersectionResult;
911 if (ce7[pointer] != 0) {
912 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
913 cellY + halfOfCellSize, cellZ + halfOfCellSize,
914 halfOfCellSize, ce7[pointer], ray);
915 if (rayIntersectionResult >= 0)
916 return rayIntersectionResult;
919 if (ce2[pointer] != 0) {
920 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
921 cellY - halfOfCellSize, cellZ - halfOfCellSize,
922 halfOfCellSize, ce2[pointer], ray);
923 if (rayIntersectionResult >= 0)
924 return rayIntersectionResult;
927 if (ce3[pointer] != 0) {
928 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
929 cellY + halfOfCellSize, cellZ - halfOfCellSize,
930 halfOfCellSize, ce3[pointer], ray);
931 if (rayIntersectionResult >= 0)
932 return rayIntersectionResult;
939 if (ce1[pointer] != 0) {
940 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
941 cellY - halfOfCellSize, cellZ - halfOfCellSize,
942 halfOfCellSize, ce1[pointer], ray);
943 if (rayIntersectionResult >= 0)
944 return rayIntersectionResult;
947 if (ce5[pointer] != 0) {
948 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
949 cellY - halfOfCellSize, cellZ + halfOfCellSize,
950 halfOfCellSize, ce5[pointer], ray);
951 if (rayIntersectionResult >= 0)
952 return rayIntersectionResult;
954 if (ce2[pointer] != 0) {
955 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
956 cellY - halfOfCellSize, cellZ - halfOfCellSize,
957 halfOfCellSize, ce2[pointer], ray);
958 if (rayIntersectionResult >= 0)
959 return rayIntersectionResult;
962 if (ce4[pointer] != 0) {
963 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
964 cellY + halfOfCellSize, cellZ - halfOfCellSize,
965 halfOfCellSize, ce4[pointer], ray);
966 if (rayIntersectionResult >= 0)
967 return rayIntersectionResult;
970 if (ce6[pointer] != 0) {
971 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
972 cellY - halfOfCellSize, cellZ + halfOfCellSize,
973 halfOfCellSize, ce6[pointer], ray);
974 if (rayIntersectionResult >= 0)
975 return rayIntersectionResult;
978 if (ce8[pointer] != 0) {
979 rayIntersectionResult = traceCell(cellX - halfOfCellSize,
980 cellY + halfOfCellSize, cellZ + halfOfCellSize,
981 halfOfCellSize, ce8[pointer], ray);
982 if (rayIntersectionResult >= 0)
983 return rayIntersectionResult;
986 if (ce3[pointer] != 0) {
987 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
988 cellY + halfOfCellSize, cellZ - halfOfCellSize,
989 halfOfCellSize, ce3[pointer], ray);
990 if (rayIntersectionResult >= 0)
991 return rayIntersectionResult;
993 if (ce7[pointer] != 0) {
994 rayIntersectionResult = traceCell(cellX + halfOfCellSize,
995 cellY + halfOfCellSize, cellZ + halfOfCellSize,
996 halfOfCellSize, ce7[pointer], ray);
997 if (rayIntersectionResult >= 0)
998 return rayIntersectionResult;
1002 return TRACE_NO_HIT;