Added lights and managed to get the orientation of one of the skybox walls correct. #story[1261]

main
Joseph Gardner 8 years ago
parent 7a8ea7fea7
commit bcc827b554

@ -17,6 +17,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.MeshView;
import javafx.scene.transform.Translate;
import javafx.util.Callback;
@ -177,6 +178,16 @@ public class RaceController extends Controller {
private void initialiseView3D(VisualiserRaceEvent race) {
viewSubjects = FXCollections.observableArrayList();
AmbientLight ambientLight = new AmbientLight(new Color(1, 1, 1, 0.75));
ambientLight.setTranslateX(250);
ambientLight.setTranslateZ(210);
ambientLight.setLightOn(true);
PointLight pointLight = new PointLight();
ambientLight.setTranslateX(250);
ambientLight.setTranslateZ(210);
ambientLight.setLightOn(true);
// Import boat mesh
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
StlMeshImporter importer = new StlMeshImporter();
@ -197,6 +208,8 @@ public class RaceController extends Controller {
view3D.setYaw(0);
view3D.setPitch(60);
view3D.enableTracking();
view3D.addAmbientLight(ambientLight);
view3D.addPointLight(pointLight);
canvasBase.add(view3D, 0, 0);
// Set up projection from GPS to view

@ -42,7 +42,7 @@ public class SeaSurface {
PhongMaterial material = new PhongMaterial();
material.setDiffuseMap(diffuseMap);
material.setSpecularColor(Color.WHITE);
//material.setSpecularColor(Color.WHITE);
Plane3D seaPlane = new Plane3D(noiseArray.length, noiseArray.length, 10, 10);
MeshView seaSurface = new MeshView(seaPlane);

@ -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;
}

@ -3,9 +3,7 @@ package visualiser.layout;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.SubScene;
import javafx.scene.*;
import javafx.scene.input.PickResult;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
@ -198,7 +196,7 @@ public class View3D extends Pane {
target.getHeading().angleProperty().addListener(pivotHeading);
this.setDistance(THIRD_PERSON_LIMIT);
this.setPitch(15);
this.setPitch(20);
}
public void setNearClip(double nearClip) {
@ -263,4 +261,12 @@ public class View3D extends Pane {
public void setPitch(double pitch) {
this.pitch.setAngle(-pitch);
}
public void addAmbientLight(AmbientLight ambientLight) {
this.world.getChildren().add(ambientLight);
}
public void addPointLight(PointLight pointLight) {
this.world.getChildren().add(pointLight);
}
}

Loading…
Cancel
Save