Framerate control + basic physics math

Apprentice
Posts: 11
Joined: 2007.01
Post: #1
Hi all, I'm new here and getting back into mac game programming after a very long hiatus (think System 7 & COPYBITS Wink. 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. Smile

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:

[Image: inGameScreenshot_2.jpg?t=1168412311]
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
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!
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #3
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 Smile

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.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #5
>This thread< has some good info/links on fixed vs. variable time steps.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Best way to calculate framerate ferum 18 19,230 Sep 7, 2006 11:05 AM
Last Post: TomorrowPlusX
  Bullet Physics Library / COLLADA physics viewer erwincoumans 14 12,970 Aug 12, 2006 12:59 AM
Last Post: Fenris
  NSTimer / animation framerate question MonitorFlickers 5 5,208 Dec 4, 2005 01:10 PM
Last Post: MonitorFlickers
  Basic questions about rigid body physics hangt5 15 6,352 Jul 7, 2005 04:18 PM
Last Post: hangt5
  Simple physics math LongJumper 8 3,901 Sep 5, 2003 08:23 PM
Last Post: mars