/********************************************************************************************* Northeastern University MIME Department Course: MIM3142, Building Virtual Environments using Java3D Term: Spring, 1999 professor: Ronald R. Mourant Student: Talal Al-Shihabi taken from the Particles example written by Jeff White at Brown University *********************************************************************************************/ /********************************************************************************************* class FPS: show the frame rate of the program *********************************************************************************************/ 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; protected static float frameRate; public int i=1; public FPS(int nFrames){ this.nFrames = nFrames; w = new WakeupOnElapsedFrames(nFrames); } public FPS(){ this(200); } public void initialize(){ setSchedulingBounds (new BoundingSphere( new Point3d(), 1000)); startTime = System.currentTimeMillis(); wakeupOn(w); } public void processStimulus(Enumeration criteria){ long time = System.currentTimeMillis(); frameRate=1000 * (float)nFrames/(float)(time-startTime); System.out.println("fps:"+ frameRate); startTime = time; wakeupOn(w); } public static float getFrameRate() { return frameRate; } }