Loading src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +47 −6 Original line number Diff line number Diff line Loading @@ -19,8 +19,26 @@ import javafx.stage.Stage; import java.io.IOException; import java.util.Arrays; /** * Demonstrates advanced JavaFX graphics and window management by creating a 3D scene with * animated elements and FPS (Frames Per Second) counter. * <p> * This application creates a 3D scene containing a textured cube and a dynamically generated * mesh based on input parameters. It showcases the handling of 3D transformations, animation, * camera movement, and basic input from the keyboard to manipulate the scene. Additionally, * it includes a real-time FPS counter overlaid on the scene to monitor performance. */ public class GraphicsAndWindowsTest extends Application { public static String[] parameters; /** * Starts the JavaFX application. * This method initializes the 3D scene with its objects, animation timer, and event handlers. * * @param stage The primary stage for this application, onto which the scene is set. * @throws IOException If there is an issue reading the input file for generating the mesh. */ @Override public void start(Stage stage) throws IOException { Box cube = new Box(300,300,300); Loading @@ -35,9 +53,10 @@ public class GraphicsAndWindowsTest extends Application { cube.getTransforms().add(translate1); TriangleMesh mesh = new TriangleMesh(); //Texture coordinates used to add image to a mesh //We have it as 0,0 since we do not need an image /** * Texture coordinates used to add image to a mesh. * Initialized at 0, 0 since there is no need for an image. */ float[] texCoords = { 0, 0 }; Loading Loading @@ -118,14 +137,19 @@ public class GraphicsAndWindowsTest extends Application { } }); //Subscene to handle our 3D components //Makes it easier to have 2D and 3D components in the same animation /* * SubScene to handle 3D components * Makes it easier to have 2D and 3D components in the same animation */ SubScene subScene3D = new SubScene(group3D, 1500, 800); subScene3D.setFill(Color.SILVER); subScene3D.setCamera(camera); //Text label to display our FPS /* * Text label to display FPS */ Label fpsLabel = new Label("FPS: 0"); fpsLabel.setTextFill(Color.WHITE); Loading @@ -151,6 +175,17 @@ public class GraphicsAndWindowsTest extends Application { 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. This method contains the logic for * updating the scene's elements, such as moving objects, checking for boundary conditions, and updating * the FPS counter displayed in the scene. * <p> * Movement and boundary checking are based on the bounds of the 3D mesh and the cube within the scene. * The FPS counter is updated once every second, based on the number of frames rendered in that interval. * * @param now The timestamp of the current frame given in nanoseconds. This value can be used to * calculate the time difference between frames for smooth animation and movement. */ @Override public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Loading Loading @@ -196,6 +231,12 @@ public class GraphicsAndWindowsTest extends Application { }; timer.start(); } /** * The entry point of the application. This method is called when the application starts. * * @param args Command-line arguments passed to the application. Expected to contain * parameters for mesh generation and other configurations. */ public static void main(String[] args) { Application.launch(args); } Loading Loading
src/main/java/org/example/newmat/GraphicsAndWindowsTest.java +47 −6 Original line number Diff line number Diff line Loading @@ -19,8 +19,26 @@ import javafx.stage.Stage; import java.io.IOException; import java.util.Arrays; /** * Demonstrates advanced JavaFX graphics and window management by creating a 3D scene with * animated elements and FPS (Frames Per Second) counter. * <p> * This application creates a 3D scene containing a textured cube and a dynamically generated * mesh based on input parameters. It showcases the handling of 3D transformations, animation, * camera movement, and basic input from the keyboard to manipulate the scene. Additionally, * it includes a real-time FPS counter overlaid on the scene to monitor performance. */ public class GraphicsAndWindowsTest extends Application { public static String[] parameters; /** * Starts the JavaFX application. * This method initializes the 3D scene with its objects, animation timer, and event handlers. * * @param stage The primary stage for this application, onto which the scene is set. * @throws IOException If there is an issue reading the input file for generating the mesh. */ @Override public void start(Stage stage) throws IOException { Box cube = new Box(300,300,300); Loading @@ -35,9 +53,10 @@ public class GraphicsAndWindowsTest extends Application { cube.getTransforms().add(translate1); TriangleMesh mesh = new TriangleMesh(); //Texture coordinates used to add image to a mesh //We have it as 0,0 since we do not need an image /** * Texture coordinates used to add image to a mesh. * Initialized at 0, 0 since there is no need for an image. */ float[] texCoords = { 0, 0 }; Loading Loading @@ -118,14 +137,19 @@ public class GraphicsAndWindowsTest extends Application { } }); //Subscene to handle our 3D components //Makes it easier to have 2D and 3D components in the same animation /* * SubScene to handle 3D components * Makes it easier to have 2D and 3D components in the same animation */ SubScene subScene3D = new SubScene(group3D, 1500, 800); subScene3D.setFill(Color.SILVER); subScene3D.setCamera(camera); //Text label to display our FPS /* * Text label to display FPS */ Label fpsLabel = new Label("FPS: 0"); fpsLabel.setTextFill(Color.WHITE); Loading @@ -151,6 +175,17 @@ public class GraphicsAndWindowsTest extends Application { 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. This method contains the logic for * updating the scene's elements, such as moving objects, checking for boundary conditions, and updating * the FPS counter displayed in the scene. * <p> * Movement and boundary checking are based on the bounds of the 3D mesh and the cube within the scene. * The FPS counter is updated once every second, based on the number of frames rendered in that interval. * * @param now The timestamp of the current frame given in nanoseconds. This value can be used to * calculate the time difference between frames for smooth animation and movement. */ @Override public void handle(long now) { //Built in class that helps calculate the bounds of the mesh for collision Loading Loading @@ -196,6 +231,12 @@ public class GraphicsAndWindowsTest extends Application { }; timer.start(); } /** * The entry point of the application. This method is called when the application starts. * * @param args Command-line arguments passed to the application. Expected to contain * parameters for mesh generation and other configurations. */ public static void main(String[] args) { Application.launch(args); } Loading