[Demo]Physix - A simple physics toy



This is essentially just a port of some code I wrote for the Arduboy demonstrating how my fixed points library can be used to do decent physics simulations that would otherwise be difficult using float.

Github Repo

Releases (with .bin files)

.webm version


More screencaps


DPad - move the filled in square
B + Left - toggle the text info
B + Down - toggle gravity (on/off)
B + Up - toggle gravity direction (up/down)


I struggled a bit with figuring out waht the Pokitto equivalent of certain Arduboy functions were.

E.g. not having to call Display::clear() or Display::update() and Buttons::pressed behaving differently to what I was expecting and some of the functions documented in the doxygen aparently not existing (e.g. Buttons::bHeld()).

Also drawRect and fillRect don’t appear to be functioning properly in HiRes mode for some reason, hence the .bin is in lowres mode.
(I’ll file a bug report tomorrow.)

My mistake. The bug was with my code.
I forgot that 220 and 176 end up being negative when cast to int8_t.

Once I’d figured out what was what though, it’s not too dissimilar from the original.

Later on I’m going to trying increasing the size of the fixed points to see if the ARM chip gets on better with values closer to its native word size.


@sbmrgd has informed me that Physix wasn’t compiling for PokittoSim due to some issues with random,
so I’ve gone through and made sure the v0.1.1 release compiles for PokittoSim.

(I’ve also removed the debug counter that I forgot to remove before.)

Also fixed the highres issue for v0.1.2, which should be the last version for a while.


Any pics or even better, a video?


I don’t have anything set up for recording on computer and it’s a bit too dark for my video camera,
but I can dump some screencaps from the simulator.


Isn’t there a build in feature in the simulator to record a video? I have not tried it myself.


There might be, but as far as I’m aware there isn’t.


#define SCREENCAPTURE   0      // nonzero = the nth frame will be written to disk
#define MAKE_GIF        0       // nonzero = make a gif using ImageMagick Convert


I’ve got to run off, but I’ll come back and sort one later.

(And then maybe make a thread called “How to capture a gif using the simulator”.)


I’ve added the gif.

I tweaked the code to not dump the stuff in my C drive though, and then assembled the frames via command line instead of letting the simulator do it though.

It’s given me some ideas for improving that aspect of the simulator though,
e.g. dumping the files relative to the executable.


Looks nice! Any idea of the performance of the physics engine? I know they can be pretty heavy (pun intended :wink: ).


Honestly, I have no idea.
The Arduboy version that it’s adapted from runs fine and that’s got an ATMega32u4.

But this demo doesn’t really push the boat out in regards to physics.
There’s no collision testing (other than cheap hacks to stop the blocks falling offscreen) or collision resolution, which are usually two of the more expensive things.

Maybe I’ll come back at a later point to add collisions and then see how far it can be pushed.

I made a PR for ‘putting the files near the executable’ like I mentioned earlier:

and raised an issue for my other idea:


@Pharap can you add FixedPoints library to PokittoLib?
Right now there’s a FixMath lib but maybe yours can fit better our needs.

Why not integrate some already existent library to do this? Maybe https://github.com/ginsweater/gif-h ? In that way it will be consistent on all develop platform. We could bind a key (F8) to toogle GIF recording on the output build directory.

P.S. Nice demo BTW


I was originally going to create a non-Arduino version designed to work in any C++11 environment,
but it got put on the back-burner.

If I put it into the library, I’d have trouble updating it, and there might be issues with breaking changes that I’ve got planned for FixedPoints.
(I don’t know if milestones are publicly visible, but here’s the 2.0.0 milestone.)

So basically: maybe at some point, but not yet, and if I can find the time to start work on the general C++ edition, that version should work for Pokitto anyway.

Perhaps. The two reasons I suggested a script rather than a library are because a script would be less effort and it would allow for better customisation.

If we used that library you linked to, I’d recommend rewriting some of it so it uses new and delete instead of malloc and free and doesn’t use deprecated headers (i.e. make it use #include <cstdlib> instead of #include <stdlib.h>).

Though that particular library is a very minimalist approach and doesn’t provide the range of options that doing commandline ffmpeg would allow.

But it gets points for using Allman style braces.