Reputation: 816
I have this code:
public static final BlockFace[] axis = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
public static final BlockFace[] radial = {BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST};
public static BlockFace yawToFace(float yaw, boolean useSubCardinalDirections) {
if (useSubCardinalDirections) {
return radial[Math.round(yaw / 45f) & 0x7];
} else {
return axis[Math.round(yaw / 90f) & 0x3];
}
}
How would I go about reversing this in an efficient matter? I can think of a few brute-forcey ways, but they seem very inefficient.
So, what I have is a yawToFace() method, I want to create a faceToYaw() method.
Any help would be greatly appreciate. Thank you! :)
Upvotes: 1
Views: 124
Reputation: 774
I think storing the degrees in the BlockFace enum would be totally acceptable. Otherwise you'd need to search through the arrays, find the matching index, and then multiply by 45 or 90.
Upvotes: 3