Loading src/main/java/Graph/readFile.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public class readFile { } mag = Math.sqrt(mag); for (int ii = 0; ii < 3; ii++) { direction[ii] = direction[ii]/mag * speed; direction[ii] = direction[ii]/mag; } } index++; Loading @@ -84,6 +84,7 @@ public class readFile { public Map<Integer,VertexKey> getMapping() {return indexToVertex;} public double[] getDirection() {return direction;} public double getSpeed() {return speed;} /** * 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 +30 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ public class MovingObject { private Map<Integer, Double> centroidRays; private boolean dirtyTranslate; private double[] velocityVec; private double[] velocityVec, directionVec; private double speed; private double gravity; MovingObject() { texCoords = new float[2]; Loading @@ -32,6 +35,7 @@ public class MovingObject { dirtyTranslate = true; centroidRays = new HashMap<>(); velocityVec = new double[3]; directionVec = new double[3]; } public MovingObject(String[] parameters) { Loading @@ -39,14 +43,18 @@ public class MovingObject { fileObject = new readFile(parameters); fileObject.makeVertexHash(fileObject.getPath()); //fileObject.makeMatrix(); velocityVec = fileObject.getDirection(); directionVec = fileObject.getDirection(); speed = fileObject.getSpeed(); initVelocity(); initPhysics(1, speed); velocityVec = getVelocityVec(); mesh.getPoints().setAll(fileObject.getVertices()); mesh.getFaces().setAll(fileObject.getFaces()); triangleView = new MeshView(mesh); setTempDefault(); setCentroid(); } /* public MovingObject(String filePath) { this(); fileObject = new readFile(filePath); Loading @@ -57,6 +65,11 @@ public class MovingObject { setTempDefault(); setCentroid(); } */ public void initPhysics(double grav, double speed) { gravity = 1; } public void setTexCoords(float t1, float t2) { texCoords[0] = t1; Loading @@ -72,17 +85,26 @@ public class MovingObject { triangleView.getTransforms().add(translate); } public void updateTranslate(double x, double y, double z) { translate.setX(x); translate.setY(y); translate.setZ(z); public void updateTranslate() { velocityVec[1] += gravity; translate.setX(translate.getX() + velocityVec[0]); translate.setY(translate.getY() + velocityVec[1]); translate.setZ(translate.getZ() + velocityVec[2]); } public Translate getTranslate() { return translate; } public double[] getVelocityVec() {return velocityVec;} public double[] getVelocityVec() { return velocityVec; } public void initVelocity() { for (int ii = 0; ii < 3; ii++) { velocityVec[ii] = directionVec[ii] * speed; } } public void setNewFilePath(String filePath) { fileObject = new readFile(filePath); Loading src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +7 −58 Original line number Diff line number Diff line Loading @@ -52,9 +52,9 @@ public class GraphicsAndWindowsTest extends Application { Box ourWindow = sceneWindow.makeWindow(); ObstacleField obs = new ObstacleField(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),350,100, 20, 50, "Box", Color.ORANGERED); // ObstacleField obs = new ObstacleField(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), // sceneWindow.getYOffset(),350,100, 20, 50, "Box", // Color.ORANGERED); String[] ob2 = {"--image", "src/teapot.txt", "--speed", "20", "--dir", "4,", "10,", "6"}; String[] ob3 = {"--image", "src/teapot.txt", "--speed", "5", "--dir", "1,", "1,", "1"}; Loading @@ -81,7 +81,7 @@ public class GraphicsAndWindowsTest extends Application { group3D.setTranslateZ(250); 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 @@ -183,10 +183,8 @@ public class GraphicsAndWindowsTest extends Application { meshBounds[i] = objects[i].getMesh().getBoundsInParent(); direction[i] = objects[i].getVelocityVec(); } //Number is roughly 1 mill divided by 60 if (now - lastUpdate >= 16_000_000) { // Roughly 60 frames per second int lastChanged = 1; double winLeftXBound = sceneWindow.getXOffset(); double winTopYBound = sceneWindow.getYOffset(); Loading @@ -194,65 +192,20 @@ public class GraphicsAndWindowsTest extends Application { // Reverse direction at bounds for (int i = 0; i < objects.length; i++) { if (meshBounds[i].getMinX() + direction[i][0] < winLeftXBound || meshBounds[i].getMaxX() + direction[i][0] > winLeftXBound + WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 0; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getX() + directionX - minX) < 10 || Math.abs(points[j] + translate.getX() + directionX - maxX) < 10) { points[j] += (float) (-directionX*5); } } */ //update the direction of the mesh and set the new coordinates //mesh.getPoints().setAll(points); direction[i][0] *= -1; lastChanged = 1; } if (meshBounds[i].getMinY() + direction[i][1] < winTopYBound || meshBounds[i].getMaxY() + direction[i][1] > winTopYBound + WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 1; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getY() + directionY - minY) < 10 || Math.abs(points[j] + translate.getY() + directionY - maxY) < 10) { points[j] += (float) (-directionY*5); } } */ //update the direction of the mesh and set the new coordinates direction[i][1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMaxZ() + direction[i][2] > WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 2; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getZ() + directionZ - minZ) < 10 || Math.abs(points[j] + translate.getZ() + directionZ - maxZ) < 10) { points[j] += (float) (-directionZ*5); } } */ //update the direction of the mesh and set the new coordinates direction[i][2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); } if(obs.checkCollision(meshBounds[i])){ /*if(obs.checkCollision(meshBounds[i])){ switch (lastChanged){ case 1: direction[i][0] *= -1; Loading @@ -262,12 +215,8 @@ public class GraphicsAndWindowsTest extends Application { default: System.out.println(); } } objects[i].updateTranslate(objects[i].getTranslate().getX() + direction[i][0], objects[i].getTranslate().getY() + direction[i][1], objects[i].getTranslate().getZ() + direction[i][2]); }*/ objects[i].updateTranslate(); System.out.println(Arrays.toString(objects[i].getCentroid())); objects[i].updateRays(); } Loading target/classes/Graph/readFile.class +73 B (8.1 KiB) File changed.No diff preview for this file type. View original file View changed file target/classes/Shape/MovingObject.class +297 B (5.8 KiB) File changed.No diff preview for this file type. View original file View changed file Loading
src/main/java/Graph/readFile.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public class readFile { } mag = Math.sqrt(mag); for (int ii = 0; ii < 3; ii++) { direction[ii] = direction[ii]/mag * speed; direction[ii] = direction[ii]/mag; } } index++; Loading @@ -84,6 +84,7 @@ public class readFile { public Map<Integer,VertexKey> getMapping() {return indexToVertex;} public double[] getDirection() {return direction;} public double getSpeed() {return speed;} /** * 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 +30 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ public class MovingObject { private Map<Integer, Double> centroidRays; private boolean dirtyTranslate; private double[] velocityVec; private double[] velocityVec, directionVec; private double speed; private double gravity; MovingObject() { texCoords = new float[2]; Loading @@ -32,6 +35,7 @@ public class MovingObject { dirtyTranslate = true; centroidRays = new HashMap<>(); velocityVec = new double[3]; directionVec = new double[3]; } public MovingObject(String[] parameters) { Loading @@ -39,14 +43,18 @@ public class MovingObject { fileObject = new readFile(parameters); fileObject.makeVertexHash(fileObject.getPath()); //fileObject.makeMatrix(); velocityVec = fileObject.getDirection(); directionVec = fileObject.getDirection(); speed = fileObject.getSpeed(); initVelocity(); initPhysics(1, speed); velocityVec = getVelocityVec(); mesh.getPoints().setAll(fileObject.getVertices()); mesh.getFaces().setAll(fileObject.getFaces()); triangleView = new MeshView(mesh); setTempDefault(); setCentroid(); } /* public MovingObject(String filePath) { this(); fileObject = new readFile(filePath); Loading @@ -57,6 +65,11 @@ public class MovingObject { setTempDefault(); setCentroid(); } */ public void initPhysics(double grav, double speed) { gravity = 1; } public void setTexCoords(float t1, float t2) { texCoords[0] = t1; Loading @@ -72,17 +85,26 @@ public class MovingObject { triangleView.getTransforms().add(translate); } public void updateTranslate(double x, double y, double z) { translate.setX(x); translate.setY(y); translate.setZ(z); public void updateTranslate() { velocityVec[1] += gravity; translate.setX(translate.getX() + velocityVec[0]); translate.setY(translate.getY() + velocityVec[1]); translate.setZ(translate.getZ() + velocityVec[2]); } public Translate getTranslate() { return translate; } public double[] getVelocityVec() {return velocityVec;} public double[] getVelocityVec() { return velocityVec; } public void initVelocity() { for (int ii = 0; ii < 3; ii++) { velocityVec[ii] = directionVec[ii] * speed; } } public void setNewFilePath(String filePath) { fileObject = new readFile(filePath); Loading
src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +7 −58 Original line number Diff line number Diff line Loading @@ -52,9 +52,9 @@ public class GraphicsAndWindowsTest extends Application { Box ourWindow = sceneWindow.makeWindow(); ObstacleField obs = new ObstacleField(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),350,100, 20, 50, "Box", Color.ORANGERED); // ObstacleField obs = new ObstacleField(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), // sceneWindow.getYOffset(),350,100, 20, 50, "Box", // Color.ORANGERED); String[] ob2 = {"--image", "src/teapot.txt", "--speed", "20", "--dir", "4,", "10,", "6"}; String[] ob3 = {"--image", "src/teapot.txt", "--speed", "5", "--dir", "1,", "1,", "1"}; Loading @@ -81,7 +81,7 @@ public class GraphicsAndWindowsTest extends Application { group3D.setTranslateZ(250); 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 @@ -183,10 +183,8 @@ public class GraphicsAndWindowsTest extends Application { meshBounds[i] = objects[i].getMesh().getBoundsInParent(); direction[i] = objects[i].getVelocityVec(); } //Number is roughly 1 mill divided by 60 if (now - lastUpdate >= 16_000_000) { // Roughly 60 frames per second int lastChanged = 1; double winLeftXBound = sceneWindow.getXOffset(); double winTopYBound = sceneWindow.getYOffset(); Loading @@ -194,65 +192,20 @@ public class GraphicsAndWindowsTest extends Application { // Reverse direction at bounds for (int i = 0; i < objects.length; i++) { if (meshBounds[i].getMinX() + direction[i][0] < winLeftXBound || meshBounds[i].getMaxX() + direction[i][0] > winLeftXBound + WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 0; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getX() + directionX - minX) < 10 || Math.abs(points[j] + translate.getX() + directionX - maxX) < 10) { points[j] += (float) (-directionX*5); } } */ //update the direction of the mesh and set the new coordinates //mesh.getPoints().setAll(points); direction[i][0] *= -1; lastChanged = 1; } if (meshBounds[i].getMinY() + direction[i][1] < winTopYBound || meshBounds[i].getMaxY() + direction[i][1] > winTopYBound + WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 1; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getY() + directionY - minY) < 10 || Math.abs(points[j] + translate.getY() + directionY - maxY) < 10) { points[j] += (float) (-directionY*5); } } */ //update the direction of the mesh and set the new coordinates direction[i][1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMaxZ() + direction[i][2] > WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); /* // find the vertices which come close to the bounding box threshold and squish them into the mesh for (int j = 2; j < points.length; j += 3) { if (Math.abs(points[j] + translate.getZ() + directionZ - minZ) < 10 || Math.abs(points[j] + translate.getZ() + directionZ - maxZ) < 10) { points[j] += (float) (-directionZ*5); } } */ //update the direction of the mesh and set the new coordinates direction[i][2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); } if(obs.checkCollision(meshBounds[i])){ /*if(obs.checkCollision(meshBounds[i])){ switch (lastChanged){ case 1: direction[i][0] *= -1; Loading @@ -262,12 +215,8 @@ public class GraphicsAndWindowsTest extends Application { default: System.out.println(); } } objects[i].updateTranslate(objects[i].getTranslate().getX() + direction[i][0], objects[i].getTranslate().getY() + direction[i][1], objects[i].getTranslate().getZ() + direction[i][2]); }*/ objects[i].updateTranslate(); System.out.println(Arrays.toString(objects[i].getCentroid())); objects[i].updateRays(); } Loading
target/classes/Graph/readFile.class +73 B (8.1 KiB) File changed.No diff preview for this file type. View original file View changed file
target/classes/Shape/MovingObject.class +297 B (5.8 KiB) File changed.No diff preview for this file type. View original file View changed file