diff --git a/racevisionGame/src/main/java/visualiser/layout/Plane3D.java b/racevisionGame/src/main/java/visualiser/layout/Plane3D.java index 2589662c..b8e03157 100644 --- a/racevisionGame/src/main/java/visualiser/layout/Plane3D.java +++ b/racevisionGame/src/main/java/visualiser/layout/Plane3D.java @@ -11,19 +11,19 @@ import java.util.Arrays; import java.util.List; /** - * Created by fwy13 on 10/09/17. + * 3D plane */ public class Plane3D extends TriangleMesh{ /** * Lenght is up down, and width is left right - * @param width - * @param length - * @param subdivisionsWidth - * @param subdivisionsLength + * @param width width of the plane + * @param length length of the plane + * @param subdivisionsWidth number of divisions along the width of the plane + * @param subdivisionsLength number of division along the length of the plane */ public Plane3D(float width, float length, int subdivisionsWidth, int subdivisionsLength){ - + //add texture points and vertex points float subWidth = width / (float) subdivisionsWidth; float subLength = length / (float) subdivisionsLength; @@ -47,47 +47,9 @@ public class Plane3D extends TriangleMesh{ this.getPoints().setAll(copyListToArray(pointsList)); this.getTexCoords().setAll(copyListToArray(textureCoord)); - + //connect points to make faces ArrayList faces = new ArrayList<>(); -// p0 1 2 t2 0 3 -// p2 1 3 t3 0 1 -// faces.add(2); -// faces.add(3); -// faces.add(0); -// faces.add(2); -// faces.add(1); -// faces.add(0); -// faces.add(2); -// faces.add(3); -// faces.add(1); -// faces.add(0); -// faces.add(3); -// faces.add(1); - -// faces.add(1); -// faces.add(1); -// faces.add(0); -// faces.add(0); -// faces.add(3); -// faces.add(3); -// faces.add(4); -// faces.add(4); -// faces.add(1); -// faces.add(1); -// faces.add(3); -// faces.add(3); -// faces.add(2); -// faces.add(2); -// faces.add(1); -// faces.add(1); -// faces.add(4); -// faces.add(4); -// faces.add(5); -// faces.add(5); -// faces.add(2); -// faces.add(2); -// faces.add(4); -// faces.add(4); + int listSize = pointsList.size()/3; int divsInRow = subdivisionsWidth + 1; for (int i = 0; i < listSize; i++){ @@ -128,6 +90,10 @@ public class Plane3D extends TriangleMesh{ } + /** + * Testing function to see if the points are correct + * @param index index that the points correspond to (remember 3 is a point) + */ private void printPointAtIndex(int index){ int i = index * 3; float x = this.getPoints().get(i); @@ -136,6 +102,11 @@ public class Plane3D extends TriangleMesh{ System.out.println(String.format("Point at %d is x:%f, y:%f, z:%f", index, x, y, z)); } + /** + * copies the list to a float array because java List.toArray isn't working + * @param list list to copy + * @return array + */ private static float[] copyListToArray(List list){ float[] res = new float[list.size()]; for (int i = 0; i < list.size(); i++){ @@ -144,6 +115,11 @@ public class Plane3D extends TriangleMesh{ return res; } + /** + * copies the list to an integer array because java List.toArray isn't working + * @param list list to copy + * @return array + */ private static int[] copyListToIntArray(List list){ int[] res = new int[list.size()]; for (int i = 0; i < list.size(); i++){ diff --git a/racevisionGame/src/main/java/visualiser/layout/SeaSurface.java b/racevisionGame/src/main/java/visualiser/layout/SeaSurface.java index 6da2e5e3..666503d6 100644 --- a/racevisionGame/src/main/java/visualiser/layout/SeaSurface.java +++ b/racevisionGame/src/main/java/visualiser/layout/SeaSurface.java @@ -13,12 +13,19 @@ import javafx.scene.shape.TriangleMesh; import visualiser.utils.PerlinNoiseGenerator; /** - * Created by fwy13 on 10/09/17. + * Creates a SeaSurface */ public class SeaSurface { private float[][] noiseArray; 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){ noiseArray = PerlinNoiseGenerator.createNoise(size, freq); createSurface(); @@ -26,6 +33,9 @@ public class SeaSurface { surface.setX(x); } + /** + * Creates the sea surface + */ private void createSurface(){ Image diffuseMap = createImage(noiseArray.length, noiseArray); @@ -45,9 +55,9 @@ public class SeaSurface { /** * Create texture for uv mapping - * @param size - * @param noise - * @return + * @param size size of the image to make + * @param noise array of noise + * @return image that is created */ private Image createImage(double size, float[][] noise) { @@ -56,6 +66,7 @@ public class SeaSurface { WritableImage wr = new WritableImage(width, height); PixelWriter pw = wr.getPixelWriter(); + //interpolate colours based on noise for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { @@ -65,13 +76,14 @@ public class SeaSurface { 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 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) { 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) @@ -97,6 +125,10 @@ public class SeaSurface { return value; } + /** + * Get surface + * @return the surface so it can be drawn + */ public Subject3D getSurface(){ return surface; } diff --git a/racevisionGame/src/main/java/visualiser/layout/View3D.java b/racevisionGame/src/main/java/visualiser/layout/View3D.java index 2096e3e0..9f080747 100644 --- a/racevisionGame/src/main/java/visualiser/layout/View3D.java +++ b/racevisionGame/src/main/java/visualiser/layout/View3D.java @@ -89,6 +89,7 @@ public class View3D extends Pane { /** * Default constructor for View3D. Sets up Scene and PerspectiveCamera. + * @param fill whether or not to fill the background of the view. */ public View3D(boolean fill) { this.world = new Group(); diff --git a/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java b/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java index a166b3cb..542b043f 100644 --- a/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java +++ b/racevisionGame/src/main/java/visualiser/utils/GPSConverter.java @@ -102,7 +102,10 @@ public class GPSConverter { } /** - * Get angle between two GraphCoordinates + * Gets the bearing between two coordinates + * @param coord1 coordinate 1 + * @param coord2 coordinate 2 + * @return return the bearing between the two. */ public static double getAngle(GraphCoordinate coord1, GraphCoordinate coord2){ return Math.atan2(coord2.getX() - coord1.getX(), coord2.getY() - coord1.getY()); diff --git a/racevisionGame/src/main/java/visualiser/utils/PerlinNoiseGenerator.java b/racevisionGame/src/main/java/visualiser/utils/PerlinNoiseGenerator.java index 337dc656..00167656 100644 --- a/racevisionGame/src/main/java/visualiser/utils/PerlinNoiseGenerator.java +++ b/racevisionGame/src/main/java/visualiser/utils/PerlinNoiseGenerator.java @@ -1,15 +1,16 @@ package visualiser.utils; /** - * Created by fwy13 on 10/09/17. + * Perlin Noise Generator */ public class PerlinNoiseGenerator { /** * Create an array of the given size with values of perlin noise - * @param size - * @return + * @param size size of array that you wish to create + * @param freq frequency that the noise is to be generated at. + * @return noise generated */ public static float[][] createNoise( int size, double freq) { float[][] noiseArray = new float[(int) size][(int) size];