Loading src/main/java/Graph/readFile.java +44 −29 Original line number Diff line number Diff line Loading @@ -8,20 +8,30 @@ import java.util.Random; * readFile class utilized to parse through commands to obtain the information of the figure */ public class readFile { public static String[] path = new String[3]; final private static double[] speed = new double[3]; final private static double[][] direction = new double[3][3]; private static int numPath = 0, numSpeed = 0, numDir = 0, index = 0, vertexCount = 0; public static Map<VertexKey, ArrayList<VertexKey>> vertexList = new HashMap<>(); public static Map<VertexKey,Integer> vertexToIndex = new HashMap<>(); public static Map<Integer, VertexKey> indexToVertex = new HashMap<>(); private String path; private static double speed; private static double[] direction; private static int index, vertexCount; public static Map<VertexKey, ArrayList<VertexKey>> vertexList; public static Map<VertexKey,Integer> vertexToIndex; public static Map<Integer, VertexKey> indexToVertex; public static float[] vertices; private static ArrayList<Integer> faces = new ArrayList<>(); private static ArrayList<Integer> faces; public static AdjacencyMatrix adjMatrix; public readFile() { direction = new double[3]; vertexList = new HashMap<>(); vertexToIndex = new HashMap<>(); indexToVertex = new HashMap<>(); faces = new ArrayList<>(); index = 0; vertexCount = 0; } /** * Parses an array of command-line arguments to extract image paths, speeds, and directional vectors. * This method expects arguments in specific formats: Loading @@ -34,35 +44,40 @@ public class readFile { * * @param args args the command-line arguments to be parsed. */ public static void parseCommand(String[] args) { public readFile(String[] args) { this(); for (String arg : args) { if (Objects.equals(arg, "--image")) { path[numPath] = args[index + 1]; numPath++; path = args[index + 1]; } if (Objects.equals(arg, "--speed")) { speed[numSpeed] = Double.parseDouble(args[index + 1]); numSpeed++; speed = Double.parseDouble(args[index + 1]); } if (Objects.equals(arg, "--dir")) { for (int ii = 0; ii < 3; ii++) { direction[numDir][ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); direction[ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); } numDir++; } index++; } System.out.println("Image path: " + path[0]); System.out.println("Speed: " + speed[0]); System.out.println("Direction: " + Arrays.toString(direction[0])); if ((numPath != numDir) || (numSpeed != numDir) || (numPath == 0)) { // die return; System.out.println("Image path: " + path); System.out.println("Speed: " + speed); System.out.println("Direction: " + Arrays.toString(direction)); } public readFile(String filePath) { this.path = filePath; for (int i = 0; i < 3; i++) { direction[i] = 0; } speed = 0; this.makeVertexHash(path); } public String getPath() { return this.path; } /** * Reads vertex data from a specified file and populates global hash structures * to map each vertex to its adjacent vertices and indices. The file should contain Loading @@ -72,7 +87,7 @@ public class readFile { * @param currPath the path to the file containing the triangles' vertex data. * @throws FileNotFoundException if the file at {@code currPath} does not exist or cannot be read. */ public static void makeVertexHash(String currPath) { public void makeVertexHash(String currPath) { try { File fileObj = new File(currPath); Loading Loading @@ -128,7 +143,7 @@ public class readFile { * adding an edge to the adjacency matrix for each adjacency. This process constructs a complete * representation of the graph's connectivity in matrix form. */ public static void makeMatrix() { public void makeMatrix() { adjMatrix = new AdjacencyMatrix(vertexCount); for (int i = 0; i < vertexCount; i++) { VertexKey currVertexKey = indexToVertex.get(i); Loading @@ -151,7 +166,7 @@ public class readFile { * Each vertex's coordinates occupy three consecutive positions in the array (x, y, z), * scaled by a factor of 3. */ public static float[] getVertices() { public float[] getVertices() { float[] vertices = new float[vertexCount * 3]; VertexKey tmp; int count = 0; Loading Loading @@ -180,12 +195,12 @@ public class readFile { * two consecutive entries are created in the output array: the face index and a 0 as a * placeholder for the texture index. */ public static int[] getFaces() { public int[] getFaces() { int[] facesWithTexture = new int[faces.size()*2]; int count = 0; for (int face : faces) { facesWithTexture[count*2] = faces.get(count); facesWithTexture[count*2] = face; facesWithTexture[count*2 + 1] = 0; count++; } Loading @@ -206,7 +221,7 @@ public class readFile { * its contents will be replaced with the new, randomly generated data. * @throws IOException If an I/O error occurs during writing to the file. */ public static void randFileGenerator(String filename) throws IOException { public void randFileGenerator(String filename) throws IOException { Random random = new Random(); try (FileWriter writer = new FileWriter(filename)) { for (int i = 0; i < 15000; i++) { Loading @@ -229,7 +244,7 @@ public class readFile { * @return A string formatted as "[x1,y1,z1] [x2,y2,z2] [x3,y3,z3]", where x, y, and z are coordinate * values for three points, generated randomly. */ private static String makeLine(Random random) { private String makeLine(Random random) { return String.format("[%f,%f,%f] [%f,%f,%f] [%f,%f,%f]", vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], Loading @@ -243,7 +258,7 @@ public class readFile { * * @param numVertices The number of vertices to generate. This determines the size of the {@code vertices} array. */ public static void generateRandomVertices(int numVertices) { public void generateRandomVertices(int numVertices) { float range = 30; Random random = new Random(); vertices = new float[numVertices * 3]; Loading src/main/java/Shape/MovingObject.java +5 −5 Original line number Diff line number Diff line Loading @@ -97,12 +97,12 @@ public class MovingObject { public void setCentroid() { if (dirtyTranslate) { float[] vertices = fileObject.getVertices(); int count = 0; float count = 0; float x = 0; float y = 0; float z = 0; for(float ii : vertices) { int index = count % 3; float index = count % 3; if (index == 0) { x += ii; } else if (index == 1) { Loading @@ -112,9 +112,9 @@ public class MovingObject { } count++; } centroid[0] = x/count; centroid[1] = y/count; centroid[2] = z/count; centroid[0] = (float) (x/(count/3.0)); centroid[1] = (float) (y/(count/3.0)); centroid[2] = (float) (z/(count/3.0)); } } Loading src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import javafx.scene.transform.Translate; import javafx.stage.Stage; import java.io.IOException; import java.util.Arrays; /** Loading Loading @@ -227,7 +228,7 @@ public class GraphicsAndWindowsTest extends Application { double newX = newObject.getTranslate().getX() + directionX; double newZ = newObject.getTranslate().getZ() + directionZ; newObject.updateTranslate(newX,newY,newZ); System.out.println(Arrays.toString(newObject.getCentroid())); lastUpdate = now; } if (fpsTimer == 0) { Loading Loading
src/main/java/Graph/readFile.java +44 −29 Original line number Diff line number Diff line Loading @@ -8,20 +8,30 @@ import java.util.Random; * readFile class utilized to parse through commands to obtain the information of the figure */ public class readFile { public static String[] path = new String[3]; final private static double[] speed = new double[3]; final private static double[][] direction = new double[3][3]; private static int numPath = 0, numSpeed = 0, numDir = 0, index = 0, vertexCount = 0; public static Map<VertexKey, ArrayList<VertexKey>> vertexList = new HashMap<>(); public static Map<VertexKey,Integer> vertexToIndex = new HashMap<>(); public static Map<Integer, VertexKey> indexToVertex = new HashMap<>(); private String path; private static double speed; private static double[] direction; private static int index, vertexCount; public static Map<VertexKey, ArrayList<VertexKey>> vertexList; public static Map<VertexKey,Integer> vertexToIndex; public static Map<Integer, VertexKey> indexToVertex; public static float[] vertices; private static ArrayList<Integer> faces = new ArrayList<>(); private static ArrayList<Integer> faces; public static AdjacencyMatrix adjMatrix; public readFile() { direction = new double[3]; vertexList = new HashMap<>(); vertexToIndex = new HashMap<>(); indexToVertex = new HashMap<>(); faces = new ArrayList<>(); index = 0; vertexCount = 0; } /** * Parses an array of command-line arguments to extract image paths, speeds, and directional vectors. * This method expects arguments in specific formats: Loading @@ -34,35 +44,40 @@ public class readFile { * * @param args args the command-line arguments to be parsed. */ public static void parseCommand(String[] args) { public readFile(String[] args) { this(); for (String arg : args) { if (Objects.equals(arg, "--image")) { path[numPath] = args[index + 1]; numPath++; path = args[index + 1]; } if (Objects.equals(arg, "--speed")) { speed[numSpeed] = Double.parseDouble(args[index + 1]); numSpeed++; speed = Double.parseDouble(args[index + 1]); } if (Objects.equals(arg, "--dir")) { for (int ii = 0; ii < 3; ii++) { direction[numDir][ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); direction[ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); } numDir++; } index++; } System.out.println("Image path: " + path[0]); System.out.println("Speed: " + speed[0]); System.out.println("Direction: " + Arrays.toString(direction[0])); if ((numPath != numDir) || (numSpeed != numDir) || (numPath == 0)) { // die return; System.out.println("Image path: " + path); System.out.println("Speed: " + speed); System.out.println("Direction: " + Arrays.toString(direction)); } public readFile(String filePath) { this.path = filePath; for (int i = 0; i < 3; i++) { direction[i] = 0; } speed = 0; this.makeVertexHash(path); } public String getPath() { return this.path; } /** * Reads vertex data from a specified file and populates global hash structures * to map each vertex to its adjacent vertices and indices. The file should contain Loading @@ -72,7 +87,7 @@ public class readFile { * @param currPath the path to the file containing the triangles' vertex data. * @throws FileNotFoundException if the file at {@code currPath} does not exist or cannot be read. */ public static void makeVertexHash(String currPath) { public void makeVertexHash(String currPath) { try { File fileObj = new File(currPath); Loading Loading @@ -128,7 +143,7 @@ public class readFile { * adding an edge to the adjacency matrix for each adjacency. This process constructs a complete * representation of the graph's connectivity in matrix form. */ public static void makeMatrix() { public void makeMatrix() { adjMatrix = new AdjacencyMatrix(vertexCount); for (int i = 0; i < vertexCount; i++) { VertexKey currVertexKey = indexToVertex.get(i); Loading @@ -151,7 +166,7 @@ public class readFile { * Each vertex's coordinates occupy three consecutive positions in the array (x, y, z), * scaled by a factor of 3. */ public static float[] getVertices() { public float[] getVertices() { float[] vertices = new float[vertexCount * 3]; VertexKey tmp; int count = 0; Loading Loading @@ -180,12 +195,12 @@ public class readFile { * two consecutive entries are created in the output array: the face index and a 0 as a * placeholder for the texture index. */ public static int[] getFaces() { public int[] getFaces() { int[] facesWithTexture = new int[faces.size()*2]; int count = 0; for (int face : faces) { facesWithTexture[count*2] = faces.get(count); facesWithTexture[count*2] = face; facesWithTexture[count*2 + 1] = 0; count++; } Loading @@ -206,7 +221,7 @@ public class readFile { * its contents will be replaced with the new, randomly generated data. * @throws IOException If an I/O error occurs during writing to the file. */ public static void randFileGenerator(String filename) throws IOException { public void randFileGenerator(String filename) throws IOException { Random random = new Random(); try (FileWriter writer = new FileWriter(filename)) { for (int i = 0; i < 15000; i++) { Loading @@ -229,7 +244,7 @@ public class readFile { * @return A string formatted as "[x1,y1,z1] [x2,y2,z2] [x3,y3,z3]", where x, y, and z are coordinate * values for three points, generated randomly. */ private static String makeLine(Random random) { private String makeLine(Random random) { return String.format("[%f,%f,%f] [%f,%f,%f] [%f,%f,%f]", vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], Loading @@ -243,7 +258,7 @@ public class readFile { * * @param numVertices The number of vertices to generate. This determines the size of the {@code vertices} array. */ public static void generateRandomVertices(int numVertices) { public void generateRandomVertices(int numVertices) { float range = 30; Random random = new Random(); vertices = new float[numVertices * 3]; Loading
src/main/java/Shape/MovingObject.java +5 −5 Original line number Diff line number Diff line Loading @@ -97,12 +97,12 @@ public class MovingObject { public void setCentroid() { if (dirtyTranslate) { float[] vertices = fileObject.getVertices(); int count = 0; float count = 0; float x = 0; float y = 0; float z = 0; for(float ii : vertices) { int index = count % 3; float index = count % 3; if (index == 0) { x += ii; } else if (index == 1) { Loading @@ -112,9 +112,9 @@ public class MovingObject { } count++; } centroid[0] = x/count; centroid[1] = y/count; centroid[2] = z/count; centroid[0] = (float) (x/(count/3.0)); centroid[1] = (float) (y/(count/3.0)); centroid[2] = (float) (z/(count/3.0)); } } Loading
src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import javafx.scene.transform.Translate; import javafx.stage.Stage; import java.io.IOException; import java.util.Arrays; /** Loading Loading @@ -227,7 +228,7 @@ public class GraphicsAndWindowsTest extends Application { double newX = newObject.getTranslate().getX() + directionX; double newZ = newObject.getTranslate().getZ() + directionZ; newObject.updateTranslate(newX,newY,newZ); System.out.println(Arrays.toString(newObject.getCentroid())); lastUpdate = now; } if (fpsTimer == 0) { Loading