O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – simulating physics with Box2D

Let's encapsulate Box2D simulation in a dedicated service first:

  1. First, create jni/PhysicsObject.hpp and insert Box2D main include file. Class PhysicsObject exposes a location and a collision flag publicly. It holds various Box2D properties defining a physical entity:
    • A reusable body definition to define how to simulate a body (static, with rotations).
    • A body to represent a body instance in the simulated world.
    • A shape to detect collisions. Here use a circle shape.
    • A fixture to bind a shape to a body and define a few physics properties.

    The class PhysicsObject is set up with initialize() and refreshed with update() after each simulation step. Method createTarget() will help us create a joint for the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required