#### Archived

This topic is now archived and is closed to further replies.

# Fixed point time based physics ...

This topic is 6233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Every time based physics solution I've seen involves the use of floating point solutions. Basically multiplying all motion by a floating point factor. Here is what I am currently implementing in my game. All my positions and velocities are stored in fixed point format. I assume that one second = 1024 milliseconds. My main physics section looks like this pseudocode:
  void Game::main(int dt) // dt is last loop time in msec { for(each object) { object.pos.x += (dt*object.vel.x)/1024; object.pos.y += (dt*object.vel.y)/1024; } } 
Basically, by treating my time delta as a 22.10 fixed point number, I can do all my physics using fixed point math. Anyway, in reality, with modern processors, floating point is not that big a deal, and there are probably better ways to do this, but I just thought I'd throw this out. Edited by - Vanukoff on June 27, 2001 9:18:17 PM

##### Share on other sites
Yes, modern computers handle floating points just fine, but converting them to ints when doing collision detection (if you''re using tile-based CD, since you''d have to either convert the sprite coords to int or tile coords to float). You have to convert for blitting too, and with fixed, it just takes one shift to do it, which is why I''m using fixed in my engine too. One cool time saver I''ve found is make a variable, and divide your time delta by 1024, and then just multiply all your values by that. Only one mul with a small value (I''ve heard it''s faster to multiply a large number by a small one than a small one by a large, so do like pos * incVal instead of incVal * pos), and no slow divide^^

-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002278
×