Wrote some missing java docs #story[1261]
This commit is contained in:
@@ -11,19 +11,19 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by fwy13 on 10/09/17.
|
* 3D plane
|
||||||
*/
|
*/
|
||||||
public class Plane3D extends TriangleMesh{
|
public class Plane3D extends TriangleMesh{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lenght is up down, and width is left right
|
* Lenght is up down, and width is left right
|
||||||
* @param width
|
* @param width width of the plane
|
||||||
* @param length
|
* @param length length of the plane
|
||||||
* @param subdivisionsWidth
|
* @param subdivisionsWidth number of divisions along the width of the plane
|
||||||
* @param subdivisionsLength
|
* @param subdivisionsLength number of division along the length of the plane
|
||||||
*/
|
*/
|
||||||
public Plane3D(float width, float length, int subdivisionsWidth, int subdivisionsLength){
|
public Plane3D(float width, float length, int subdivisionsWidth, int subdivisionsLength){
|
||||||
|
//add texture points and vertex points
|
||||||
float subWidth = width / (float) subdivisionsWidth;
|
float subWidth = width / (float) subdivisionsWidth;
|
||||||
float subLength = length / (float) subdivisionsLength;
|
float subLength = length / (float) subdivisionsLength;
|
||||||
|
|
||||||
@@ -47,47 +47,9 @@ public class Plane3D extends TriangleMesh{
|
|||||||
this.getPoints().setAll(copyListToArray(pointsList));
|
this.getPoints().setAll(copyListToArray(pointsList));
|
||||||
this.getTexCoords().setAll(copyListToArray(textureCoord));
|
this.getTexCoords().setAll(copyListToArray(textureCoord));
|
||||||
|
|
||||||
|
//connect points to make faces
|
||||||
ArrayList<Integer> faces = new ArrayList<>();
|
ArrayList<Integer> 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 listSize = pointsList.size()/3;
|
||||||
int divsInRow = subdivisionsWidth + 1;
|
int divsInRow = subdivisionsWidth + 1;
|
||||||
for (int i = 0; i < listSize; i++){
|
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){
|
private void printPointAtIndex(int index){
|
||||||
int i = index * 3;
|
int i = index * 3;
|
||||||
float x = this.getPoints().get(i);
|
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));
|
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<Float> list){
|
private static float[] copyListToArray(List<Float> list){
|
||||||
float[] res = new float[list.size()];
|
float[] res = new float[list.size()];
|
||||||
for (int i = 0; i < list.size(); i++){
|
for (int i = 0; i < list.size(); i++){
|
||||||
@@ -144,6 +115,11 @@ public class Plane3D extends TriangleMesh{
|
|||||||
return res;
|
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<Integer> list){
|
private static int[] copyListToIntArray(List<Integer> list){
|
||||||
int[] res = new int[list.size()];
|
int[] res = new int[list.size()];
|
||||||
for (int i = 0; i < list.size(); i++){
|
for (int i = 0; i < list.size(); i++){
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ public class View3D extends Pane {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
* 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) {
|
public View3D(boolean fill) {
|
||||||
this.world = new Group();
|
this.world = new Group();
|
||||||
|
|||||||
@@ -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){
|
public static double getAngle(GraphCoordinate coord1, GraphCoordinate coord2){
|
||||||
return Math.atan2(coord2.getX() - coord1.getX(), coord2.getY() - coord1.getY());
|
return Math.atan2(coord2.getX() - coord1.getX(), coord2.getY() - coord1.getY());
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package visualiser.utils;
|
package visualiser.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by fwy13 on 10/09/17.
|
* Perlin Noise Generator
|
||||||
*/
|
*/
|
||||||
public class PerlinNoiseGenerator {
|
public class PerlinNoiseGenerator {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an array of the given size with values of perlin noise
|
* Create an array of the given size with values of perlin noise
|
||||||
* @param size
|
* @param size size of array that you wish to create
|
||||||
* @return
|
* @param freq frequency that the noise is to be generated at.
|
||||||
|
* @return noise generated
|
||||||
*/
|
*/
|
||||||
public static float[][] createNoise( int size, double freq) {
|
public static float[][] createNoise( int size, double freq) {
|
||||||
float[][] noiseArray = new float[(int) size][(int) size];
|
float[][] noiseArray = new float[(int) size][(int) size];
|
||||||
|
|||||||
Reference in New Issue
Block a user