Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (652)
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 1993 times)
0 Members and 1 Guest are viewing this topic.
Offline KONI

Junior Devvie

Java games rock!

« Posted 2003-12-03 06: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

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

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

 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



Offline blahblahblahh

JGO Coder

Medals: 1

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

 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

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

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

 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.



Offline kevglass

« JGO Spiffy Duke »

Medals: 272
Projects: 25
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #4 - Posted 2003-12-03 07: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.


Offline KONI

Junior Devvie

Java games rock!

« Reply #5 - Posted 2003-12-03 11: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.

SHC (17 views)
2015-08-01 03:58:20

Jesse (18 views)
2015-07-29 04:35:27

Riven (38 views)
2015-07-27 16:38:00

Riven (20 views)
2015-07-27 15:35:20

Riven (23 views)
2015-07-27 12:26:13

Riven (13 views)
2015-07-27 12:23:39

BurntPizza (34 views)
2015-07-25 00:14:37

BurntPizza (45 views)
2015-07-24 22:06:39

BurntPizza (26 views)
2015-07-24 06:06:53

NoxInc (34 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!