Show Xojo: ImpulseEngine, a simple open source 2D physics engine

I’m happy to announce the public release of ImpulseEngine, an open source rigid body 2D physics engine written in 100% native Xojo code. Based on Randy Gaul’s ImpulseEngine.

GitHub repo.

The engine is complete and functional but is probably best used to learn about 2D vector physics rather than in an actual game as it is missing some important features such as joints. I’m currently working on a second physics engine that will address some of ImpulseEngine’s shortfalls but I learned a lot creating this project.

The engine is written in 100% Xojo and has no external dependencies. It uses API 2.0 and therefore requires Xojo 2019 Release 2 to compile. It will not run on iOS due to this limitation.

Getting started is a simple as adding the ImpulseEngine module to your project. The project includes a simple demo application illustrating how to create bodies and add them to the simulation. I’ve tried to keep the engine’s API simple and have thoroughly documented the code.

[code]Using ImpulseEngine

// I’m assuming your viewport (e.g: a canvas control) is 640 x 480 pixels.

Var dt As Double = 1/60 // 60 FPS.
Var iterations As Integer = 5

// Create a new world.
Var w As New World(dt, iterations)

// Add a thin box to act as the ground.
Var ground As Body = w.AddBox(320, 471, 639, 8)
ground.IsStatic = True

// Add a circle to the simulation.
Var circ As Body = w.AddCircle(320, 0, 15)

// Add a polygon with some spin.
Var poly As Body = MyWorld.AddPolygon(150, 50, 0, 0, 30, -50, 60, -20, 75, 20, 40, 40)
poly.AngularVelocity = 0.55

// Call World.Update every dt seconds.
// Assume we have a Timer elsewhere with an interval of 1/fps that
// calls w.Update and then draws every body in the World in a canavs.
// See the demo app to see how this can be done.[/code]

Here’s a short YouTube video showing the demo: YouTube link.


That is really cool!

Makes me want to build my own version of Tetris :wink:

Well done Garry!