April 2015
Beginner to intermediate
494 pages
10h 26m
English
Let's rewrite the DroidBlaster physics engine with Box2D with the following steps:
jni/PhysicsManager.hpp header and insert the Box2D include file.Define a constant PHYSICS_SCALE to convert the body position from physics to game coordinates. Indeed, Box2D uses its own scale for a better precision.
Then, replace PhysicsBody with a new structure, PhysicsCollision, that will indicate which bodies entered in collision, as shown in the following:
#ifndef PACKT_PHYSICSMANAGER_HPP #define PACKT_PHYSICSMANAGER_HPP #include "GraphicsManager.hpp" #include "TimeManager.hpp" #include "Types.hpp" #include <Box2D/Box2D.h> #include <vector> #define PHYSICS_SCALE 32.0f struct PhysicsCollision { bool collide; ...