Skip to content

Instantly share code, notes, and snippets.

@Corosauce
Created July 15, 2013 20:57
Show Gist options
  • Save Corosauce/6003401 to your computer and use it in GitHub Desktop.
Save Corosauce/6003401 to your computer and use it in GitHub Desktop.
/* coords: unrotated world coord, rotation: quantify to 90, start: uncentered world coords for structure start point, size: structure size */
public ChunkCoordinates rotate(ChunkCoordinates coords, double rotation, Vec3 start, Vec3 size) {
double centerX = start.xCoord+(size.xCoord/2D);
double centerZ = start.zCoord+(size.zCoord/2D);
double vecX = coords.posX - centerX + 0.05; //+0.05 fixes the 0 angle distance calculation issue
double vecZ = coords.posZ - centerZ + 0.05;
double distToCenter = Math.sqrt(vecX * vecX + vecZ * vecZ);
double rotYaw = (float)(Math.atan2(vecZ, vecX) * 180.0D / Math.PI) - rotation;
double newX = start.xCoord + Math.cos(rotYaw * 0.017453D) * distToCenter;
double newZ = start.zCoord + Math.sin(rotYaw * 0.017453D) * distToCenter;
return new ChunkCoordinates((int)Math.floor(newX), coords.posY, (int)Math.floor(newZ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment