Abort ray-tracing if there is no advance. Formatting + numbers.

If there is no advance on any axis, loop should be stopped.
This commit is contained in:
asofold 2014-07-13 03:19:28 +02:00
parent aba5674f6a
commit 4ebe911509

View File

@ -76,7 +76,7 @@ public abstract class RayTracing {
private static final double tDiff(final double dTotal, final double offset){ private static final double tDiff(final double dTotal, final double offset){
if (dTotal > 0.0){ if (dTotal > 0.0){
return (1 - offset) / dTotal; return (1.0 - offset) / dTotal;
} }
else if (dTotal < 0.0){ else if (dTotal < 0.0){
return offset / -dTotal; return offset / -dTotal;
@ -101,11 +101,22 @@ public abstract class RayTracing {
tY = tDiff(dY, oY); tY = tDiff(dY, oY);
tZ = tDiff(dZ, oZ); tZ = tDiff(dZ, oZ);
tMin = Math.min(tX, Math.min(tY, tZ)); tMin = Math.min(tX, Math.min(tY, tZ));
if (tMin == Double.MAX_VALUE || t + tMin > 1.0) tMin = 1.0 - t; if (tMin == Double.MAX_VALUE) {
// All differences are 0 (no progress).
break;
}
if (t + tMin > 1.0) {
// Set to the remaining distance (does trigger).
tMin = 1.0 - t;
}
// Call step with appropriate arguments. // Call step with appropriate arguments.
step ++; step ++;
if (!step(blockX, blockY, blockZ, oX, oY, oZ, tMin)) break; // || tMin == 0) break; if (!step(blockX, blockY, blockZ, oX, oY, oZ, tMin)) {
if (t + tMin >= 1.0 - tol) break; break; // || tMin == 0) break;
}
if (t + tMin >= 1.0 - tol) {
break;
}
// Advance (add to t etc.). // Advance (add to t etc.).
changed = false; changed = false;
// TODO: Some not handled cases would mean errors. // TODO: Some not handled cases would mean errors.
@ -113,23 +124,23 @@ public abstract class RayTracing {
oX += tMin * dX; oX += tMin * dX;
if (tX == tMin){ if (tX == tMin){
if (dX < 0){ if (dX < 0){
oX = 1; oX = 1.0;
blockX --; blockX --;
changed = true; changed = true;
} }
else if (dX > 0){ else if (dX > 0){
oX = 0; oX = 0.0;
blockX ++; blockX ++;
changed = true; changed = true;
} }
} }
else if (oX >= 1 && dX > 0.0){ else if (oX >= 1.0 && dX > 0.0){
oX -= 1; oX -= 1.0;
blockX ++; blockX ++;
changed = true; changed = true;
} }
else if (oX < 0 && dX < 0.0){ else if (oX < 0 && dX < 0.0){
oX += 1; oX += 1.0;
blockX --; blockX --;
changed = true; changed = true;
} }
@ -137,23 +148,23 @@ public abstract class RayTracing {
oY += tMin * dY; oY += tMin * dY;
if (tY == tMin){ if (tY == tMin){
if (dY < 0){ if (dY < 0){
oY = 1; oY = 1.0;
blockY --; blockY --;
changed = true; changed = true;
} }
else if (dY > 0){ else if (dY > 0){
oY = 0; oY = 0.0;
blockY ++; blockY ++;
changed = true; changed = true;
} }
} }
else if (oY >= 1 && dY > 0.0){ else if (oY >= 1 && dY > 0.0){
oY -= 1; oY -= 1.0;
blockY ++; blockY ++;
changed = true; changed = true;
} }
else if (oY < 0 && dY < 0.0){ else if (oY < 0 && dY < 0.0){
oY += 1; oY += 1.0;
blockY --; blockY --;
changed = true; changed = true;
} }
@ -161,23 +172,23 @@ public abstract class RayTracing {
oZ += tMin * dZ; oZ += tMin * dZ;
if (tZ == tMin){ if (tZ == tMin){
if (dZ < 0){ if (dZ < 0){
oZ = 1; oZ = 1.0;
blockZ --; blockZ --;
changed = true; changed = true;
} }
else if (dZ > 0){ else if (dZ > 0){
oZ = 0; oZ = 0.0;
blockZ ++; blockZ ++;
changed = true; changed = true;
} }
} }
else if (oZ >= 1 && dZ > 0.0){ else if (oZ >= 1 && dZ > 0.0){
oZ -= 1; oZ -= 1.0;
blockZ ++; blockZ ++;
changed = true; changed = true;
} }
else if (oZ < 0 && dZ < 0.0){ else if (oZ < 0 && dZ < 0.0){
oZ += 1; oZ += 1.0;
blockZ --; blockZ --;
changed = true; changed = true;
} }