We have tried this technique in many ways this since Java3D 1.1.2.
But there are some hidden problems.
First, on Win9x and NT, System.currentTimeMillis() does not have that good of
accuracy. For example, if you were to print out System.currentTimeMillis() in
a loop, the values will jump at approximately 5ms intervals. i.e.
1000...1000....1000....1005....1005....1005...1011....1011....
Something like that. As I understand it, this is a Windows problem because of
the way it handles multiprocessing and multithreading. Windows is not meant to
be a real-time OS, anyway. BTW, most UNIX OSes will give ~1-2ms accuracy,
which is not must better when you need ~16.7ms to do 60 fps.
Also, sleep() suffers from the same problem. Sleep(20) is not going to be 20ms
that often.
Second, there is a call in Java3D 1.2 to do exactly this. It's
View.setMinimumFrameCycleTime().
However, we have NEVER gotten it to work properly, probably because of the same
problems.
Markus Junginger wrote:
> The Java3D Render Thread uses 100% of the CPU to maximize the frame rate.
> But for the human eye it doesn't make a big difference if it's 25fps or
> 100fps. The CPU-Power is often needed for other calculations. So what do you
> think of my suggestion of overriding the postSwap method of Canvas3D like
> this:
>
> public final void postSwap()
> {
> long now=System.currentTimeMillis();
>
> frames++;
> float fps=frames/((now-last)/1000f);
> if(now>last+secs*1000)
> {
> if(last!=0) System.out.println(fps+" fps");
> last=now;
> frames=0;
> }
> if(fps>25)
> {
> try{Thread.sleep(20);}
> catch(Exception e) {}
> }
> }
>
> My question is now: is it a good solution and is it okay to call sleep() at
> all in postSwap?
> It works fine on my system, and the CPU-Usage scales to the complexity of my
> scene.
>
> Markus Junginger
>
> ===========================================================================
> 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".
--
__________________________________________________________
Shawn Kendall Full Sail Real World Education
Course Director 3300 University BLVD
Real Time 3D for Gaming Winter Park FL 32792
[EMAIL PROTECTED] http://www.fullsail.com
__________________________________________________________
===========================================================================
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".