1 #ifndef BLANK_WORLD_STEERING_HPP
2 #define BLANK_WORLD_STEERING_HPP
4 #include "../geometry/Location.hpp"
5 #include "../geometry/primitive.hpp"
20 // standalone behaviours
23 OBSTACLE_AVOIDANCE = 0x0004,
25 // requires target velocity
26 TARGET_VELOCITY = 0x0008,
28 // behaviours requiring a target entity
29 EVADE_TARGET = 0x0010,
30 PURSUE_TARGET = 0x0020,
33 explicit Steering(const Entity &);
36 Steering &Enable(unsigned int b) noexcept { enabled |= b; return *this; }
37 Steering &Disable(unsigned int b) noexcept { enabled &= ~b; return *this; }
38 bool AnyEnabled(unsigned int b) const noexcept { return enabled & b; }
39 bool AllEnabled(unsigned int b) const noexcept { return (enabled & b) == b; }
41 Steering &SetTargetEntity(Entity &) noexcept;
42 Steering &ClearTargetEntity() noexcept;
43 bool HasTargetEntity() const noexcept { return target_entity; }
44 const Entity &GetTargetEntity() const noexcept { return *target_entity; }
46 Steering &SetTargetVelocity(const glm::vec3 &v) noexcept { target_velocity = v; return *this; }
47 const glm::vec3 &GetTargetVelocity() const noexcept { return target_velocity; }
49 /// time in seconds in which steering tried to arrive at target velocity
50 Steering &SetAcceleration(float a) noexcept { accel = a; return *this; }
51 /// maximum magnitude of velocity that behaviours generate
52 Steering &SetSpeed(float s) noexcept { speed = s; return *this; }
54 /// configure wandering
55 /// r is the radius of the sphere
56 /// dist is the distance between the entity and the sphere's center
57 /// disp is the maximum variance of the point on the sphere in units per second
58 Steering &SetWanderParams(float r, float dist, float disp) noexcept {
65 void Update(World &, float dt);
67 glm::vec3 Force(const EntityState &) const noexcept;
70 void UpdateWander(World &, float dt);
71 void UpdateObstacle(World &);
73 /// try to add as much of in to out so it doesn't exceed max
74 /// returns true if it's maxed out
75 static bool SumForce(glm::vec3 &out, const glm::vec3 &in, float max) noexcept;
77 /// slow down to a halt
78 glm::vec3 Halt(const EntityState &) const noexcept;
79 /// accelerate to match given velocity
80 glm::vec3 TargetVelocity(const EntityState &, const glm::vec3 &) const noexcept;
81 /// move towards given location
82 glm::vec3 Seek(const EntityState &, const ExactLocation &) const noexcept;
83 /// move away from given location
84 glm::vec3 Flee(const EntityState &, const ExactLocation &) const noexcept;
85 /// try to halt at given location
86 glm::vec3 Arrive(const EntityState &, const ExactLocation &) const noexcept;
87 /// seek given entity's predicted position
88 glm::vec3 Pursuit(const EntityState &, const Entity &) const noexcept;
89 /// flee given entity's predicted position
90 glm::vec3 Evade(const EntityState &, const Entity &) const noexcept;
91 /// move around for no reason
92 glm::vec3 Wander(const EntityState &) const noexcept;
93 /// try not to crash into blocks
94 glm::vec3 ObstacleAvoidance(const EntityState &) const noexcept;
99 Entity *target_entity;
100 glm::vec3 target_velocity;
108 glm::vec3 wander_pos;
110 glm::vec3 obstacle_dir;
112 unsigned int enabled;