Fixed point time based physics ...

Started by
0 comments, last by Vanukoff 22 years, 9 months ago
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
Advertisement
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^_^)

This topic is closed to new replies.

Advertisement