Skip to content

Instantly share code, notes, and snippets.

@matyklug18
Created December 8, 2019 15:20
Show Gist options
  • Save matyklug18/bd37c21a138844baf24fad655cf43335 to your computer and use it in GitHub Desktop.
Save matyklug18/bd37c21a138844baf24fad655cf43335 to your computer and use it in GitHub Desktop.
Vector3i end = new Vector3i((int) floor(rayPos.x), (int) floor(rayPos.y), (int) floor(rayPos.z));
float dToPX = (float) (end.x-floor(end.x));
float dToPY = (float) (end.y-floor(end.y));
float dToPZ = (float) (end.z-floor(end.z));
float dToNX = abs(1-dToPX);
float dToNY = abs(1-dToPY);
float dToNZ = abs(1-dToPZ);
BlockSide side;
float smallestValue = 0;
smallestValue = dToPX;
side = BlockSide.RIGHT;
if(smallestValue > dToPY) {
smallestValue = dToPY;
side = BlockSide.TOP;
}
if(smallestValue > dToPZ) {
smallestValue = dToPZ;
side = BlockSide.BACK;
}
if(smallestValue > dToPY) {
smallestValue = dToPY;
side = BlockSide.TOP;
}
if(smallestValue > dToNX) {
smallestValue = dToNX;
side = BlockSide.LEFT;
}
if(smallestValue > dToNY) {
smallestValue = dToNY;
side = BlockSide.BOTTOM;
}
if(smallestValue > dToNZ) {
smallestValue = dToNZ;
side = BlockSide.FRONT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment