Kaynağa Gözat

thx chatgpt

____tbvns____ 5 ay önce
ebeveyn
işleme
f8b8348821

+ 18 - 11
PowerGDEditor/src/main/java/xyz/tbvns/Models/GDInstance.java

@@ -38,21 +38,28 @@ public class GDInstance {
     public Model getFrameOnPercent(double percent) {
         double usablePercent = percent - (start / 100);
         if (usablePercent > 0) {
-            float max = LevelInfo.getLevel().getMaxPos();
-            double speed = LevelInfo.getLevel().getSpeedAt((float) percent);
-            //Animation length in second
-            //TODO: MAKE THIS WORK + add a function to convert percentage to time with correct estimation pf speed (
-            double fullTime = (double) animationObject.getFrames().size() / 24;
-            int frame = 0;
-            if (!(frame > animationObject.getModelFrames().size() - 1)) {
-                System.out.println(frame);
-                return animationObject.getModelFrames().get(frame);
+            float max = LevelInfo.getLevel().getMaxPos(); // Max distance
+            double pos = max * usablePercent; // Position based on percent traveled
+            double speed = LevelInfo.getLevel().getSpeedAt((float) percent); // Speed at the current position
+
+            // Calculate the distance per frame
+            double distancePerFrame = (speed / fps) * 10; // Speed divided by FPS gives distance per frame
+
+            // Calculate the current frame
+            int frame = (int) (pos / distancePerFrame); // Position divided by distance per frame
+
+            System.out.println(pos + " - " + frame);
+
+            // Ensure the frame is within bounds
+            if (frame < animationObject.getModelFrames().size()) {
+                return animationObject.getModelFrames().get(frame); // Return the correct frame
             }
-            return animationObject.getModelFrames().getLast();
+            return animationObject.getModelFrames().getLast(); // If out of bounds, return last frame
         }
-        return animationObject.getModelFrames().getFirst();
+        return animationObject.getModelFrames().getFirst(); // If no progress, return first frame
     }
 
+
     private ModelInstance instance;
     private boolean animation;
     private double start;

+ 4 - 4
PowerGDEditor/src/main/java/xyz/tbvns/Utils.java

@@ -23,8 +23,8 @@ public class Utils {
     public static float getCameraPercent() {
         return Main.getCamera().position.x / (LevelInfo.getLevel().getMaxPos() / 30);
     }
-
-    public static float percentToTime() {
-        //TODO: add that
-    }
+//
+//    public static float percentToTime() {
+//        //TODO: add that
+//    }
 }