* Calculate a camera position centered above all loaded chunks.
* @return The calculated camera position
*/
public Vector3d calcCenterCamera() {
if (chunks.isEmpty())
return new Vector3d(0, 128, 0);
int xmin = Integer.MAX_VALUE;
int xmax = Integer.MIN_VALUE;
int zmin = Integer.MAX_VALUE;
int zmax = Integer.MIN_VALUE;
for (ChunkPosition cp: chunks) {
if (cp.x < xmin)
xmin = cp.x;
if (cp.x > xmax)
xmax = cp.x;
if (cp.z < zmin)
zmin = cp.z;
if (cp.z > zmax)
zmax = cp.z;
}
xmax += 1;
zmax += 1;
xmin *= 16;
xmax *= 16;
zmin *= 16;
zmax *= 16;
int xcenter = (xmax + xmin)/2;
int zcenter = (zmax + zmin)/2;
for (int y = Chunk.Y_MAX-1; y >= 0; --y) {
int block = octree.get(xcenter - origin.x, y - origin.y,
zcenter - origin.z);
if (Block.get(block) != Block.AIR) {
return new Vector3d(xcenter, y+5, zcenter);
}
}
return new Vector3d(xcenter, 128, zcenter);
}