Dave,
I hit exactly this problem also. I ended up writing
a piece of native code to get the time more accurately
which helped a little.
The Windows source code follows, in case it's any use to you.
Rob
NativeClock.java:
package rob.util;
public class NativeClock
{
static
{
System.loadLibrary("NativeClock");
}
public static native double currentTime();
}
NATIVECLOCK.C:
#include "rob_util_NativeClock.h"
#include <windows.h>
JNIEXPORT jdouble JNICALL
Java_rob_util_NativeClock_currentTime(JNIEnv *e, jclass c)
{
jdouble retVal;
LARGE_INTEGER clock_f;
LARGE_INTEGER clock_c;
QueryPerformanceFrequency(&clock_f);
QueryPerformanceCounter(&clock_c);
retVal = (jdouble)clock_c.LowPart;
retVal /= (jdouble)clock_f.LowPart;
return retVal;
}
Rob Nugent
Development Manager
Critical Path Southampton
[EMAIL PROTECTED]
http://www.cp.net
Tel: +44 (0) 1489 585503
Fax: +44 (0) 1489 881363
----- Original Message -----
From: "David" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, March 04, 2001 5:25 PM
Subject: [JAVA3D] Java timer, frame/time based calculations
> We do our view changes and animations per frame, using elapsed time to
> calculate rotations in degrees/sec and movements in meters/sec. That way
> our scene stays consistant even if frame rates drop. But I had long felt
> things were not as smooth as they could be and never looked into it until
> now. Turns out that we are getting elapsed time from one frame to another
> of zero very often, causing our scene to be rendered exactly the same as
> several frames in a row, then a draw a new frame then a few copies, etc.
It
> looks like at around 50 fps, I am getting 3 dups for every 1 real frame
> recalc. Course everything still looks right, but I am losing 3 steps of
> smoothness.
>
> For example if I am rotating my view at 90 degrees per second I am doing
> that in N steps, instead of N*4 steps, thus the rotation is not as smooth
as
> it should be.
>
> At 50 fps, I am calculating a frame every 20 ms. I thought the
> System.currentTimeMillis() had a resolution of 5ms, but it looks like I am
> dead wrong. The numbers below look like 60ms, but its probably 50ms. How
> can I get the time to a better resolution?
>
> Dave Yazel
>
>
> In printing out the time stamps I get this:
>
> Frame got elapsed time of zero (last=983725910240, cur=983725910240 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910290, cur=983725910290 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910290, cur=983725910290 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910350, cur=983725910350 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910350, cur=983725910350 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910350, cur=983725910350 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910400, cur=983725910400 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910400, cur=983725910400 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910400, cur=983725910400 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910400, cur=983725910400 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910460, cur=983725910460 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910460, cur=983725910460 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910460, cur=983725910460 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910510, cur=983725910510 [1 min
7
> sec, 55mb]
> Frame got elapsed time of zero (last=983725910510, cur=983725910510 [1 min
7
> sec, 55mb]
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".