Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
Last active March 25, 2024 22:30
Show Gist options
  • Save h4k1m0u/04f10b496fee322f0e9ac1b98d9587bd to your computer and use it in GitHub Desktop.
Save h4k1m0u/04f10b496fee322f0e9ac1b98d9587bd to your computer and use it in GitHub Desktop.
Notions in Box2D-2.4 taken from its HelloWorld example

From the hello world example:

  • Coordinate system: y-axis points upwards and gravity downwards.
  • Units: meters, kilograms, and seconds
  • Area density: mass / area, and expressed in kg/m^2
  • Fixture: Used to attach a shape to the body
  • Shape: its coords are local to the body
  • Static body: mass ~> oo (stored = 0 in box2d)
  • Dynamic body: moves in response to forces
  • FPS: 60 frames/sec = freq => delta_t = 1/60 sec
  • Constraint solver: Iterates over constraints a number of times (two phases: velocity and position phases)
  • Solver iteration: Passes over all constraints
  • World: leaves scope (or deleted) => its children (bodies, fixtures...) are freed
  • Meter to pixel: As per this blog post, take main character's height as a reference to convert between renderer's units (px) to box2D's (meter).

From the testbed example examples:

  • b2Draw class: Used to draw physics entities for debugging purposes
  • b2ContactListener class: Used to handle collision events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment