Add: Helper methods for obtaining X and Z coordinates of chunk given a block's X and Z world coordinates.

This commit is contained in:
Nicolas Reed 2015-05-04 00:58:13 -04:00
parent d4f93f8266
commit cfa49b50a4
2 changed files with 12 additions and 2 deletions

View File

@ -174,6 +174,16 @@ namespace TrueCraft.Core
return ChunkZ * Chunk.Depth + BlockCoord;
}
public static int BlockToChunkX(int BlockCoord)
{
return (int)Math.Floor((double)BlockCoord / Chunk.Width);
}
public static int BlockToChunkZ(int BlockCoord)
{
return (int)Math.Floor((double)BlockCoord / Chunk.Depth);
}
/// <summary>
/// Returns a value indicating the most extreme value of the
/// provided Vector.

View File

@ -299,8 +299,8 @@ namespace TrueCraft.Core.World
if (coordinates.Y < 0 || coordinates.Y >= Chunk.Height)
throw new ArgumentOutOfRangeException("coordinates", "Coordinates are out of range");
var chunkX = (int)Math.Floor((double)coordinates.X / Chunk.Width);
var chunkZ = (int)Math.Floor((double)coordinates.Z / Chunk.Depth);
var chunkX = MathHelper.BlockToChunkX(coordinates.X);
var chunkZ = MathHelper.BlockToChunkZ(coordinates.Z);
chunk = GetChunk(new Coordinates2D(chunkX, chunkZ));
return new Coordinates3D(