Box2D Physics

From ENIGMA
Revision as of 15:08, 1 January 2021 by RobertBColton (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This article is an overview of using the Box2D physics extension which provides you with an advanced comprehensive 2D physics API, for information on GameMaker: Studio compatibility please see Studio Physics.

Official Box2D Logo

Setting up Box2D

Note: Box2D is already compiled and included in versions of ENIGMA with the Windows patch, such as the portable ZIP, and nothing more is required than for you to simply enable the extension under Build->Settings.

Note: If you used the Linux install script Box2D 2.3.0 will already be installed and nothing more is required than for you to simply enable the extension under Build->Settings.

For Linux the build commands are:

git clone https://github.com/erincatto/Box2D
cd Box2D/Box2D/Build
cmake -DBOX2D_INSTALL=ON -DBOX2D_BUILD_SHARED=ON ..
make
make install	

You might want to add -DCMAKE_INSTALL_PREFIX=/opt/Box2D or similar to the cmake call to change the installation location. make install might need sudo.
3) Run sudo ldconfig, it won't work until you do ldconfig deferred processing
4) You are good to go!
If you are on Windows you can just build and place the static library under enigma-dev/ENIGMASystem/additional/windows/
Also do not forget to enable the extension for your game under Build->Settings in LateralGM.

Simulating the world of Box2D

An example Box2D game is hosted on the EDC here.

Worlds

Worlds are what hold and contain the physics simulation in Box2D.

Bodies

In physics, a physical body or physical object (sometimes simply called a body or object) is a collection of masses, taken to be one. For example, a football can be considered an object but the ball also consists of many particles (pieces of matter). Physics bodies in Box2D can be compromised of multiple fixtures, for instance a bicycle has two wheel fixtures and the frame fixture.

Shapes

A 2D geometrical object, such as a circle or polygon. They are generally made up of points and can create several different types of shapes depending on what they are needed for. They also provide helper functions to easily create basic shapes. A limitation of the Box2D physics engine is that all shapes must be convex and in counter clockwise order, otherwise you may experience a crash as the behaviour is unexpected.

Fixtures

A fixture binds a shape to a body and adds material properties such as density, friction, and restitution.

Joints

This is a constraint used to hold two or more bodies together. Box2D supports several joint types: revolute, prismatic, distance, and more. Some joints may have limits and motors.

Forces

Forces appear all throughout nature, ever since the iconic picture of Isaac Newton being hit by a falling apple. The extension provides useful helper functions for applying forces to bodies or througout the room including functions for radial, centripetal, and centrifugal forces not provided by Box2D itself.

See Also