Qt + Box2D is easy!

Qt SoftwareBox2D is an Open Source rigid body 2D physics engine for C++. It’s currently (2.0.1) released under the MIT license, which is quite permissive. Box2D is used by, among other things, Gluon (http://gluon.tuxfamily.org/), which is a game library from KDE in-the-making.

Integrating Box2D into your Qt application is quite easy, and this blog shows you how to get started. First of all:

  • Step 1: Download Box2D from Google Code: http://code.google.com/p/box2d/
  • Step 2: Build it (I had to insert a few #include <cstring> to get it to build)
  • Step 3: Build and try the test bed application: Box2D/Examples/TestBed/
  • Step 4: Read the manual: http://www.box2d.org/manual.html
  • Step 5: Continue reading this blog to hook up the two frameworks…

The library doesn’t seem to install, so I just compiled it in-source and used it directly.

What I found during my approx 2 hour study today was that Box2D manages a world with bodies, similar to how QGraphicsScene manages items. In short, you create a world object and populate it with elements. Some bodies are static, like the ground, and some dynamic, like a bouncing ball. You can define joints, masses, friction, and other parameters, define a gravity vector, and then start simulating. Box2D doesn’t require a graphics system – any scene graph with elements that you can move and rotate should do fine. Graphics View works quite well. I’ve based this code on the provided “Hello World” example that comes with Box2D.

The world object defines the bounds of the coordinate system and the gravity vector. It feels very similar to QGraphicsScene. The bounds are, according to the docs, not enforced, but I got many run-time aborts when items are outside these bounds so you better make the world large enough to cover all your items. Continue reading

Related Posts

Ubuntu 12.10 installation and disk partitioning guide Alternate titles: How to create partitions in Ubuntu 12.10 manually; Manual disk partitioning guide for Ubuntu 12.10. Ubiquity, the graphical insta...
How to install applications on and update Linpus Lite Desktop 1.7 Linpus Lite Desktop 1.7 is a desktop-centric Linux distribution I recently reviewed (see Linpus Lite Desktop 1.7 review. It uses a heavily-modifie...
Triple-boot Windows 7 and 8 and Ubuntu 14.04 on a PC with UEFI firmware This tutorial provides a step-by-step guide on how to triple-boot Windows 7 and 8 and Ubuntu 14.04 on a computer with UEFI firmware and on a single ha...
Spice up Ubuntu 10.10 desktop with Cairo-Dock Ubuntu 10.10, the latest edition of the popular Linux distribution, which was just reviewed here, ships with the same blank desktop that has come to i...
10 tips for a 10x performance boost for your website or Web app How fast does a website need to be? For each second a page takes to load, about 4% of users abandon it. Top e-commerce sites offer a time to first int...
Dual-boot Ubuntu 12.04 and Windows 7 on a computer with 2 hard drives This is the second article on dual-booting Ubuntu Desktop 12.04 with Windows 7. But while the first one, how to dual-boot Ubuntu 12.04 and Windows 7, ...

We Recommend These Vendors and Free Offers

ContainerizeThis 2016 is a free, 2-day conference for all things containers and big data. Featured, will be presentations and free, hands-on workshops. Learn more at ContainerizeThis.com

Launch an SSD VPS in Europe, USA, Asia & Australia on Vultr's KVM-based Cloud platform starting at $5:00/month (15 GB SSD, 768 MB of RAM).

Deploy an SSD Cloud server in 55 seconds on DigitalOcean. Built for developers and starting at $5:00/month (20 GB SSD, 512 MB of RAM).

Want to become an expert ethical hacker and penetration tester? Request your free video training course of Online Penetration Testing and Ethical Hacking

Whether you're new to Linux or are a Linux guru, you can learn a lot more about the Linux kernel by requesting your free ebook of Linux Kernel In A Nutshell.


  1. this is so LOL. Delete or redo right please

  2. Pingback: Links 27/2/2010: Kolivas’ New Patches, Predictions for Sub-notebooks with ARM | Boycott Novell

Leave a Comment

Your email address will not be published. Required fields are marked *