Using physics rules in your game
The first step to have physics in the game is to have the environment ready so that proper calculations can be applied to the bodies, and the physics simulation can work on them.
Getting ready
To work through this recipe, you will need a machine running Windows and Visual Studio. No other prerequisites are required.
How to do it…
In this recipe, we will see how easy it is to add physics rules to our game:
First, set up all the objects in the game scene.
Give them properties so that they have vector points and velocities.
Assign bounding boxes or bounding circles, depending on the shape of the object.
Apply forces on each of the bodies.
Detect collisions between them based on the shape.
Solve for the constraints.
Output the result.
Take a look at the following code snippet:
#include <Box2D/Collision/b2Collision.h> #include <Box2D/Collision/Shapes/b2CircleShape.h> #include <Box2D/Collision/Shapes/b2PolygonShape.h> void b2CollideCircles( b2Manifold*...