X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=925046cbd0c9f4a2559822b34821498d362c2f9a;hb=b9462143d9b2fd1f54aa3b4ec32eecb62c01615f;hp=ee5bf02c191ffcf3be293d0a4acda9b31289f751;hpb=d122d3e445d64f7d710c1cfaf285ff01bbe955b9;p=blank.git diff --git a/src/world/world.cpp b/src/world/world.cpp index ee5bf02..925046c 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -80,7 +80,7 @@ void Entity::UnsetController() noexcept { glm::vec3 Entity::ControlForce(const EntityState &s) const noexcept { if (HasController()) { - return GetController().ControlForce(s); + return GetController().ControlForce(*this, s); } else { return -s.velocity; } @@ -153,6 +153,29 @@ EntityController::~EntityController() { } +bool EntityController::MaxOutForce( + glm::vec3 &out, + const glm::vec3 &add, + float max +) noexcept { + if (iszero(add) || any(isnan(add))) { + return false; + } + float current = iszero(out) ? 0.0f : length(out); + float remain = max - current; + if (remain <= 0.0f) { + return true; + } + float additional = length(add); + if (additional > remain) { + out += normalize(add) * remain; + return true; + } else { + out += add; + return false; + } +} + EntityState::EntityState() : chunk_pos(0)