|
|
|
@ -13,12 +13,19 @@ import javafx.scene.shape.TriangleMesh;
|
|
|
|
import visualiser.utils.PerlinNoiseGenerator;
|
|
|
|
import visualiser.utils.PerlinNoiseGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by fwy13 on 10/09/17.
|
|
|
|
* Creates a SeaSurface
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class SeaSurface {
|
|
|
|
public class SeaSurface {
|
|
|
|
private float[][] noiseArray;
|
|
|
|
private float[][] noiseArray;
|
|
|
|
private Subject3D surface;
|
|
|
|
private Subject3D surface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sea Surface Constructor
|
|
|
|
|
|
|
|
* @param size size of the sea surface (has to be square for simplicity's sake)
|
|
|
|
|
|
|
|
* @param freq frequency the perlin noise is to be generated at
|
|
|
|
|
|
|
|
* @param x offset that the sea should be set at position-wise
|
|
|
|
|
|
|
|
* @param z offset that the sea should be set at position-wise
|
|
|
|
|
|
|
|
*/
|
|
|
|
public SeaSurface(int size, double freq, double x, double z){
|
|
|
|
public SeaSurface(int size, double freq, double x, double z){
|
|
|
|
noiseArray = PerlinNoiseGenerator.createNoise(size, freq);
|
|
|
|
noiseArray = PerlinNoiseGenerator.createNoise(size, freq);
|
|
|
|
createSurface();
|
|
|
|
createSurface();
|
|
|
|
@ -26,6 +33,9 @@ public class SeaSurface {
|
|
|
|
surface.setX(x);
|
|
|
|
surface.setX(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Creates the sea surface
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void createSurface(){
|
|
|
|
private void createSurface(){
|
|
|
|
Image diffuseMap = createImage(noiseArray.length, noiseArray);
|
|
|
|
Image diffuseMap = createImage(noiseArray.length, noiseArray);
|
|
|
|
|
|
|
|
|
|
|
|
@ -45,9 +55,9 @@ public class SeaSurface {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create texture for uv mapping
|
|
|
|
* Create texture for uv mapping
|
|
|
|
* @param size
|
|
|
|
* @param size size of the image to make
|
|
|
|
* @param noise
|
|
|
|
* @param noise array of noise
|
|
|
|
* @return
|
|
|
|
* @return image that is created
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Image createImage(double size, float[][] noise) {
|
|
|
|
private Image createImage(double size, float[][] noise) {
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +66,7 @@ public class SeaSurface {
|
|
|
|
|
|
|
|
|
|
|
|
WritableImage wr = new WritableImage(width, height);
|
|
|
|
WritableImage wr = new WritableImage(width, height);
|
|
|
|
PixelWriter pw = wr.getPixelWriter();
|
|
|
|
PixelWriter pw = wr.getPixelWriter();
|
|
|
|
|
|
|
|
//interpolate colours based on noise
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
|
|
|
|
|
|
|
|
@ -65,13 +76,14 @@ public class SeaSurface {
|
|
|
|
|
|
|
|
|
|
|
|
gray = clamp(gray, 0, 1);
|
|
|
|
gray = clamp(gray, 0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//values to interpolate on
|
|
|
|
Color brightBlue = new Color(0.06, 0.5, .78, 1);
|
|
|
|
Color brightBlue = new Color(0.06, 0.5, .78, 1);
|
|
|
|
Color lightBlue = new Color(0.15, 0.68, .88, 1);
|
|
|
|
Color lightBlue = new Color(0.15, 0.68, .88, 1);
|
|
|
|
Color lighterBlue = new Color(0.28, 0.73, .91, 1);
|
|
|
|
Color lighterBlue = new Color(0.28, 0.73, .91, 1);
|
|
|
|
|
|
|
|
|
|
|
|
Color color = Color.WHITE.interpolate(brightBlue, gray).interpolate(lighterBlue, gray).interpolate(lightBlue, gray);
|
|
|
|
Color colour = Color.WHITE.interpolate(brightBlue, gray).interpolate(lighterBlue, gray).interpolate(lightBlue, gray);
|
|
|
|
|
|
|
|
|
|
|
|
pw.setColor(x, y, color);
|
|
|
|
pw.setColor(x, y, colour);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -80,12 +92,28 @@ public class SeaSurface {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Nomalises the values so that the colours are correct
|
|
|
|
|
|
|
|
* @param value value to normalise
|
|
|
|
|
|
|
|
* @param min current min
|
|
|
|
|
|
|
|
* @param max current max
|
|
|
|
|
|
|
|
* @param newMin new min
|
|
|
|
|
|
|
|
* @param newMax new max
|
|
|
|
|
|
|
|
* @return returns normalised value
|
|
|
|
|
|
|
|
*/
|
|
|
|
private static double normalizeValue(double value, double min, double max, double newMin, double newMax) {
|
|
|
|
private static double normalizeValue(double value, double min, double max, double newMin, double newMax) {
|
|
|
|
|
|
|
|
|
|
|
|
return (value - min) * (newMax - newMin) / (max - min) + newMin;
|
|
|
|
return (value - min) * (newMax - newMin) / (max - min) + newMin;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* clamps a value between a min and max
|
|
|
|
|
|
|
|
* @param value value to clamp
|
|
|
|
|
|
|
|
* @param min minimum value it can be
|
|
|
|
|
|
|
|
* @param max maximum value it can be
|
|
|
|
|
|
|
|
* @return result after clamp
|
|
|
|
|
|
|
|
*/
|
|
|
|
private static double clamp(double value, double min, double max) {
|
|
|
|
private static double clamp(double value, double min, double max) {
|
|
|
|
|
|
|
|
|
|
|
|
if (Double.compare(value, min) < 0)
|
|
|
|
if (Double.compare(value, min) < 0)
|
|
|
|
@ -97,6 +125,10 @@ public class SeaSurface {
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get surface
|
|
|
|
|
|
|
|
* @return the surface so it can be drawn
|
|
|
|
|
|
|
|
*/
|
|
|
|
public Subject3D getSurface(){
|
|
|
|
public Subject3D getSurface(){
|
|
|
|
return surface;
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|