Made sea surface look like a sea surface which is randomly generated each time, size may need to be altered a bit else it will cause the program to slow #story[1261]
parent
a7eefca13a
commit
9ac9c25923
@ -0,0 +1,156 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import com.sun.javafx.geom.PickRay;
|
||||
import com.sun.javafx.scene.input.PickResultChooser;
|
||||
import com.sun.javafx.sg.prism.NGNode;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.shape.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 10/09/17.
|
||||
*/
|
||||
public class Plane3D extends TriangleMesh{
|
||||
|
||||
/**
|
||||
* Lenght is up down, and width is left right
|
||||
* @param width
|
||||
* @param length
|
||||
* @param subdivisionsWidth
|
||||
* @param subdivisionsLength
|
||||
*/
|
||||
public Plane3D(float width, float length, int subdivisionsWidth, int subdivisionsLength){
|
||||
|
||||
float subWidth = width / (float) subdivisionsWidth;
|
||||
float subLength = length / (float) subdivisionsLength;
|
||||
|
||||
ArrayList<Float> pointsList = new ArrayList<>();
|
||||
ArrayList<Float> textureCoord = new ArrayList<>();
|
||||
float startW = -width/2;
|
||||
float startL = -length/2;
|
||||
|
||||
for (float l = 0; l <= length; l += subLength) {
|
||||
for (float w = 0; w <= width; w += subWidth){
|
||||
//add points
|
||||
pointsList.add(w + startW);
|
||||
pointsList.add(l + startL);
|
||||
pointsList.add(0f);
|
||||
//addTexture coords
|
||||
textureCoord.add(1 - w/width);
|
||||
textureCoord.add(1 - l/length);
|
||||
}
|
||||
}
|
||||
|
||||
this.getPoints().setAll(copyListToArray(pointsList));
|
||||
this.getTexCoords().setAll(copyListToArray(textureCoord));
|
||||
|
||||
|
||||
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 divsInRow = subdivisionsWidth + 1;
|
||||
for (int i = 0; i < listSize; i++){
|
||||
int row = i/divsInRow;
|
||||
|
||||
if (row < 1){
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean notFirstCol = (i) % divsInRow != 0;
|
||||
boolean notLastCol = (i + 1) % divsInRow != 0;
|
||||
if (notFirstCol){
|
||||
faces.add(i);
|
||||
faces.add(i);
|
||||
// printPointAtIndex(i);
|
||||
faces.add(i - divsInRow);
|
||||
faces.add(i - divsInRow);
|
||||
// printPointAtIndex(i - divsInRow);
|
||||
faces.add(i - 1);
|
||||
faces.add(i - 1);
|
||||
// printPointAtIndex(i-1);
|
||||
}
|
||||
if (notLastCol) {
|
||||
faces.add(i - divsInRow + 1);
|
||||
faces.add(i - divsInRow + 1);
|
||||
// printPointAtIndex(i - divsInRow + 1);
|
||||
faces.add(i - divsInRow);
|
||||
faces.add(i - divsInRow);
|
||||
// printPointAtIndex(i - divsInRow);
|
||||
faces.add(i);
|
||||
faces.add(i);
|
||||
// printPointAtIndex(i);
|
||||
}
|
||||
|
||||
}
|
||||
this.getFaces().setAll(copyListToIntArray(faces));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void printPointAtIndex(int index){
|
||||
int i = index * 3;
|
||||
float x = this.getPoints().get(i);
|
||||
float y = this.getPoints().get(i + 1);
|
||||
float z = this.getPoints().get(i + 2);
|
||||
System.out.println(String.format("Point at %d is x:%f, y:%f, z:%f", index, x, y, z));
|
||||
}
|
||||
|
||||
private static float[] copyListToArray(List<Float> list){
|
||||
float[] res = new float[list.size()];
|
||||
for (int i = 0; i < list.size(); i++){
|
||||
res[i] = list.get(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static int[] copyListToIntArray(List<Integer> list){
|
||||
int[] res = new int[list.size()];
|
||||
for (int i = 0; i < list.size(); i++){
|
||||
res[i] = list.get(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue