This project demonstrates that it is possible to run a 2D Physics engine made from scratch in Ada on a STM32, with some very cool results !
Basically, the project is split in two independent parts:
- The Physics engine, with its API, available for you to download and use for your own projects: https://github.com/Kidev/AdaPhysics2D It is of course open, and a tutorial to easily use it is available on the Github page of the engine. With it, you will be able to create awesome physics projects (like games) really quickly, efficiently (remember that it runs smoothly on a STM32), and without any actual knowledge in physics !
- The STM32 wrapper, made with the help of Adacore's Ada_Drivers_Library, that provides an easy and fun way to discover all the features of the engine: https://github.com/Kidev/DemoAdaPhysics2D
So, what are the physics engine features ? Well, it does :
- Multiple 2D worlds, with layering
- Real time collision detection and impulse resolution
- Multiple entities (Circles and Rectangles) with custom initial position, speed, gravity and material (wood, steel...)
- Multiple environments with custom area and material (water, air...)
- Custom forces impulsions
- Solid (static and dynamic) friction: objects don't keep sliding forever, and it takes work to make them move when they are still
- Liquid friction: the environment affects objects speed
- Archimedes's principle: objects float in environments with a higher density
- Ropes and springs to link entities: to make pendulums and use springs !
- And an easy to use open source API !
The STM32 makes it very fun to play with, and you can shake the board to affect the entities with the gyroscope ! But the menus can be difficult to understand. So, to make it easier:
When you load the app you are greeted with a menu. Chose "START". You are now facing one world. By pressing the blue button, you can change the current mode. The modes rotate. Here are the modes:
- The disabled mode (no led), where you cannot interact with the touch screen
- The create circle mode (green led), where pressing the screen will spawn a Circle entity in the word
- The create rectangle mode (green led), same as previous one but for a Rectangle
- The edit mode (red led), where you can change the material of the entity (solid or environment) you are touching: turn water into air !
- The link mode (green and red led), where pressing one entity and then another will link them together with a rope or a spring !
- The menu mode (no led), where you can disable or enable gravity, change the material of the entity you're creating in the create mode ("C:"), change the material of the edit mode ("E:") and change the type of the rope ("L:" for rope or spring)
- And then, back to the disabled mode !