X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=d2b05d66850e96923704bfd262335af5cc464832;hb=e4a1425dccd0ba9b106e415dd02809f4308a85ee;hp=dfcf7217f99372d1ea4ada491d55ffa409ec2336;hpb=ee3fee8a4bf3e77b17c940fb8f3daf30ede46cce;p=blank.git diff --git a/src/world/world.cpp b/src/world/world.cpp index dfcf721..d2b05d6 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -605,8 +605,8 @@ void World::Update(Entity &entity, float dt) { 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.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); state.pos.block += f.position * dt; state.velocity += f.velocity * dt; @@ -725,7 +725,22 @@ glm::vec3 World::Gravity( const Entity &entity, const EntityState &state ) { - return glm::vec3(0.0f); + glm::vec3 force(0.0f); + ExactLocation::Coarse begin(state.pos.chunk - 1); + ExactLocation::Coarse end(state.pos.chunk + 2); + + for (ExactLocation::Coarse pos(begin); pos.z < end.z; ++pos.z) { + for (pos.y = begin.y; pos.y < end.y; ++pos.y) { + for (pos.x = begin.x; pos.x < end.x; ++pos.x) { + Chunk *chunk = chunks.Get(pos); + if (chunk) { + force += chunk->GravityAt(state.pos); + } + } + } + } + + return force; } World::EntityHandle World::RemoveEntity(EntityHandle &eh) {