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