/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.anzix.fsz.voxelworld.features.components;
import com.ardor3d.math.functions.FbmFunction3D;
import com.ardor3d.math.functions.Function3D;
import com.ardor3d.math.functions.Functions;
import com.ardor3d.math.type.ReadOnlyVector3;
/**
*
* @author csiga
*/
public class Noise {
public Noise(int octaves, double frequency, double verticalStretch) {
this.octaves = octaves;
this.frequency = frequency;
this.persistence = 0.4;
this.lacunarity = 3.14;
this.maxValue = getMaxValue();
this.proceduralFunction = new FbmFunction3D(Functions.simplexNoise(), octaves, frequency, persistence, lacunarity);
this.verticalStretch = verticalStretch;
}
private Function3D proceduralFunction;
private int octaves;
private double frequency;
private double persistence;
private double lacunarity;
private double maxValue;
private double maxDensity = 1.0;
private double verticalStretch;
private double getMaxValue() {
double maxvalue = 0;
double curentPersistence = 1;
for (int i = 0; i < this.octaves; i++) {
maxvalue += curentPersistence;
curentPersistence *= this.persistence;
}
return maxvalue;
}
public double getDensity(ReadOnlyVector3 p) {
double r = proceduralFunction.eval(p.getX(), p.getY()*verticalStretch, p.getZ());
return r / maxValue * maxDensity;
}
public double getDensity(double x, double y, double z) {
double r = proceduralFunction.eval(x,y*verticalStretch,z);
return r / maxValue * maxDensity;
}
}