/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.anzix.fsz.voxelworld;
import net.anzix.fsz.voxelworld.layers.LayerBlockPosition;
import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyVector3;
/**
*
* @author kovacsandras
*/
public class VoxelBlockPosition extends AbstractBlockPosition{
@Override
public String toString() {
return "POSITION: " + x + "," + y + "," + z;
}
public int x,y,z;
VoxelBlockPosition() {
this.x = 0;
this.y = 0;
this.z = 0;
}
VoxelBlockPosition(final int x, final int y, final int z) {
this.x = x;
this.y = y;
this.z = z;
}
VoxelBlockPosition(VoxelBlockPosition p) {
this.x = p.x;
this.y = p.y;
this.z = p.z;
}
VoxelBlockPosition(final ReadOnlyVector3 worldPosition, final DetailLevel level) {
double scale = VoxelWorld.BLOCK_SIZE*level.getScale();
this.x = (int)Math.floor(worldPosition.getX()/scale);
this.y = (int)Math.floor(worldPosition.getY()/scale);
this.z = (int)Math.floor(worldPosition.getZ()/scale);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final VoxelBlockPosition other = (VoxelBlockPosition) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
if (this.z != other.z) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 59 * hash + this.x;
hash = 59 * hash + this.y;
hash = 59 * hash + this.z;
return hash;
}
@Override
public Vector3 getAsWorldCoords(DetailLevel level) {
double scale = VoxelWorld.BLOCK_SIZE*level.getScale();
return new Vector3(x*scale, y*scale, z*scale);
}
public double getBottomHeight(DetailLevel level) {
double scale = VoxelWorld.BLOCK_SIZE*level.getScale();
return y*scale;
}
public double getTopHeight(DetailLevel level) {
double scale = VoxelWorld.BLOCK_SIZE*level.getScale();
return (y+1)*scale;
}
@Override
public int distance(AbstractBlockPosition other) {
if (other instanceof VoxelBlockPosition) {
final VoxelBlockPosition o = (VoxelBlockPosition) other;
return Math.max(Math.abs(x-o.x), Math.max(Math.abs(y-o.y), Math.abs(z-o.z)));
}
if (other instanceof LayerBlockPosition) {
final LayerBlockPosition o = (LayerBlockPosition) other;
return Math.max(Math.abs(x-o.x), Math.abs(z-o.z));
}
return 0;
}
public void compose(final LayerBlockPosition layerBlockPosition, int y) {
this.x = layerBlockPosition.x;
this.y = y;
this.z = layerBlockPosition.z;
}
@Override
public boolean isInBlock(ReadOnlyVector3 positionInWorldCoords, DetailLevel level) {
Vector3 blockCornerInWorldCoords = getAsWorldCoords(level);
if (positionInWorldCoords.getX() < blockCornerInWorldCoords.getX()
|| positionInWorldCoords.getY() < blockCornerInWorldCoords.getY()
|| positionInWorldCoords.getZ() < blockCornerInWorldCoords.getZ() )
return false;
double blockSize = VoxelWorld.BLOCK_SIZE * level.getScale();
if (positionInWorldCoords.getX() >= blockCornerInWorldCoords.getX() + blockSize
|| positionInWorldCoords.getY() >= blockCornerInWorldCoords.getY() + blockSize
|| positionInWorldCoords.getZ() >= blockCornerInWorldCoords.getZ() + blockSize)
return false;
return true;
}
}