A world is a bag of bodies with gravity, stepped forward together. Today you build the World and its first step, integrating every body under gravity.
Build a World that holds bodies and gravity and integrates every dynamic body one step.
The World is the top-level object a user of the engine actually holds: a list of
bodies and a global gravity. Its Step advances the whole simulation by one
fixed dt, and today that means the integration loop from chapter two, now run over
every body. Applying gravity as a weight force mass * gravity means the mass
cancels when you divide by it to get acceleration, so every dynamic body falls at the
same rate gravity - which is why a feather and an anvil drop together in a vacuum.
Static bodies are skipped entirely, so the ground stays put while everything else
falls onto it. This is the walking skeleton of the engine: from here, each remaining
lesson slots one more stage into Step - finding contacts, then resolving them - until
a full frame runs. Right now stepping the world just drops its bodies, but that is
already a runnable simulation you can print frame by frame.
type World struct {Bodies []*BodyGravity Vec2}func (w *World) Step(dt float64) {for _, b := range w.Bodies {if b.InvMass == 0 { continue } // statics never integrateb.ApplyForce(Scale(w.Gravity, b.Mass)) // weight = m * g, so accel = gb.Acceleration = b.accelerationFromForce()b.Integrate(dt)b.ClearForces()}}