Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  physics & rendering loop  (Read 1356 times)
0 Members and 1 Guest are viewing this topic.
Offline KONI

Junior Member




Java games rock!


« Posted 2003-12-03 07:03:24 »

I've read through the thread with "the discreet rendering loop" but I still have some questions:

I am programming a physics engine with unlimited forces acting on unlimited numbers of objects in a environment. For each object I am calculating the result of the forces and applying it correctly. This is already working.

But I use for the physics a loop with an interval of 50 ms, which means that it will be calculated 20 times per second. Until now I have a passive rendering mode, which means that I do a repaint() in the physics loop.

What I don't understand: Even if I would do a rendering loop, the position of the objects won't change for 50 ms, so what is actually the reason of repainting when there isn't something new to display ?

When an object reaches a suffisent fast velocity, it changes its position in 50ms for let's say 20pixels...this means that I will get a sloppy movement animation even if I render at more than 50ms ?!?!

What am I doing wrong ?

A solution I could imagine would be to move the object in the rendering loop just enough so that it will be a smooth animation...but I don't know exactly...

The entire code is quite big and I don't want to annoy you here with bad code.
Offline endolf
« League of Dukes »

JGO Coder


Medals: 4
Projects: 1


Current project release date: sometime in 3003


« Reply #1 - Posted 2003-12-03 07:11:23 »

Hi
 You have two options really, increase the speed of your physics loop so that it updates as fast as you are rendering, or, interpolate, interpolation is good over a network as it means reduced coms, but if your not worried about a network layer then just redner as fast as you can and call you update method on your physics loop every frame.
 If you arn't already doing it then you will need to modify your physics loop so that it works of a time since last move, rather than a fixed 50ms update, then it will be nice and smooth Smiley

HTH

Endolf

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2003-12-03 08:07:11 »

Quote
Hi
 You have two options really, increase the speed of your physics loop so that it updates as fast as you are rendering, or, interpolate,


At 20 fps, how effective are the different ways of interpolating physics?

E.g. You could

  • zero all forces between physics frames, and hold all velocities constant. The lower the acceleration on an object the nearer this would be to perfect, but without having to do anything but linear interpolation
  • hold all resultant forces constant, and interpolate changes to velocities. This would presumably be less expensive than doing a full calculation?


But how are you managing collisions? Interpolating between physics frames is going to cause "bounces" if you only do the collision checks at physic frames (i.e. interpolates through a wall, then the physics kicks in and bounces it back again. At 20 fps the human eye will consciously see this very obviously. At 75 fps there will be a noticeable flicker, but most humans won't know why. If you had physics at 100 fps, theoretically no-one would even see the bounces).

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf
« League of Dukes »

JGO Coder


Medals: 4
Projects: 1


Current project release date: sometime in 3003


« Reply #3 - Posted 2003-12-03 08:17:11 »

Hi
 Thats why I didn't really go into interpolation, it's bad enough when you are just doing it on movement of objects like ships or people, but this would be even worse, but if there is a network in there then it's probably the best choice. The best bet with no network is just to run the physics engine as fast as your rendering loop, the extra load from the physics will reduce the frame rate, but will look alot better than if you render faster than you are drawing.

HTH

Endolf

Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #4 - Posted 2003-12-03 08:29:35 »

Thats what I currently do. However, if I was to stick a network into the equation I'd still run the physics as fast as the renderer. EDIT: Effectively I suppose its the same thing, its just the way you choose to interpolate.

However, the server would override the positions/velocities of things if they were out of sync. This only works if you use your second option above, storing the resultant forces and continuing calculating what you think the server will calculate between updates. I've used this in the past and it gives results you'd expect, if something happens between updates that your client simply couldn't predict you get a jump.

Kev

Offline KONI

Junior Member




Java games rock!


« Reply #5 - Posted 2003-12-03 12:46:13 »

I am still using a passive renderer but I now manage to run it at 10 ms interval. I know this may sound stupid but I ain't that good in english and therefor ... what exactly is this interpolating thing ?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (168 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.093 seconds with 21 queries.