+}
+
+}
+
+void World::Update(Entity &entity, float dt) {
+ EntityState state(entity.GetState());
+
+ EntityDerivative a(CalculateStep(entity, state, 0.0f, EntityDerivative()));
+ EntityDerivative b(CalculateStep(entity, state, dt * 0.5f, a));
+ EntityDerivative c(CalculateStep(entity, state, dt * 0.5f, b));
+ EntityDerivative d(CalculateStep(entity, state, dt, c));
+
+ EntityDerivative f;
+ constexpr float sixth = 1.0f / 6.0f;
+ f.position = sixth * ((a.position + 2.0f * (b.position + c.position)) + d.position);
+ f.velocity = sixth * ((a.velocity + 2.0f * (b.velocity + c.velocity)) + d.velocity);
+ f.orient = sixth * ((a.orient + 2.0f * (b.orient + c.orient)) + d.orient);
+
+ state.block_pos += f.position * dt;
+ state.velocity += f.velocity * dt;
+ state.orient = delta_rot(f.orient, dt) * state.orient;
+ state.AdjustPosition();
+
+ entity.SetState(state);
+}
+
+EntityDerivative World::CalculateStep(
+ const Entity &entity,
+ const EntityState &cur,
+ float dt,
+ const EntityDerivative &delta
+) {
+ EntityState next(cur);
+ next.block_pos += delta.position * dt;
+ next.velocity += delta.velocity * dt;
+ next.orient = delta_rot(cur.ang_vel, dt) * cur.orient;
+ next.AdjustPosition();
+
+ EntityDerivative out;
+ out.position = next.velocity;
+ out.velocity = CalculateForce(entity, next); // by mass = 1kg
+ return out;
+}
+
+glm::vec3 World::CalculateForce(
+ const Entity &entity,
+ const EntityState &state
+) {
+ return ControlForce(entity, state) + CollisionForce(entity, state) + Gravity(entity, state);
+}
+
+glm::vec3 World::ControlForce(
+ const Entity &entity,
+ const EntityState &state
+) {
+ constexpr float k = 10.0f; // spring constant
+ constexpr float b = 10.0f; // damper constant
+ const glm::vec3 x(-entity.TargetVelocity()); // endpoint displacement from equilibrium, by 1s, in m
+ const glm::vec3 v(state.velocity); // relative velocity between endpoints in m/s
+ return ((-k) * x) - (b * v); // times 1kg/s, in kg*m/s²
+}
+
+namespace {
+
+std::vector<WorldCollision> col;
+
+}
+
+glm::vec3 World::CollisionForce(
+ const Entity &entity,
+ const EntityState &state
+) {
+ col.clear();
+ if (entity.WorldCollidable() && Intersection(entity, state, col)) {
+ // determine displacement for each cardinal axis and move entity accordingly
+ glm::vec3 min_pen(0.0f);
+ glm::vec3 max_pen(0.0f);
+ for (const WorldCollision &c : col) {
+ if (!c.Blocks()) continue;
+ glm::vec3 local_pen(c.normal * c.depth);
+ // swap if neccessary (normal may point away from the entity)
+ if (dot(c.normal, state.RelativePosition(c.ChunkPos()) - c.BlockCoords()) > 0) {
+ local_pen *= -1;