The first assignment of the Game Behaviour module in the final year of my course at the University of Derby was to develop a 2D Physics Sandbox using Box2D, allowing for the construction of a various modular, wheeled vehicles.
Other than Box2D, naturally, I used a number of other open source libraries in the development of my sandbox, DropCakes. These include the 2D graphics library SFML and aditional vector maths header RixMath.h, used for all rendering; the GUI library Gwen (GUI Without Extravagant Nonsense), used for all GUI elements; and finally, the XML parser library pugixml, used for scene serialization and de-serialization.
In addition to these libraries I developed a custom component engine, Crispis, based heavily on Coment, but with numerous modifications based on personal preference and goals. This was intended to allow for dynamic creation and removal of components in the editor/sandbox, which would allow the user to easily apply various behaviours to objects and configure them. Due to time constraints the only example of this at hand-in is the Motor Controller Component which allows for manual (keyboard) control of motored joints. Notable differences from Coment include:
- Processes (a.k.a systems) are sorted and executed based on priority values.
- Entities must be manually registered with processes
Here I will provide a brief overview of DropCakes’s features, omitting any instructional information, as this is included in the readme.txt provided with both source and executable distributions.
- Linear drag based upon an estimation of an object’s reference area.
- Angular drag based upon an estimate of an object’s width/radius.
- Fixed time step physics simulation decoupled from framerate (time delta is capped so that at <10 fps slowdown will occur in order to avoid the physics simulation going into a death spiral).
- Create static and dynamic Box2D physics bodies:
– Rectangles, Circles, Triangle-tessellated Polygons
- Edit limited properties of Box2D physics bodies after creation, such as restitution and friction.
- Create Box2D physics joints:
– Weld, Distance, Revolute, Prismatic, Pulley, Rope,Wheel
- Edit limited properties of Box2D physics joints after creation, including limits and motors.
- Delete Box2D physics bodies.
- Edit properties of the physics simulation including time step, linear and angular drag, air density, and gravity.
- Move objects within the simulation using the Physics Movement Cursor.
- Attach Crispis Entities and Components to Box2D bodies and joints for dynamic behaviour:
– Currently only the Motor Controller Component is supplied, which allows for binding keyboard inputs to any joint motor.
- Save and Load worlds via XML serialization:
– Implementation of Entity and Component serialization required a lot of workarounds, so enabling this for new components requires more work than it really should.
- Play, Pause, Resume, and Stop simulation:
– World is automatically serialized on play and reset to this state on stop, so you can easily test out devices without risking breaking them.
- Zoomable, translatable camera.
- Recursive, infinite grid rendering.
- Triangle tessellation for the Polygon tool:
– Implementation is imperfect and failed tessellations of highly irregular shapes will fail to spawn without warning.