/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.anzix.fsz.voxelworld.features;
import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyVector3;
import net.anzix.fsz.voxelworld.BasicFeature;
import net.anzix.fsz.voxelworld.DetailLevel;
import net.anzix.fsz.voxelworld.FszMatrix4;
import net.anzix.fsz.voxelworld.layers.LayerBlock;
/**
*
* @author kovacsandras
*/
public class House extends BasicFeature{
public House( FszMatrix4 position, double sizeX, double sizeY, double sizeZ, double wallThickness) {
this.outerHalfSizeX = sizeX / 2.0;
this.outerHalfSizeY = sizeY / 2.0;
this.outerHalfSizeZ = sizeZ / 2.0;
this.innerHalfSizeX = sizeX / 2.0 - wallThickness;
this.innerHalfSizeY = sizeY / 2.0 + wallThickness;
this.innerHalfSizeZ = sizeZ / 2.0 - wallThickness;
this.transform = new FszMatrix4();
position.invert(transform);
}
private double outerHalfSizeX;
private double outerHalfSizeY;
private double outerHalfSizeZ;
private double innerHalfSizeX;
private double innerHalfSizeY;
private double innerHalfSizeZ;
private final FszMatrix4 transform;
public float getDensity(final ReadOnlyVector3 p, LayerBlock layerBlock, int x, int y, int z, DetailLevel level) {
Vector3 temp = transform.applyPost(p, null);
double fox = Math.abs(temp.getX() / outerHalfSizeX);
double foy = Math.abs(temp.getY() / outerHalfSizeY);
double foz = Math.abs(temp.getZ() / outerHalfSizeZ);
double fix = Math.abs(temp.getX() / innerHalfSizeX);
double fiy = Math.abs(temp.getY() / innerHalfSizeY);
double fiz = Math.abs(temp.getZ() / innerHalfSizeZ);
double fo = 1.0 - (fox > foy ? ( fox > foz ? fox : foz )
: ( foy > foz ? foy : foz ));
double fi = 1.0 - (fix > fiy ? ( fix > fiz ? fix : fiz )
: ( fiy > fiz ? fiy : fiz ));
return (float) Math.min(fo, -fi);
}
}