Framerate control + basic physics math
Hi all, I'm new here and getting back into mac game programming after a very long hiatus (think System 7 & COPYBITS
. So I guess I wanted to introduce myself first (hi.) and also ask a few quick questions to anyone who might know:
1) i'm currently working on a game and am trying to implement a framerate 'control' variable. i basically have an NSTimer that calculates all my movement in the game, and then sends a SetNeedsDisplay to the main game view at the very end. in the beginning of the timer I calculate a control kinda like:
frameRateControl = ((currentTime - lastTimerFireTime) / idealFramerate);
And then I multiply that value anytime I calculate a movement, such a sprites change in location, for instance. This seems to produce the correct results, but am I doing this the 'right' way? Or am I supposed to be using this control variable in the NSView's drawing method instead of the timer? I'm a bit unsure as to whether i'm implementing this technique properly.
2nd Question) does anyone know of any books or websites that give a 'crash course' in basic trig/calculus equations I can brush up on for my games physics? sadly I do not remember as much from my highschool math classes as I should and it would be nice to find some kind of online 'game math for dummies' site.
3rd question) has anyone noticed a decline in the amount of people doing cocoa develoment? i get concerned sometimes because it seems like there is such a tremendous lack of 'community' among cocoa users, I have trouble finding any websites (other than a few like these) that have active coca discussions. anyone have any links they want to share?
thanks for your help~
oh and there's an ingame screenshot of my game here if anyone would like to take a peek:
. So I guess I wanted to introduce myself first (hi.) and also ask a few quick questions to anyone who might know:1) i'm currently working on a game and am trying to implement a framerate 'control' variable. i basically have an NSTimer that calculates all my movement in the game, and then sends a SetNeedsDisplay to the main game view at the very end. in the beginning of the timer I calculate a control kinda like:
frameRateControl = ((currentTime - lastTimerFireTime) / idealFramerate);
And then I multiply that value anytime I calculate a movement, such a sprites change in location, for instance. This seems to produce the correct results, but am I doing this the 'right' way? Or am I supposed to be using this control variable in the NSView's drawing method instead of the timer? I'm a bit unsure as to whether i'm implementing this technique properly.
2nd Question) does anyone know of any books or websites that give a 'crash course' in basic trig/calculus equations I can brush up on for my games physics? sadly I do not remember as much from my highschool math classes as I should and it would be nice to find some kind of online 'game math for dummies' site.

3rd question) has anyone noticed a decline in the amount of people doing cocoa develoment? i get concerned sometimes because it seems like there is such a tremendous lack of 'community' among cocoa users, I have trouble finding any websites (other than a few like these) that have active coca discussions. anyone have any links they want to share?
thanks for your help~
oh and there's an ingame screenshot of my game here if anyone would like to take a peek:
Yes thats a perfectly sensible and accurate way to do it, I always do physics type movement this way and you can write a decent realtime game with Cocoa.
Sir, e^iπ + 1 = 0, hence God exists; reply!
unknown Wrote:Yes thats a perfectly sensible and accurate way to do it, I always do physics type movement this way and you can write a decent realtime game with Cocoa.
Why does that strike me as funny

Anyway, the (currentTime - lastTimerFireTime) interval is what you should use for your physics calculations if you want real-time physics. The way you do it will slow the game speed down as framerate drops, which might be OK if that's intended.
Generally, I only calculate a frameRateControl like variable to adjust level of detail, so that the physics keeps marching on at a uniform rate, which is important for networked play, for example.
This may be of interest: http://www.sacredsoftware.net/tutorials/...tion.xhtml
>This thread< has some good info/links on fixed vs. variable time steps.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Best way to calculate framerate | ferum | 18 | 14,803 |
Sep 7, 2006 11:05 AM Last Post: TomorrowPlusX |
|
| Bullet Physics Library / COLLADA physics viewer | erwincoumans | 14 | 11,251 |
Aug 12, 2006 12:59 AM Last Post: Fenris |
|
| NSTimer / animation framerate question | MonitorFlickers | 5 | 4,519 |
Dec 4, 2005 01:10 PM Last Post: MonitorFlickers |
|
| Basic questions about rigid body physics | hangt5 | 15 | 5,527 |
Jul 7, 2005 04:18 PM Last Post: hangt5 |
|
| Simple physics math | LongJumper | 8 | 3,379 |
Sep 5, 2003 08:23 PM Last Post: mars |
|

