diff examples/java3d/FPS.java @ 1:5df24c91468d

Oh my what a mess.
author samer
date Fri, 05 Apr 2019 16:26:00 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/java3d/FPS.java	Fri Apr 05 16:26:00 2019 +0100
@@ -0,0 +1,32 @@
+import javax.media.j3d.*;
+import javax.vecmath.*;
+import java.util.Enumeration;
+
+final class FPS extends Behavior {
+
+    protected int nFrames;
+    protected long startTime;
+    protected final WakeupCondition w;
+
+    public FPS(int nFrames){
+        this.nFrames=nFrames;
+        w=new WakeupOnElapsedFrames(nFrames);        
+    }
+
+    public FPS(){
+        this(100);
+    }
+
+    public void initialize(){
+        setSchedulingBounds(new BoundingSphere(new Point3d(),1000));
+        startTime=System.currentTimeMillis();
+        wakeupOn(w);
+    }
+
+    public void processStimulus(Enumeration criteria){
+        long time=System.currentTimeMillis();
+        System.err.println("fps: "+ 1000 * (double) nFrames / (double) (time-startTime));
+        startTime=time;
+        wakeupOn(w);
+    }
+}