Kolf: 1. Box2D, 2. ???, 3. Profit!!!

February 12, 2010

The semester is nearly finished; Tuesday is the last exam (on quantum field theory). So finally I have some time for hacking. In the last few months, aside from some personal stuff, hacking almost exclusively meant Palapeli for me. I’m currently working on the design of the next version of Palapeli (with GHNS and puzzle piles, if everything works out), but that’s not what I’m hacking on right now.

In Kolf 2, I’ve decided some time ago to abandon the third spatial dimension and completely return to the classic Kolf feeling. This big change means exchanging the Open Dynamics Engine by a 2D physics engine. There seems to be only one good 2D physics engine around, Box2D. Incidentally, Box2D switched to CMake just two weeks ago.

After only some hours, I had some first prototypes of how I could implement the current Kolf-NG on top of Box2D. In order to get a clean design, I chose not to rewrite Kolf-NG from ODE to Box2D, but to create a complete new Kolf, with big parts of code being adapted from Kolf-NG. Now there are three Kolfs in KDE’s SVN:

  • trunk/KDE/kdegames/kolf: quite stable and shipping, home-grown 2D physics engine
  • trunk/playground/games/kolf-ng quite unstable, external 3D physics engine
  • trunk/playground/games/kolf2 mostly just a testcase at the moment, external 2D physics engine

Now probably you want to build and try Kolf 2 (read: the testcase which will become Kolf 2 at some point). This is quite tricky, because the CMake-based Box2D has not yet had a stable release, so you’ll have to checkout the development version from this SVN url. Even worse, you have to apply this patch against the SVN checkout to have Kolf 2 find the installed Box2D library. Even worse, you’ll need to apply the following patch against the Kolf 2 checkout to have the test-case work properly. (I did not commit this because I usually forget to remove such stuff again.)

diff --git a/kolf2/base/scene.cpp b/kolf2/base/scene.cpp
index db7fa83..c68ce8d 100644
--- a/kolf2/base/scene.cpp
+++ b/kolf2/base/scene.cpp
@@ -30,7 +30,7 @@ static const int MillisecondsPerStep = 1000.0 * SecondsPerStep;

 Kolf::Scene::Scene(QObject* parent)
        : QGraphicsScene(parent)
-       , m_world(new b2World(b2Vec2(0, 0), true)) //parameters: no gravity, objects are allowed to sleep
+       , m_world(new b2World(b2Vec2(0, -100), true)) //parameters: no gravity, objects are allowed to sleep
        , m_objectFactory(new Kolf::ObjectFactory(this, m_world))
        , m_simulationTimerId(startTimer(MillisecondsPerStep))

And even then, you will only see two colliding rectangles. I hope to get the gameplay and course loading working as in Kolf-NG by the end of next week (modulo the terrain). Still, the door is open to great features such as Kolf 1 compatibility.


5 Responses to “Kolf: 1. Box2D, 2. ???, 3. Profit!!!”

  1. johnflux Says:

    you can use a 3d engone and just set z=0

    • Stefan Majewsky Says:

      Yes, of course, but using a real 2D engine makes stuff simpler and cleaner and improves performance. Besides that, ODE integration has always had some hard-to-find problems, while Box2D seems to Just Work.

  2. saLOUt Says:

    Cool. Crayon Physics and Numpty Physics (http://numptyphysics.garage.maemo.org/) were build on top of box2d, too. 😉

  3. Other good 2D engines are:

    * Chipmunk (http://code.google.com/p/chipmunk-physics/) which also uses CMake. I’ve contributed patches and it’s got some really nice features. It is C though but I think there’s a C++ wrapper. Simple enough to write your own anyway.

    * Stepcore – I’m unsure if any integration could work but from what I’ve heard it should be usable.

  4. […] working today to add a putter interface to Kolf 2. (Attention: There are three Kolfs at the moment. I did previously explain why.) After fixing one or two crashes and fighting against Qt’s partly abstruse event forwarding […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s