Skip to content

Commit

Permalink
jse3d v1.2.1 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Emery Ferrari committed May 6, 2020
1 parent e94f1fd commit 53dcd57
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/com/emeryferrari/jse3d/JSE3DConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ public class JSE3DConst {
public static final String NAME = "jse3d";
public static final String VERSION = "v1.2 beta";
public static final String FULL_NAME = JSE3DConst.NAME + " " + JSE3DConst.VERSION;
public static final int PHYSICS_TIMESTEP = 60;
}
7 changes: 1 addition & 6 deletions src/com/emeryferrari/jse3d/Point3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,22 @@ private Transition(double x, double y, double z, int millis) {
}
@Override
public void run() {
boolean done = false;
double xDiff = xt-x;
double yDiff = yt-y;
double zDiff = zt-z;
double xIteration = xDiff/(double)(60.0*((double)millis/1000.0));
double yIteration = yDiff/(double)(60.0*((double)millis/1000.0));
double zIteration = zDiff/(double)(60.0*((double)millis/1000.0));
int fps = 0;
long lastFpsTime = 0L;
long lastLoopTime = System.nanoTime();
final int TARGET_FPS = 60;
final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
final long OPTIMAL_TIME = 1000000000 / JSE3DConst.PHYSICS_TIMESTEP;
for (int i = 0; i < (int)(60.0*((double)millis/1000.0)); i++) {
long now = System.nanoTime();
long updateLength = now - lastLoopTime;
lastLoopTime = now;
lastFpsTime += updateLength;
fps++;
if (lastFpsTime >= 1000000000) {
lastFpsTime = 0;
fps = 0;
}
movePos(x+xIteration, y+yIteration, z+zIteration);
try {Thread.sleep((lastLoopTime-System.nanoTime()+OPTIMAL_TIME)/1000000);} catch (InterruptedException ex) {ex.printStackTrace();}
Expand Down

0 comments on commit 53dcd57

Please sign in to comment.