cluttermm and playing with clutter-box2d


There are now C++ bindings for the various clutter-0.8 libraries. That’s cluttermm-0.8, clutter-gtkmm-0.8, and clutter-cairomm-0.8. The tarball versions are 0.7.x because they are not ABI-stable yet. Armin Burgmeier did most of the work for Openismus to update cluttermm for clutter-0.8 and make it mostly complete.

I’d still like to find the time to do a C++ version of my Clutter tutorial.


I really wanted to look at clutter-box2d. It’s the clutter-with-simple-2D-physics thing created by Øyvind KolÃ¥s. His Moblin Playground Clutter prototype (watch the screencast) shows how it might be used. For instance, it makes it easier to implement the spinning circular menus you see at the left and right, and to implement the photo “table”. Since I wrote the clutter tutorial, I’ve thought we need abstractions such as this.

So I wrapped it as clutter-box2dmm and made C++ versions of its examples to get familiar with it.

clutter-box2d provides a ClutterBox2D (or Clutter::Box2D::Box2D in C++) container actor, which has child properties for its child actors. For instance, you can say whether the actor should be static (not moving) or dynamic (moving and colliding according to some simple physics), and you can say whether the actor should be manipulatable by pushing it around with the mouse. You can also specify its velocity. These are explicit methods on the Box2D class in the C++ binding.

You can then start the simulation on the ClutterBox2D. By default there is normal gravity (a bug, I think), which makes examples fun. The examples create a static box around the edges of the ClutterStage so the actors don’t fall out of it.

You can also specify some joints to connect actors in certain ways, such as a distance joint to put an invisible rod between them, or a revolute joint, as used to link the sections in the chain example. The joints are a bit difficult to understand.

This is all useful apart from some minor bugs that seem fixable, maybe together with the Box2D project that clutter-box2d uses. (Can’t stop damping and Can’t stop rotation.) It would be even more useful if applications could respond to collisions between objects and objects arriving at locations, which is apparently also doable.

However, I think clutter-box2d provides only some of the abstractions that I’d like. I particularly still miss the ability to simply define a rail and put an actor on it so its motion is restricted to that path. The actor would then be moved programmatically (maybe just by specifying an end point to reach) or by the user. clutter-box2d could do that by defining a rail and some runners, but it’s not a high level concept, and it’s probably not efficient.

I’d also like the idea of actors falling into locations as you move them, like those ball bearing maze games, and maybe it would be useful to have some ability to connect actors by elastic, and to let them bounce and compress.