|
|
|
|
@ -7,6 +7,7 @@ import javafx.scene.image.WritableImage;
|
|
|
|
|
import javafx.scene.paint.Color;
|
|
|
|
|
import javafx.scene.paint.PhongMaterial;
|
|
|
|
|
import javafx.scene.shape.MeshView;
|
|
|
|
|
import javafx.scene.transform.Rotate;
|
|
|
|
|
import visualiser.utils.PerlinNoiseGenerator;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
@ -35,17 +36,20 @@ public class SkyBox {
|
|
|
|
|
private void makeSkyBox() {
|
|
|
|
|
//addTop();
|
|
|
|
|
addFront();
|
|
|
|
|
addBack();
|
|
|
|
|
addLeft();
|
|
|
|
|
addRight();
|
|
|
|
|
addSeaOverlay();
|
|
|
|
|
//addBack();
|
|
|
|
|
//addLeft();
|
|
|
|
|
//addRight();
|
|
|
|
|
//addSeaOverlay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addTop() {
|
|
|
|
|
MeshView surface = makeSurface(new Image(getClass().getClassLoader().getResourceAsStream("images/skybox/skyTop.png")));
|
|
|
|
|
|
|
|
|
|
surface.setRotationAxis(new Point3D(0, 0, 1));
|
|
|
|
|
surface.setRotate(180);
|
|
|
|
|
|
|
|
|
|
surface.setTranslateX(x);
|
|
|
|
|
surface.setTranslateY(y - size);
|
|
|
|
|
surface.setTranslateY(y - size + 0.01);
|
|
|
|
|
surface.setTranslateZ(z);
|
|
|
|
|
|
|
|
|
|
Subject3D top = new Subject3D(surface);
|
|
|
|
|
@ -95,13 +99,13 @@ public class SkyBox {
|
|
|
|
|
|
|
|
|
|
private void addBack() {
|
|
|
|
|
MeshView surface = makeSurface(new Image(getClass().getClassLoader().getResourceAsStream("images/skybox/skyBack.png")));
|
|
|
|
|
surface.getTransforms().add(new Rotate(90, 0, 0));
|
|
|
|
|
|
|
|
|
|
surface.setTranslateX(size/2);
|
|
|
|
|
surface.setTranslateY(size/2);
|
|
|
|
|
surface.setRotationAxis(new Point3D(0, 0, 1));
|
|
|
|
|
surface.setRotate(90);
|
|
|
|
|
surface.setTranslateX(-size/2);
|
|
|
|
|
surface.setTranslateY(-size/2);
|
|
|
|
|
surface.setRotationAxis(new Point3D(1, 0, 0));
|
|
|
|
|
surface.setRotate(-90);
|
|
|
|
|
|
|
|
|
|
surface.setScaleY(-1);
|
|
|
|
|
surface.setScaleZ(-1);
|
|
|
|
|
|
|
|
|
|
surface.setTranslateX(x - size/2);
|
|
|
|
|
surface.setTranslateY(y - size/2);
|
|
|
|
|
@ -114,12 +118,13 @@ public class SkyBox {
|
|
|
|
|
private void addFront() {
|
|
|
|
|
MeshView surface = makeSurface(new Image(getClass().getClassLoader().getResourceAsStream("images/skybox/skyFront.png")));
|
|
|
|
|
|
|
|
|
|
surface.setTranslateX(size/2);
|
|
|
|
|
surface.setTranslateY(size/2);
|
|
|
|
|
surface.setRotationAxis(new Point3D(0, 0, 1));
|
|
|
|
|
surface.setRotate(-90);
|
|
|
|
|
surface.setTranslateX(-size/2);
|
|
|
|
|
surface.setTranslateY(-size/2);
|
|
|
|
|
surface.getTransforms().add(new Rotate(90, 0, 0));
|
|
|
|
|
|
|
|
|
|
surface.setRotationAxis(new Point3D(1, 0, 0));
|
|
|
|
|
surface.setRotate(90);
|
|
|
|
|
|
|
|
|
|
surface.setScaleY(-1);
|
|
|
|
|
surface.setScaleZ(-1);
|
|
|
|
|
|
|
|
|
|
surface.setTranslateX(x + size/2);
|
|
|
|
|
surface.setTranslateY(y - size/2);
|
|
|
|
|
@ -148,76 +153,6 @@ public class SkyBox {
|
|
|
|
|
skyBoxPlanes.add(seaSurface.getSurface());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create texture for uv mapping
|
|
|
|
|
* @param size size of the image to make
|
|
|
|
|
* @return image that is created
|
|
|
|
|
*/
|
|
|
|
|
private Image createImage(int size) {
|
|
|
|
|
float[][] noise = PerlinNoiseGenerator.createNoise(size, freq);
|
|
|
|
|
|
|
|
|
|
WritableImage wr = new WritableImage(size, size);
|
|
|
|
|
PixelWriter pw = wr.getPixelWriter();
|
|
|
|
|
//interpolate colours based on noise
|
|
|
|
|
for (int x = 0; x < size; x++) {
|
|
|
|
|
for (int y = 0; y < size; y++) {
|
|
|
|
|
|
|
|
|
|
float value = noise[x][y];
|
|
|
|
|
|
|
|
|
|
double gray = normalizeValue(value, -.5, .5, 0., 1.);
|
|
|
|
|
|
|
|
|
|
gray = clamp(gray, 0, 1);
|
|
|
|
|
|
|
|
|
|
//values to interpolate on
|
|
|
|
|
Color brightBlue = new Color(0.06, 0.5, .78, 1);
|
|
|
|
|
Color lightBlue = new Color(0.15, 0.68, .88, 1);
|
|
|
|
|
Color lighterBlue = new Color(0.28, 0.73, .91, 1);
|
|
|
|
|
|
|
|
|
|
Color colour = Color.WHITE.interpolate(brightBlue, gray).interpolate(lighterBlue, gray).interpolate(lightBlue, gray);
|
|
|
|
|
|
|
|
|
|
pw.setColor(x, y, colour);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wr;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) {
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
if (Double.compare(value, min) < 0)
|
|
|
|
|
return min;
|
|
|
|
|
|
|
|
|
|
if (Double.compare(value, max) > 0)
|
|
|
|
|
return max;
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Subject3D> getSkyBoxPlanes() {
|
|
|
|
|
return skyBoxPlanes;
|
|
|
|
|
}
|
|
|
|
|
|