ABPE, the Physics Engine!

ABPE is a true 2d Newton’s Physics Engine for Xojo and RealBasic! It is the translation of the latest stable (a045) Actionscript Physics Engine engine written by Alec Cove. It uses GDIPlus on Windows and Quartz 2D on Mac to get nice and fast graphics. It’s not an exact translation as some adaptions needed to be done to let it work in Xojo/Realbasic. (They were Actionscript specific). I also added the possiblity to add a texture to the elements.

Some Features:

  • collision detection (Circle-Circle, Rect-Rect, Circle-Rect and Rect-Circle) between groups and within groups
  • particles with elasticity, friction, traction, etc…
  • Constraints with stiffness that connect particles
  • groups of particles and constraints that can interact with each other
  • self-buildable forces (like gravity, push, …)
  • vector functions
  • …

More info and the full source code for Windows and OSX on my blog:

Let’s make some games!



The link for RB2007R4 (Windows compatible only): is incorrect

The link is

While it should be

Brilliant! (standing ovation)


Thanks @Dirk Cleenwerck for the report. Should be ok now :slight_smile:

nuff said :slight_smile:

Pretty cool! :slight_smile:
Now lets make an angry bird clone. :wink:

ABPE is really amazing. I played with it all weekend, the hanging bridge is my favourite. I don’t understand though how constraints, particles, collections, composites and groups all fit together, I mean when should I subclass Composite vs Group or how to connect them and set their parameters for intended effects. Is there a link that gives a good overview of this?

The first thing I did with ABPE is a little tweak to make the window resizeable which looks nice fullscreen but noticeably slowed down. So then I did a bigger tweak to use OpenGL which is relatively unaffected by size and it runs fullscreen easy. The rendering isn’t 1:1 with before, OpenGL doesn’t really have line widths or circles and the anti-aliasing isn’t as smooth in places.

Then I tried to figure out the collection/composite/group/particle/constraint system by implementing that RobotDemo of a Jansen Walker. But I got it done mostly through pattern matching and didn’t learning those things:( The robot has a little slide on flat ground and a couple times it slipped inside of the block pyramid, not sure if that’s the demo or stuff I missed.

Here’s the project so far with gl and the robot. To factor in gl, in the framework only ABPEEngine and ABPESprite had to be modified and then just the CarDemo Window. Not sure how cross platform my code is, especially sprite image loading and alpha, for some reason I had to do things differently to get alpha working.

And here’s the unmodified ABPE with RobotDemo dropped in. Required just a little refactoring of the window but a couple features had to be left out. The view is supposed to pan with the robots position but I don’t know how to set that, it’s commented out in RobotDemo.Timer1.Action() if that’s the right place to fix it. And ABPEEngine doesn’t have DrawTriangle(), 2 calls to that are commented out in RLeg.paint(). Actually, it should be DrawFillTriangle to follow the nomenclature.

Robot controls
press Left to toggle power
Right to change direction
Up to hide/show some legs

@Will Shank Waw man, this look really great! I tested it on my Windows 7 machine and except commenting out GDIPlus statements in the open/close of the app object it runs very well. I’m a novice on OpenGL so it’s great to see the the Draw functions converted. The only thing that not seams to work is the drawimage in the car demo. May be a Windows thing…

Would you mind if I put this up on my blog later (stating you’re name of course)? I’m sure we’ll see a lot of happy people :slight_smile:

The APE engine (where it is based on) is not very well documented indeed. I will try and write a help for it when I find some time. In the meantime, you can download the original help from the ActionScript engine. It may explain some more. http://gorgeousapps.com/APEOriginalHelp.zip

The difference is in the collision detection: (from this help)

The Composite class can contain Particles, and Constraints. Composites can be added to a parent Group, along with Particles and Constraints. Members of a Composite are not checked for collision with one another, internally.

The Group class can contain Particles, Constraints, and Composites. Groups can be assigned to be checked for collision with other Groups or internally.

Truly great update Will! I love it!


@Will Shank The problem of the DrawImage is solved. It is because when it runs in debug, it can’t find the file. I changed the code of LoadImage to:

  dim f as FolderItem = GetFolderItem(ImageFileName)
  if f <> nil and f.Exists then
    dim p As Picture = Picture.Open(f)
    if p <> nil then
      tex = new EZTexture2D(p, p.Mask, true)
    Dim CurrPath as string
    CurrPath = GetFolderItem("").Parent.NativePath
    if Right(CurrPath, 1) <> "\" then CurrPath = CurrPath+ "\"
    f = GetFolderItem(CurrPath + ImageFileName)
    if f <> nil and f.Exists then
      dim p As Picture = Picture.Open(f)
      if p <> nil then
        tex = new EZTexture2D(p, p.Mask, true)
    end if


Usually I go “ow” :stuck_out_tongue:

I’ve heard that GDI+ should always be on and changed it without really knowing what I’m doing. Maybe it’ll work with GDI+ off? or not.

By all means. And fix it up however you want.

Looking forward to it :slight_smile:

For me not really, it’s too fragmented. Your selected clips do though, I just don’t have the patience to sift through that API and find those enlightening pieces. Except I am now. Branching off that Composite and Group info I’ve been stitching the big picture, very slowly.

Just started learning how this works, a couple things found so far…

A Group is a set of Particle and Collection items. Setting the Groups CollideInternal property true will cause it’s items to collide amongst themselves, set false and they’ll slide through each other.

Groups can be linked to collide between each other by calling addCollidable on one with the other (not sure if the order matters). If groups aren’t linked to collide then their items won’t interact.

Here’s the simple example I’ve been working out to grasp this stuff. It adds 2 bouncing balls to CarDemo that collide with the Surfaces, Rotator and Car, but not the Capsule or Bridge. Add this code to the bottom of CarDemo.Open()

[code] //create some balls with position, size, mass, friction… and drawing style
dim ball1 As new ABPECircleParticle(300, 10, 25, false, 0.5, 0.45, 0.02)
ball1.SetStyle(1, &cFFFF44, 255, &cAA7722, 255)

dim ball2 As new ABPECircleParticle(330, 10, 15, false, 0.5, 0.5, 0.02)
ball2.SetStyle(1, &cFFFFFF, 255, &c808080, 255)

//create a new group and add the balls
dim ballGroup As new ABPEGroup(true) //“true” is for the CollideInternal setting

//link with the other groups to collide against

//add the completed group to the engine

“b a l l s” is a banned word :stuck_out_tongue:

balls works for me - just put your expletives in a code block.

Can you post a picture or describe how the line is going through? Haven’t heard of this before, not sure what it could be.

That’s what I tried to show above by adding 2 circles to CarDemo and setting them to collide with each other and with a few other groups. Do you have something else in mind for collision detection?

No need to swear @dave duke :slight_smile: Can the ABPEEngine.RemoveGroup() function not solve your problem? Otherwise, I’ll check in the morning if I can do something about it.