Loading .idea/misc.xml +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ </option> <option name="workspaceImportForciblyTurnedOn" value="true" /> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="22" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="22" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> No newline at end of file src/main/java/Graph/readFile.java +10 −4 Original line number Diff line number Diff line Loading @@ -55,9 +55,14 @@ public class readFile { speed = Double.parseDouble(args[index + 1]); } if (Objects.equals(arg, "--dir")) { double mag = 0; for (int ii = 0; ii < 3; ii++) { direction[ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); mag += Math.pow(direction[ii], 2); } mag = Math.sqrt(mag); for (int ii = 0; ii < 3; ii++) { direction[ii] = direction[ii]/mag * speed; } } index++; Loading @@ -75,9 +80,10 @@ public class readFile { this.makeVertexHash(path); } public String getPath() { return this.path; } public String getPath() {return this.path;} public Map<Integer,VertexKey> getMapping() {return indexToVertex;} public double[] getDirection() {return direction;} /** * 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 src/main/java/Shape/MovingObject.java +32 −5 Original line number Diff line number Diff line package Shape; import Graph.VertexKey; import Graph.readFile; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; Loading @@ -8,28 +9,37 @@ import javafx.scene.shape.MeshView; import javafx.scene.shape.TriangleMesh; import javafx.scene.transform.Translate; import java.io.*; import java.util.*; public class MovingObject { private readFile fileObject; private float[] texCoords; private float[] centroid; private double[] centroid; private TriangleMesh mesh; private MeshView triangleView; private Translate translate; private Map<Integer, Double> centroidRays; private boolean dirtyTranslate; private double[] velocityVec; MovingObject() { texCoords = new float[2]; mesh = new TriangleMesh(); translate = new Translate(); centroid = new float[3]; centroid = new double[3]; dirtyTranslate = true; centroidRays = new HashMap<>(); velocityVec = new double[3]; } public MovingObject(String[] parameters) { this(); fileObject = new readFile(parameters); fileObject.makeVertexHash(fileObject.getPath()); fileObject.makeMatrix(); //fileObject.makeMatrix(); velocityVec = fileObject.getDirection(); mesh.getPoints().setAll(fileObject.getVertices()); mesh.getFaces().setAll(fileObject.getFaces()); triangleView = new MeshView(mesh); Loading Loading @@ -72,6 +82,8 @@ public class MovingObject { return translate; } public double[] getVelocityVec() {return velocityVec;} public void setNewFilePath(String filePath) { fileObject = new readFile(filePath); fileObject.makeMatrix(); Loading Loading @@ -118,8 +130,23 @@ public class MovingObject { } } public float[] getCentroid() { return centroid; public double[] getCentroid() { double[] baseCentroid = new double[3]; baseCentroid[0] = centroid[0] + translate.getX(); baseCentroid[1] = centroid[1] + translate.getY(); baseCentroid[2] = centroid[2] + translate.getZ(); return baseCentroid; } public void updateRays() { double X = translate.getX(); double Y = translate.getY(); double Z = translate.getZ(); Map<Integer, VertexKey> mapping = fileObject.getMapping(); for (Integer key : mapping.keySet()) { float[] curr = mapping.get(key).get(); double dist = Math.sqrt(Math.pow(curr[0] - X, 2) + Math.pow(curr[1] - Y, 2) + Math.pow(curr[2] - Z, 2)); centroidRays.put(key, dist); } } } src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ public class GraphicsAndWindowsTest extends Application { public void start(Stage stage) throws IOException { VisibleWindow sceneWindow = new VisibleWindow(500, 600, 200); Box ourWindow = sceneWindow.makeWindow(); Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); //Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); MovingObject newObject = new MovingObject(getParameters().getRaw().toArray(new String[0])); Loading @@ -58,7 +58,7 @@ public class GraphicsAndWindowsTest extends Application { group3D.getChildren().add(newObject.getMesh()); group3D.getChildren().add(ourWindow); group3D.getChildren().add(new AmbientLight(Color.WHITE)); obs.addToGroup(group3D); //obs.addToGroup(group3D); // NOTE: Due to the perspectiveCamera it looks like it is rotating even though it isn't // If you comment out this line and the scene.setCamera(camera) line Loading Loading @@ -130,9 +130,6 @@ public class GraphicsAndWindowsTest extends Application { private long lastUpdate = 0; //Movement timer private long fpsTimer = 0; //Frame timer private long frameRate = 0; //Frames per second private double directionY = 8.0; // Direction of movement private double directionX = 4.0; // Direction of movement private double directionZ = 10.0; // Direction of movement /** * Called at every frame while the {@link AnimationTimer} is active to update the scene's elements, Loading @@ -155,13 +152,13 @@ public class GraphicsAndWindowsTest extends Application { public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Bounds meshBounds = newObject.getMesh().getBoundsInParent(); double minX = meshBounds.getMinX() + directionX; double maxX = meshBounds.getMaxX() + directionX; double minY = meshBounds.getMinY() + directionY; double maxY = meshBounds.getMaxY() + directionY; double minZ = meshBounds.getMinZ() + directionZ; double maxZ = meshBounds.getMaxZ() + directionZ; double[] direction1 = newObject.getVelocityVec(); double minX = meshBounds.getMinX() + direction1[0]; double maxX = meshBounds.getMaxX() + direction1[0]; double minY = meshBounds.getMinY() + direction1[1]; double maxY = meshBounds.getMaxY() + direction1[1]; double minZ = meshBounds.getMinZ() + direction1[2]; double maxZ = meshBounds.getMaxZ() + direction1[2]; //Number is roughly 1 mill divided by 60 if (now - lastUpdate >= 16_000_000) { // Roughly 60 frames per second Loading @@ -185,7 +182,7 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates directionX *= -1; direction1[0] *= -1; lastChanged = 1; //mesh.getPoints().setAll(points); } Loading @@ -202,7 +199,7 @@ public class GraphicsAndWindowsTest extends Application { } */ //update the direction of the mesh and set the new coordinates directionY *= -1; direction1[1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } Loading @@ -220,11 +217,12 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates directionZ *= -1; direction1[2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); } /* if(obs.checkCollision(meshBounds)){ switch (lastChanged){ case 1: directionX *= -1; Loading @@ -236,13 +234,13 @@ public class GraphicsAndWindowsTest extends Application { default: System.out.println(); } directionY *= -1; } double newY = newObject.getTranslate().getY() + directionY; double newX = newObject.getTranslate().getX() + directionX; double newZ = newObject.getTranslate().getZ() + directionZ; }*/ double newX = newObject.getTranslate().getX() + direction1[0]; double newY = newObject.getTranslate().getY() + direction1[1]; double newZ = newObject.getTranslate().getZ() + direction1[2]; newObject.updateTranslate(newX,newY,newZ); System.out.println(Arrays.toString(newObject.getCentroid())); newObject.updateRays(); lastUpdate = now; } if (fpsTimer == 0) { Loading target/classes/Graph/readFile.class +418 B (8.03 KiB) File changed.No diff preview for this file type. View original file View changed file Loading
.idea/misc.xml +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ </option> <option name="workspaceImportForciblyTurnedOn" value="true" /> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="22" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="22" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> No newline at end of file
src/main/java/Graph/readFile.java +10 −4 Original line number Diff line number Diff line Loading @@ -55,9 +55,14 @@ public class readFile { speed = Double.parseDouble(args[index + 1]); } if (Objects.equals(arg, "--dir")) { double mag = 0; for (int ii = 0; ii < 3; ii++) { direction[ii] = Double.parseDouble(args[index + ii + 1].replace(",","")); mag += Math.pow(direction[ii], 2); } mag = Math.sqrt(mag); for (int ii = 0; ii < 3; ii++) { direction[ii] = direction[ii]/mag * speed; } } index++; Loading @@ -75,9 +80,10 @@ public class readFile { this.makeVertexHash(path); } public String getPath() { return this.path; } public String getPath() {return this.path;} public Map<Integer,VertexKey> getMapping() {return indexToVertex;} public double[] getDirection() {return direction;} /** * 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
src/main/java/Shape/MovingObject.java +32 −5 Original line number Diff line number Diff line package Shape; import Graph.VertexKey; import Graph.readFile; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; Loading @@ -8,28 +9,37 @@ import javafx.scene.shape.MeshView; import javafx.scene.shape.TriangleMesh; import javafx.scene.transform.Translate; import java.io.*; import java.util.*; public class MovingObject { private readFile fileObject; private float[] texCoords; private float[] centroid; private double[] centroid; private TriangleMesh mesh; private MeshView triangleView; private Translate translate; private Map<Integer, Double> centroidRays; private boolean dirtyTranslate; private double[] velocityVec; MovingObject() { texCoords = new float[2]; mesh = new TriangleMesh(); translate = new Translate(); centroid = new float[3]; centroid = new double[3]; dirtyTranslate = true; centroidRays = new HashMap<>(); velocityVec = new double[3]; } public MovingObject(String[] parameters) { this(); fileObject = new readFile(parameters); fileObject.makeVertexHash(fileObject.getPath()); fileObject.makeMatrix(); //fileObject.makeMatrix(); velocityVec = fileObject.getDirection(); mesh.getPoints().setAll(fileObject.getVertices()); mesh.getFaces().setAll(fileObject.getFaces()); triangleView = new MeshView(mesh); Loading Loading @@ -72,6 +82,8 @@ public class MovingObject { return translate; } public double[] getVelocityVec() {return velocityVec;} public void setNewFilePath(String filePath) { fileObject = new readFile(filePath); fileObject.makeMatrix(); Loading Loading @@ -118,8 +130,23 @@ public class MovingObject { } } public float[] getCentroid() { return centroid; public double[] getCentroid() { double[] baseCentroid = new double[3]; baseCentroid[0] = centroid[0] + translate.getX(); baseCentroid[1] = centroid[1] + translate.getY(); baseCentroid[2] = centroid[2] + translate.getZ(); return baseCentroid; } public void updateRays() { double X = translate.getX(); double Y = translate.getY(); double Z = translate.getZ(); Map<Integer, VertexKey> mapping = fileObject.getMapping(); for (Integer key : mapping.keySet()) { float[] curr = mapping.get(key).get(); double dist = Math.sqrt(Math.pow(curr[0] - X, 2) + Math.pow(curr[1] - Y, 2) + Math.pow(curr[2] - Z, 2)); centroidRays.put(key, dist); } } }
src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +18 −20 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ public class GraphicsAndWindowsTest extends Application { public void start(Stage stage) throws IOException { VisibleWindow sceneWindow = new VisibleWindow(500, 600, 200); Box ourWindow = sceneWindow.makeWindow(); Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); //Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); MovingObject newObject = new MovingObject(getParameters().getRaw().toArray(new String[0])); Loading @@ -58,7 +58,7 @@ public class GraphicsAndWindowsTest extends Application { group3D.getChildren().add(newObject.getMesh()); group3D.getChildren().add(ourWindow); group3D.getChildren().add(new AmbientLight(Color.WHITE)); obs.addToGroup(group3D); //obs.addToGroup(group3D); // NOTE: Due to the perspectiveCamera it looks like it is rotating even though it isn't // If you comment out this line and the scene.setCamera(camera) line Loading Loading @@ -130,9 +130,6 @@ public class GraphicsAndWindowsTest extends Application { private long lastUpdate = 0; //Movement timer private long fpsTimer = 0; //Frame timer private long frameRate = 0; //Frames per second private double directionY = 8.0; // Direction of movement private double directionX = 4.0; // Direction of movement private double directionZ = 10.0; // Direction of movement /** * Called at every frame while the {@link AnimationTimer} is active to update the scene's elements, Loading @@ -155,13 +152,13 @@ public class GraphicsAndWindowsTest extends Application { public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Bounds meshBounds = newObject.getMesh().getBoundsInParent(); double minX = meshBounds.getMinX() + directionX; double maxX = meshBounds.getMaxX() + directionX; double minY = meshBounds.getMinY() + directionY; double maxY = meshBounds.getMaxY() + directionY; double minZ = meshBounds.getMinZ() + directionZ; double maxZ = meshBounds.getMaxZ() + directionZ; double[] direction1 = newObject.getVelocityVec(); double minX = meshBounds.getMinX() + direction1[0]; double maxX = meshBounds.getMaxX() + direction1[0]; double minY = meshBounds.getMinY() + direction1[1]; double maxY = meshBounds.getMaxY() + direction1[1]; double minZ = meshBounds.getMinZ() + direction1[2]; double maxZ = meshBounds.getMaxZ() + direction1[2]; //Number is roughly 1 mill divided by 60 if (now - lastUpdate >= 16_000_000) { // Roughly 60 frames per second Loading @@ -185,7 +182,7 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates directionX *= -1; direction1[0] *= -1; lastChanged = 1; //mesh.getPoints().setAll(points); } Loading @@ -202,7 +199,7 @@ public class GraphicsAndWindowsTest extends Application { } */ //update the direction of the mesh and set the new coordinates directionY *= -1; direction1[1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } Loading @@ -220,11 +217,12 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates directionZ *= -1; direction1[2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); } /* if(obs.checkCollision(meshBounds)){ switch (lastChanged){ case 1: directionX *= -1; Loading @@ -236,13 +234,13 @@ public class GraphicsAndWindowsTest extends Application { default: System.out.println(); } directionY *= -1; } double newY = newObject.getTranslate().getY() + directionY; double newX = newObject.getTranslate().getX() + directionX; double newZ = newObject.getTranslate().getZ() + directionZ; }*/ double newX = newObject.getTranslate().getX() + direction1[0]; double newY = newObject.getTranslate().getY() + direction1[1]; double newZ = newObject.getTranslate().getZ() + direction1[2]; newObject.updateTranslate(newX,newY,newZ); System.out.println(Arrays.toString(newObject.getCentroid())); newObject.updateRays(); lastUpdate = now; } if (fpsTimer == 0) { Loading
target/classes/Graph/readFile.class +418 B (8.03 KiB) File changed.No diff preview for this file type. View original file View changed file