/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.anzix.fsz.voxelworld.features;
import com.ardor3d.math.type.ReadOnlyVector3;
import net.anzix.fsz.voxelworld.BasicFeature;
import net.anzix.fsz.voxelworld.DetailLevel;
import net.anzix.fsz.voxelworld.layers.LayerBlock;
import net.anzix.fsz.voxelworld.VoxelBlockPosition;
import net.anzix.fsz.voxelworld.features.components.Noise;
/**
*
* @author kovacsandras
*/
public class LayerBasedTerrain extends BasicFeature {
final double EPSILON = 32.0; //ennyi lehet a zaj max hatása;
@Override
public boolean affectBlock(final VoxelBlockPosition p, final LayerBlock layerBlock, final DetailLevel level) {
if (p.getTopHeight(level) + EPSILON < layerBlock.minHeight)
return false; // fully underground
if (p.getBottomHeight(level) - EPSILON > layerBlock.maxHeight)
return false; // fully in the air
else
return true;
}
private Noise roughRockNoise;
private Noise fineRockNoise;
public LayerBasedTerrain() {
fineRockNoise = new Noise(3, 0.1, 10);
roughRockNoise = new Noise(3, 0.01, 1);
}
public float getDensity(final ReadOnlyVector3 p, LayerBlock layerBlock, int x, int y, int z, DetailLevel level) {
float layerHeight = layerBlock.heightLayer[x][z];
float rockDensity = layerBlock.rockDensityLayer[x][z];
//float plateauDensity = layerBlock.plateauDensityLayer[x][z];
float currentHeight = p.getYf();
//float plateauHeight = currentHeight / 2.0f + 30.0f;;
//float plateauFactor = plateauDensity < 0.0f ? 0.0f : plateauDensity > 0.2f ? 0.2f : plateauDensity / 0.2f;
//currentHeight = plateauFactor * plateauHeight + (1.0f-plateauFactor) * currentHeight;
float heightComponent = (layerHeight - currentHeight)*.03f;
if (level.getLevelID() < 6) {
if (rockDensity > 0) {
float rockComponent = (float) roughRockNoise.getDensity(p) * rockDensity* 3;
if (level.getLevelID() < 3 && rockDensity > .2)
rockComponent += (float) fineRockNoise.getDensity(p) * Math.min (rockDensity-0.2, 0.05) * 2;
return Math.max(heightComponent,rockComponent+heightComponent);
} else if (rockDensity < 0) {
float rockComponent = (float) roughRockNoise.getDensity(p) * rockDensity* 3;
if (level.getLevelID() < 3 && rockDensity < -.2)
rockComponent += (float) fineRockNoise.getDensity(p) * -Math.max (rockDensity+0.2, -0.05) * 2;
return Math.min(heightComponent,heightComponent+rockComponent);
}
}
return heightComponent;
//return layerHeight - currentHeight;
}
}