Tuesday, September 8, 2009

I can haz physicz?

Since these days I am mainly a full-time dad when I get home from the day job, I was somewhat surprised when I completed the integration of Chipmunk physics to my game engine over the long weekend (Labor day FTW!). Needless to said, it is pretty exciting when things are starting to come together after weeks of intense preparations :-)

Like I was saying in my previous post, there's various API to chose from when looking to add real world (2D) physics to your game. I picked Chipmunk mainly because it's in C and relatively simple. My main grip with it, is the lack of a complete, and correct, documentation. I found myself having to dive in its source code to understand or clarify some things, and while it's great to be able to do so, I shouldn't have to. A 3rd party API should be well documented, including comments in the header files! Here's a (lame) example: once you have created a body (cpBody) the API provide a set of functions which allow you to physically manipulate it, such as applying a force on it. The thing is, the wording of the purpose on the function cpBodyApplyForce is a little ambiguous: "Apply (accumulate) the force f on body at a relative offset r from the center of gravity. Both r and f are in world coordinates." ... Is the force applied for a single simulation step or permanently? It turns out that it will be applied at each steps, until all forces on the body are reset (using cpBodyResetForces) ... Maybe it's just me? The mention to "accumulate" should have been enough? Also, the r and f cited are most definitely NOT in world coordinate, but in offset from the body's center of gravity ...

Anyhow, overall Chipmunk physics is a big win, I could have grabbed Physics for Game Developers at my local book store, but this is saving me time and headache so: Yeah! :-)

Now that two majors items on my engine's to-do list are done with (the first been the rendering), I'm moving on to handling user inputs, which by it-self isn't that hard, but I'd like to be able to detect the basic gestures that we, as iPhone users, are used to: flicking and pinching. I'm not sure if I need them for the first game I have planned, but ... since I'm doing a game framework, mind as well try to be as complete as possible! At least, I'll need to provision for gestures handling even if I leave the detection for a later version of the framework ... That's one of the malediction of being a framework kind of guy, most of your time is spend on the framework rather than the end result ...

No comments: