Loading src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +61 −42 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ import java.util.Arrays; */ public class GraphicsAndWindowsTest extends Application { //public static String[] parameters; public static MovingObject[] objects; /** * Starts the JavaFX application. * This method initializes the 3D scene with its objects, animation timer, and event handlers. Loading @@ -48,14 +48,29 @@ public class GraphicsAndWindowsTest extends Application { Box ourWindow = sceneWindow.makeWindow(); //Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); MovingObject newObject = new MovingObject(getParameters().getRaw().toArray(new String[0])); String[] ob2 = {"--image", "src/teapot.txt", "--speed", "20", "--dir", "4,", "10,", "6"}; String[] ob3 = {"--image", "src/teapot.txt", "--speed", "5", "--dir", "1,", "1,", "1"}; MovingObject newObject1 = new MovingObject(getParameters().getRaw().toArray(new String[0])); MovingObject newObject2 = new MovingObject(ob2); MovingObject newObject3 = new MovingObject(ob3); objects = new MovingObject[3]; objects[0] = newObject1; objects[1] = newObject2; objects[2] = newObject3; //--image src/teapot.txt --speed 10 --dir 8, 4, 10 // Create a Translate transform // Set the translation values newObject.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject1.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject2.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject3.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); Group group3D = new Group(); // Group of our 3D elements group3D.getChildren().add(newObject.getMesh()); group3D.getChildren().add(newObject1.getMesh()); group3D.getChildren().add(newObject2.getMesh()); group3D.getChildren().add(newObject3.getMesh()); group3D.getChildren().add(ourWindow); group3D.getChildren().add(new AmbientLight(Color.WHITE)); //obs.addToGroup(group3D); Loading Loading @@ -151,14 +166,16 @@ public class GraphicsAndWindowsTest extends Application { @Override public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Bounds meshBounds = newObject.getMesh().getBoundsInParent(); 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]; //Bounds meshBounds = newObject1.getMesh().getBoundsInParent(); Bounds[] meshBounds = {newObject1.getMesh().getBoundsInParent(),newObject2.getMesh().getBoundsInParent(),newObject3.getMesh().getBoundsInParent()}; double[][] direction = {newObject1.getVelocityVec(),newObject2.getVelocityVec(),newObject3.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 @@ -167,7 +184,8 @@ public class GraphicsAndWindowsTest extends Application { double winTopYBound = sceneWindow.getYOffset(); double WindowSize = sceneWindow.getWindowSize(); // Reverse direction at bounds if (minX < winLeftXBound || maxX > winLeftXBound + WindowSize) { 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); Loading @@ -182,11 +200,14 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates direction1[0] *= -1; lastChanged = 1; //mesh.getPoints().setAll(points); direction[i][0] *= -1; lastChanged = 1; } if (minY < winTopYBound || maxY > winTopYBound+WindowSize) { 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); Loading @@ -199,11 +220,11 @@ public class GraphicsAndWindowsTest extends Application { } */ //update the direction of the mesh and set the new coordinates direction1[1] *= -1; direction[i][1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } if (minZ < 0 || maxZ > WindowSize) { if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMinZ() + direction[i][2] > WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); Loading @@ -217,7 +238,7 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates direction1[2] *= -1; direction[i][2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); Loading @@ -235,12 +256,10 @@ public class GraphicsAndWindowsTest extends Application { } directionY *= -1; }*/ 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(); objects[i].updateTranslate(objects[i].getTranslate().getX() + direction[i][0], objects[i].getTranslate().getY() + direction[i][1], objects[i].getTranslate().getZ() + direction[i][2]); System.out.println(Arrays.toString(objects[i].getCentroid())); objects[i].updateRays(); } lastUpdate = now; } if (fpsTimer == 0) { Loading target/classes/org/example/newmat/GraphicsAndWindowsTest$1.class +101 B (3.32 KiB) File changed.No diff preview for this file type. View original file View changed file target/classes/org/example/newmat/GraphicsAndWindowsTest$2.class (830 B) File changed.No diff preview for this file type. View original file View changed file target/classes/org/example/newmat/GraphicsAndWindowsTest.class +546 B (5.88 KiB) File changed.No diff preview for this file type. View original file View changed file Loading
src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +61 −42 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ import java.util.Arrays; */ public class GraphicsAndWindowsTest extends Application { //public static String[] parameters; public static MovingObject[] objects; /** * Starts the JavaFX application. * This method initializes the 3D scene with its objects, animation timer, and event handlers. Loading @@ -48,14 +48,29 @@ public class GraphicsAndWindowsTest extends Application { Box ourWindow = sceneWindow.makeWindow(); //Obstacle obs = new Obstacle(sceneWindow.getWindowSize(),sceneWindow.getXOffset(), sceneWindow.getYOffset(),10,100); MovingObject newObject = new MovingObject(getParameters().getRaw().toArray(new String[0])); String[] ob2 = {"--image", "src/teapot.txt", "--speed", "20", "--dir", "4,", "10,", "6"}; String[] ob3 = {"--image", "src/teapot.txt", "--speed", "5", "--dir", "1,", "1,", "1"}; MovingObject newObject1 = new MovingObject(getParameters().getRaw().toArray(new String[0])); MovingObject newObject2 = new MovingObject(ob2); MovingObject newObject3 = new MovingObject(ob3); objects = new MovingObject[3]; objects[0] = newObject1; objects[1] = newObject2; objects[2] = newObject3; //--image src/teapot.txt --speed 10 --dir 8, 4, 10 // Create a Translate transform // Set the translation values newObject.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject1.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject2.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); newObject3.setTranslate(sceneWindow.getXOffset(), sceneWindow.getYOffset(),0); Group group3D = new Group(); // Group of our 3D elements group3D.getChildren().add(newObject.getMesh()); group3D.getChildren().add(newObject1.getMesh()); group3D.getChildren().add(newObject2.getMesh()); group3D.getChildren().add(newObject3.getMesh()); group3D.getChildren().add(ourWindow); group3D.getChildren().add(new AmbientLight(Color.WHITE)); //obs.addToGroup(group3D); Loading Loading @@ -151,14 +166,16 @@ public class GraphicsAndWindowsTest extends Application { @Override public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Bounds meshBounds = newObject.getMesh().getBoundsInParent(); 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]; //Bounds meshBounds = newObject1.getMesh().getBoundsInParent(); Bounds[] meshBounds = {newObject1.getMesh().getBoundsInParent(),newObject2.getMesh().getBoundsInParent(),newObject3.getMesh().getBoundsInParent()}; double[][] direction = {newObject1.getVelocityVec(),newObject2.getVelocityVec(),newObject3.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 @@ -167,7 +184,8 @@ public class GraphicsAndWindowsTest extends Application { double winTopYBound = sceneWindow.getYOffset(); double WindowSize = sceneWindow.getWindowSize(); // Reverse direction at bounds if (minX < winLeftXBound || maxX > winLeftXBound + WindowSize) { 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); Loading @@ -182,11 +200,14 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates direction1[0] *= -1; lastChanged = 1; //mesh.getPoints().setAll(points); direction[i][0] *= -1; lastChanged = 1; } if (minY < winTopYBound || maxY > winTopYBound+WindowSize) { 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); Loading @@ -199,11 +220,11 @@ public class GraphicsAndWindowsTest extends Application { } */ //update the direction of the mesh and set the new coordinates direction1[1] *= -1; direction[i][1] *= -1; lastChanged = 2; //mesh.getPoints().setAll(points); } if (minZ < 0 || maxZ > WindowSize) { if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMinZ() + direction[i][2] > WindowSize) { // load the vertices of the mesh //float[] points = mesh.getPoints().toArray(null); Loading @@ -217,7 +238,7 @@ public class GraphicsAndWindowsTest extends Application { */ //update the direction of the mesh and set the new coordinates direction1[2] *= -1; direction[i][2] *= -1; lastChanged = 3; //mesh.getPoints().setAll(points); Loading @@ -235,12 +256,10 @@ public class GraphicsAndWindowsTest extends Application { } directionY *= -1; }*/ 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(); objects[i].updateTranslate(objects[i].getTranslate().getX() + direction[i][0], objects[i].getTranslate().getY() + direction[i][1], objects[i].getTranslate().getZ() + direction[i][2]); System.out.println(Arrays.toString(objects[i].getCentroid())); objects[i].updateRays(); } lastUpdate = now; } if (fpsTimer == 0) { Loading
target/classes/org/example/newmat/GraphicsAndWindowsTest$1.class +101 B (3.32 KiB) File changed.No diff preview for this file type. View original file View changed file
target/classes/org/example/newmat/GraphicsAndWindowsTest$2.class (830 B) File changed.No diff preview for this file type. View original file View changed file
target/classes/org/example/newmat/GraphicsAndWindowsTest.class +546 B (5.88 KiB) File changed.No diff preview for this file type. View original file View changed file