X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fai%2Fai.cpp;h=4b76856ea9664db0bb5dc17681155bfe501090be;hb=f5de855fbd4bf5b0df1cad950cbe9069e41369ca;hp=c47b4d3893de5a0483b86033ef16ad3f817f9644;hpb=0d580658b896dfec07466c31ae4847455724ee95;p=blank.git diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index c47b4d3..4b76856 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -4,7 +4,8 @@ #include "IdleState.hpp" #include "RoamState.hpp" -#include "../model/geometry.hpp" +#include "../geometry/distance.hpp" +#include "../geometry/rotation.hpp" #include "../rand/GaloisLFSR.hpp" #include "../world/Entity.hpp" #include "../world/World.hpp" @@ -83,7 +84,7 @@ void AIController::Update(Entity &e, float dt) { // our box is oriented for -Z velocity obstacle_transform = glm::mat4(find_rotation(glm::vec3(0.0f, 0.0f, -1.0f), e.Heading())); // and positioned relative to the entity's chunk - obstacle_transform[3] = glm::vec4(e.GetState().block_pos, 1.0f); + obstacle_transform[3] = glm::vec4(e.GetState().pos.block, 1.0f); } if (wandering) { @@ -168,7 +169,7 @@ Player *AIController::ClosestVisiblePlayer(const Entity &e) noexcept { // LOS test, assumes all entities are see-through WorldCollision col; - if (world.Intersection(aim, glm::mat4(1.0f), reference, col) && col.depth < dist) { + if (world.Intersection(aim, reference, col) && col.depth < dist) { continue; } @@ -188,7 +189,7 @@ bool AIController::LineOfSight(const Entity &from, const Entity &to) const noexc return false; } WorldCollision col; - if (world.Intersection(aim, glm::mat4(1.0f), reference, col) && col.depth < dist) { + if (world.Intersection(aim, reference, col) && col.depth < dist) { return false; } return true; @@ -280,7 +281,7 @@ glm::vec3 AIController::GetObstacleAvoidanceForce(const Entity &e, const EntityS for (WorldCollision &c : col) { // diff points from block to state glm::vec3 diff = state.RelativePosition(c.ChunkPos()) - c.BlockCoords(); - float dist = length_squared(diff); + float dist = length2(diff); if (dist < distance) { nearest = &c; difference = diff; @@ -296,7 +297,7 @@ glm::vec3 AIController::GetObstacleAvoidanceForce(const Entity &e, const EntityS // point on the "velocity ray" closest to obstacle float to_go = dot(difference, e.Heading()); // point is our future position if we keep going our way - glm::vec3 point(e.GetState().block_pos + e.Heading() * to_go); + glm::vec3 point(e.GetState().pos.block + e.Heading() * to_go); // now steer away in the direction of (point - block) // with a magniture proportional to speed/distance return normalize(point - nearest->BlockCoords()) * (e.Speed() / std::sqrt(distance)); @@ -428,7 +429,7 @@ glm::vec3 AIController::GetEvadeForce(const Entity &, const EntityState &state) glm::vec3 cur_diff(state.Diff(GetEvadeTarget().GetState())); float time_estimate = length(cur_diff) / evade_speed; EntityState pred_state(GetEvadeTarget().GetState()); - pred_state.block_pos += pred_state.velocity * time_estimate; + pred_state.pos.block += pred_state.velocity * time_estimate; return Flee(state, pred_state, evade_speed, 2.0f); } @@ -474,7 +475,7 @@ glm::vec3 AIController::GetPursuitForce(const Entity &, const EntityState &state glm::vec3 cur_diff(state.Diff(GetPursuitTarget().GetState())); float time_estimate = length(cur_diff) / pursuit_speed; EntityState pred_state(GetPursuitTarget().GetState()); - pred_state.block_pos += pred_state.velocity * time_estimate; + pred_state.pos.block += pred_state.velocity * time_estimate; return Seek(state, pred_state, pursuit_speed, 2.0f); } @@ -529,7 +530,7 @@ void ChaseState::Update(AIController &ctrl, Entity &e, float dt) const { return; } // halt if we're close enough, flee if we're too close - float dist_sq = length_squared(e.AbsoluteDifference(ctrl.GetPursuitTarget())); + float dist_sq = length2(e.AbsoluteDifference(ctrl.GetPursuitTarget())); if (dist_sq < 8.0f) { ctrl.SetFleeTarget(ctrl.GetPursuitTarget()); ctrl.SetState(flee);