/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
* This project is released under Creative Commons Zero (CC0) license.
*/
package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
final double cy3 = cy1 + ((y3p * x) / width);
final double cz3 = cz1 + ((z3p * x) / width);
- final Ray r = new Ray(cameraView.cameraCenter.x,
- cameraView.cameraCenter.y, cameraView.cameraCenter.z, cx3
- - cameraView.cameraCenter.x, cy3
- - cameraView.cameraCenter.y, cz3
- - cameraView.cameraCenter.z);
+ final Ray r = new Ray(
+ new Point3D(cameraView.cameraCenter.x,
+ cameraView.cameraCenter.y,
+ cameraView.cameraCenter.z),
+ new Point3D(
+ cx3 - cameraView.cameraCenter.x, cy3
+ - cameraView.cameraCenter.y, cz3
+ - cameraView.cameraCenter.z)
+ );
final int c = traceRay(r);
final Color color = new Color(c);
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
float red = 30, green = 30, blue = 30;
for (final LightSource l : lights) {
- final int xDist = (l.x - ray.hitCellX);
- final int yDist = (l.y - ray.hitCellY);
- final int zDist = (l.z - ray.hitCellZ);
+ final double xDist = (l.location.x - ray.hitCellX);
+ final double yDist = (l.location.y - ray.hitCellY);
+ final double zDist = (l.location.z - ray.hitCellZ);
double newRed = 0, newGreen = 0, newBlue = 0;
double tempRed, tempGreen, tempBlue;
+ (yDist * yDist) + (zDist * zDist));
distance = (distance / 3) + 1;
- final Ray r1 = new Ray(ray.hitCellX, ray.hitCellY
- - (float) 1.5, ray.hitCellZ,
+ final Ray r1 = new Ray(
+ new Point3D(
+ ray.hitCellX,
+ ray.hitCellY - (float) 1.5,
+ ray.hitCellZ),
- (float) l.x - (float) ray.hitCellX, l.y
- - (ray.hitCellY - (float) 1.5), (float) l.z
- - (float) ray.hitCellZ);
+ new Point3D((float) l.location.x - (float) ray.hitCellX, l.location.y
+ - (ray.hitCellY - (float) 1.5), (float) l.location.z
+ - (float) ray.hitCellZ)
+ );
final int rt1 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r1);
newBlue = (l.color.b * l.brightness) / distance;
}
- final Ray r2 = new Ray(ray.hitCellX - (float) 1.5,
- ray.hitCellY, ray.hitCellZ,
+ final Ray r2 = new Ray(
+ new Point3D(
+ ray.hitCellX - (float) 1.5,
+ ray.hitCellY, ray.hitCellZ),
- l.x - (ray.hitCellX - (float) 1.5), (float) l.y
- - (float) ray.hitCellY, (float) l.z
- - (float) ray.hitCellZ);
+ new Point3D(
+ l.location.x - (ray.hitCellX - (float) 1.5), (float) l.location.y
+ - (float) ray.hitCellY, (float) l.location.z
+ - (float) ray.hitCellZ)
+ );
final int rt2 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r2);
newBlue = tempBlue;
}
- final Ray r3 = new Ray(ray.hitCellX, ray.hitCellY,
- ray.hitCellZ - (float) 1.5,
-
- (float) l.x - (float) ray.hitCellX, (float) l.y
- - (float) ray.hitCellY, l.z
- - (ray.hitCellZ - (float) 1.5));
+ final Ray r3 = new Ray(
+ new Point3D(
+ ray.hitCellX, ray.hitCellY,
+ ray.hitCellZ - (float) 1.5),
+ new Point3D(
+ (float) l.location.x - (float) ray.hitCellX, (float) l.location.y
+ - (float) ray.hitCellY, l.location.z
+ - (ray.hitCellZ - (float) 1.5))
+ );
final int rt3 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r3);
newBlue = tempBlue;
}
- final Ray r4 = new Ray(ray.hitCellX, ray.hitCellY
- + (float) 1.5, ray.hitCellZ,
+ final Ray r4 = new Ray(
+ new Point3D(
+ ray.hitCellX,
+ ray.hitCellY + (float) 1.5,
+ ray.hitCellZ),
- (float) l.x - (float) ray.hitCellX, l.y
- - (ray.hitCellY + (float) 1.5), (float) l.z
- - (float) ray.hitCellZ);
+ new Point3D(
+ (float) l.location.x - (float) ray.hitCellX, l.location.y
+ - (ray.hitCellY + (float) 1.5), (float) l.location.z
+ - (float) ray.hitCellZ)
+ );
final int rt4 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r4);
newBlue = tempBlue;
}
- final Ray r5 = new Ray(ray.hitCellX + (float) 1.5,
- ray.hitCellY, ray.hitCellZ,
+ final Ray r5 = new Ray(
+ new Point3D(
+ ray.hitCellX + (float) 1.5,
+ ray.hitCellY, ray.hitCellZ),
- l.x - (ray.hitCellX + (float) 1.5), (float) l.y
- - (float) ray.hitCellY, (float) l.z
- - (float) ray.hitCellZ);
+ new Point3D(
+ l.location.x - (ray.hitCellX + (float) 1.5), (float) l.location.y
+ - (float) ray.hitCellY, (float) l.location.z
+ - (float) ray.hitCellZ)
+ );
final int rt5 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r5);
newBlue = tempBlue;
}
- final Ray r6 = new Ray(ray.hitCellX, ray.hitCellY,
- ray.hitCellZ + (float) 1.5,
+ final Ray r6 = new Ray(
+ new Point3D(
+ ray.hitCellX, ray.hitCellY,
+ ray.hitCellZ + (float) 1.5),
+
+ new Point3D(
- (float) l.x - (float) ray.hitCellX, (float) l.y
- - (float) ray.hitCellY, l.z
- - (ray.hitCellZ + (float) 1.5));
+ (float) l.location.x - (float) ray.hitCellX, (float) l.location.y
+ - (float) ray.hitCellY, l.location.z
+ - (ray.hitCellZ + (float) 1.5)));
final int rt6 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r6);
}
- final int cellColor = octreeVolume.ce2[intersectingCell];
+ final int cellColor = octreeVolume.cell2[intersectingCell];
red = (red * ((cellColor & 0xFF0000) >> 16)) / 255;
green = (green * ((cellColor & 0xFF00) >> 8)) / 255;
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;