Commit 91b0f70e authored by Timothy  Borunov's avatar Timothy Borunov
Browse files

NOW WITH AIR RESISTANCE

parent d4a5a9e3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+27 −1
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ public class GraphicsAndWindowsTest extends Application {
            private long fpsTimer = 0; //Frame timer
            private long frameRate = 0; //Frames per second



            /**
             * Called at every frame while the {@link AnimationTimer} is active to update the scene's elements,
             * including object movements, boundary condition checks, mesh deformation on collision, and FPS counter updates.
@@ -192,10 +194,30 @@ public class GraphicsAndWindowsTest extends Application {
                    double WindowSize = sceneWindow.getWindowSize();
                    // Reverse direction at bounds
                    for (int i = 0; i < objects.length; i++) {
                        direction[i][1] += 1;
                        double GRAVITY = 1;
                        double AIRRESISTANCE = 0.05;
                        //Physics updates
                        //Gravity
                        direction[i][1] += GRAVITY;

                        //air resistance computation
                        double mag = 0;
                        for (int j = 0; j < 3; j++ ) {
                            mag += Math.pow(direction[i][j],2);
                        }
                        mag = Math.sqrt(mag);
                        double airResistance = mag * AIRRESISTANCE;
                        direction[i][0] = direction[i][0] - (direction[i][0] / mag * airResistance);
                        direction[i][1] = direction[i][1] - (direction[i][1] / mag * airResistance);
                        direction[i][2] = direction[i][2] - (direction[i][2] / mag * airResistance);


                        double x = direction[i][0];
                        double y = direction[i][1];
                        double z = direction[i][2];

                        // the following will be class methods in the future
                        // Window Collision computation for X
                        if (meshBounds[i].getMinX() + direction[i][0] < winLeftXBound || meshBounds[i].getMaxX() + direction[i][0]  > winLeftXBound + WindowSize) {

                            if (meshBounds[i].getMinX() + x < winLeftXBound) {
@@ -208,6 +230,8 @@ public class GraphicsAndWindowsTest extends Application {
                            lastChanged = 1;

                        }

                        // Window Collision computation for Y
                        if (meshBounds[i].getMinY() + direction[i][1] < winTopYBound || meshBounds[i].getMaxY() + direction[i][1] > winTopYBound + WindowSize) {

                            if (meshBounds[i].getMinY() + y < winTopYBound) {
@@ -219,6 +243,8 @@ public class GraphicsAndWindowsTest extends Application {
                            direction[i][1] *= -1;
                            lastChanged = 2;
                        }

                        // Window Collision computation for Z
                        if (meshBounds[i].getMinZ() + direction[i][2] < 0 || meshBounds[i].getMaxZ() + direction[i][2] > WindowSize) {
                            if (meshBounds[i].getMinZ() + z < 0) {
                                z = direction[i][2] + (0 - (meshBounds[i].getMinZ() + z));