mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-15 03:51:20 +01:00
Attempt to fix a ray-tracing issue.
This commit is contained in:
parent
0932edd6ee
commit
d564cf17e9
@ -21,6 +21,9 @@ public abstract class RayTracing {
|
|||||||
/** Current block. */
|
/** Current block. */
|
||||||
protected int blockX, blockY, blockZ;
|
protected int blockX, blockY, blockZ;
|
||||||
|
|
||||||
|
/** End block. */
|
||||||
|
protected int endBlockX, endBlockY, endBlockZ;
|
||||||
|
|
||||||
/** Offset within current block. */
|
/** Offset within current block. */
|
||||||
protected double oX, oY, oZ;
|
protected double oX, oY, oZ;
|
||||||
|
|
||||||
@ -67,6 +70,9 @@ public abstract class RayTracing {
|
|||||||
blockX = Location.locToBlock(x0);
|
blockX = Location.locToBlock(x0);
|
||||||
blockY = Location.locToBlock(y0);
|
blockY = Location.locToBlock(y0);
|
||||||
blockZ = Location.locToBlock(z0);
|
blockZ = Location.locToBlock(z0);
|
||||||
|
endBlockX = Location.locToBlock(x1);
|
||||||
|
endBlockY = Location.locToBlock(y1);
|
||||||
|
endBlockZ = Location.locToBlock(z1);
|
||||||
oX = (double) (x0 - blockX);
|
oX = (double) (x0 - blockX);
|
||||||
oY = (double) (y0 - blockY);
|
oY = (double) (y0 - blockY);
|
||||||
oZ = (double) (z0 - blockZ);
|
oZ = (double) (z0 - blockZ);
|
||||||
@ -74,11 +80,11 @@ public abstract class RayTracing {
|
|||||||
step = 0;
|
step = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double tDiff(final double dTotal, final double offset){
|
private static final double tDiff(final double dTotal, final double offset, final int block, final int endBlock){
|
||||||
if (dTotal > 0.0){
|
if (dTotal > 0.0){
|
||||||
if (offset >= 1.0) {
|
if (offset >= 1.0) {
|
||||||
// Static block change (e.g. diagonal move).
|
// Static block change (e.g. diagonal move).
|
||||||
return 0.0;
|
return block == endBlock ? Double.MAX_VALUE : 0.0;
|
||||||
} else {
|
} else {
|
||||||
return (1.0 - offset) / dTotal;
|
return (1.0 - offset) / dTotal;
|
||||||
}
|
}
|
||||||
@ -86,7 +92,7 @@ public abstract class RayTracing {
|
|||||||
else if (dTotal < 0.0){
|
else if (dTotal < 0.0){
|
||||||
if (offset <= 0.0) {
|
if (offset <= 0.0) {
|
||||||
// Static block change (e.g. diagonal move).
|
// Static block change (e.g. diagonal move).
|
||||||
return 0.0;
|
return block == endBlock ? Double.MAX_VALUE : 0.0;
|
||||||
} else {
|
} else {
|
||||||
return offset / -dTotal;
|
return offset / -dTotal;
|
||||||
}
|
}
|
||||||
@ -107,9 +113,9 @@ public abstract class RayTracing {
|
|||||||
boolean changed;
|
boolean changed;
|
||||||
while (1.0 - t > tol){
|
while (1.0 - t > tol){
|
||||||
// Determine smallest time to block edge.
|
// Determine smallest time to block edge.
|
||||||
tX = tDiff(dX, oX);
|
tX = tDiff(dX, oX, blockX, endBlockX);
|
||||||
tY = tDiff(dY, oY);
|
tY = tDiff(dY, oY, blockY, endBlockY);
|
||||||
tZ = tDiff(dZ, oZ);
|
tZ = tDiff(dZ, oZ, blockZ, endBlockZ);
|
||||||
tMin = Math.min(tX, Math.min(tY, tZ));
|
tMin = Math.min(tX, Math.min(tY, tZ));
|
||||||
if (tMin == Double.MAX_VALUE) {
|
if (tMin == Double.MAX_VALUE) {
|
||||||
// All differences are 0 (no progress).
|
// All differences are 0 (no progress).
|
||||||
@ -186,6 +192,7 @@ public abstract class RayTracing {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: Catch special case with going beyond coordinates.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,8 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
|
|||||||
|
|
||||||
public class TestRayTracing {
|
public class TestRayTracing {
|
||||||
|
|
||||||
|
// TODO: Add a test that fails if going beyond target block coordinate.
|
||||||
|
|
||||||
protected static final Random random = new Random(System.nanoTime() + 13391);
|
protected static final Random random = new Random(System.nanoTime() + 13391);
|
||||||
|
|
||||||
protected static double maxFactor = 9.0;
|
protected static double maxFactor = 9.0;
|
||||||
@ -90,9 +92,9 @@ public class TestRayTracing {
|
|||||||
step = 0;
|
step = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private boolean ignEdge(double offset, double dTotal){
|
// private boolean ignEdge(double offset, double dTotal){
|
||||||
// return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0;
|
// return offset == 1 && dTotal > 0 || offset == 0 && dTotal < 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean step(int blockX, int blockY, int blockZ, double oX, double oY, double oZ, double dT) {
|
protected boolean step(int blockX, int blockY, int blockZ, double oX, double oY, double oZ, double dT) {
|
||||||
@ -102,13 +104,13 @@ public class TestRayTracing {
|
|||||||
if (dT < 0.0){
|
if (dT < 0.0){
|
||||||
doFail("dT < 0 at t = " + StringUtil.fdec3.format(t), coords);
|
doFail("dT < 0 at t = " + StringUtil.fdec3.format(t), coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if this check makes sense at all (dT=0 happens during multi-transitions.)l.
|
// TODO: Check if this check makes sense at all (dT=0 happens during multi-transitions.)l.
|
||||||
// if (dT == 0.0 && 1.0 - (t + dT) > tol){
|
// if (dT == 0.0 && 1.0 - (t + dT) > tol){
|
||||||
// if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)){
|
// if (!ignEdge(oX, dX) && !ignEdge(oY, dY) && !ignEdge(oZ, dZ)){
|
||||||
// doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords);
|
// doFail("Premature dT = 0 at t = " + StringUtil.fdec3.format(t), coords);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
checkOffset(oX, "x");
|
checkOffset(oX, "x");
|
||||||
checkOffset(oY, "y");
|
checkOffset(oY, "y");
|
||||||
|
Loading…
Reference in New Issue
Block a user