Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 1747 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 »

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 07: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

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


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

« JGO Spiffy Duke »


Medals: 212
Projects: 24
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.

Kev

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.

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-23 03:34:11

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!