Program Listing for File apf_manager.hpp
↰ Return to documentation for file (cosm/apf2D/apf_manager.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <memory>
#include <vector>
#include "rcppsw/er/client.hpp"
#include "rcppsw/rcppsw.hpp"
#include "rcppsw/math/rng.hpp"
#include "cosm/apf2D/tracker.hpp"
#include "cosm/apf2D/boid.hpp"
#include "cosm/apf2D/nav/phototaxis_force.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace cosm::apf2D {
namespace nav {
class arrival_force;
class avoidance_force;
class path_following_force;
class polar_force;
class wander_force;
} /* namespace nav */
namespace flocking {
class constant_speed_force;
class alignment_force;
} /* namespace flocking */
namespace config {
struct apf_manager_config;
} /* namespace config */
/*******************************************************************************
* Class Definitions
******************************************************************************/
class apf_manager : public rer::client<apf_manager> {
public:
apf_manager(boid& entity, const config::apf_manager_config* config);
~apf_manager(void);
const rmath::vector2d& value(void) const { return m_force_accum; }
void value(const rmath::vector2d& val) { m_force_accum = val; }
const class tracker* tracker(void) const { return &m_tracker; }
class tracker* tracker(void) {
return &m_tracker;
}
void forces_reset(void);
void tracking_reset(void);
bool is_enabled(void) const { return m_enabled; }
void enable(void) { m_enabled = true; }
void disable(void) { m_enabled = false; }
rmath::vector2d seek_to(const rmath::vector2d& target);
rmath::vector2d wander(rmath::rng* rng);
rmath::vector2d avoidance(const rmath::vector2d& closest_obstacle);
rmath::vector2d
phototaxis(const nav::phototaxis_force::light_sensor_readings& readings);
rmath::vector2d
phototaxis(const nav::phototaxis_force::camera_sensor_readings& readings,
const rutils::color& color);
rmath::vector2d path_following(cnav::trajectory* path);
rmath::vector2d polar(const rmath::vector2d& center);
rmath::vector2d
anti_phototaxis(const nav::phototaxis_force::light_sensor_readings& readings);
rmath::vector2d
anti_phototaxis(const nav::phototaxis_force::camera_sensor_readings& readings,
const rutils::color& color);
rmath::vector2d alignment(const std::vector<rmath::vector2d> others);
rmath::vector2d constant_speed(const std::vector<rmath::vector2d> others);
void accum(const rmath::vector2d& force);
bool within_slowing_radius(void) const;
const boid& entity(void) const { return m_entity; }
private:
/* clang-format off */
bool m_enabled{true};
boid& m_entity;
rmath::vector2d m_force_accum{};
std::unique_ptr<nav::avoidance_force> m_avoidance;
std::unique_ptr<nav::arrival_force> m_arrival;
std::unique_ptr<nav::wander_force> m_wander;
std::unique_ptr<nav::polar_force> m_polar;
std::unique_ptr<nav::phototaxis_force> m_phototaxis;
std::unique_ptr<nav::path_following_force> m_path_following;
std::unique_ptr<flocking::alignment_force> m_alignment;
std::unique_ptr<flocking::constant_speed_force> m_constant_speed;
class tracker m_tracker{};
/* clang-format on */
};
} /* namespace cosm::apf2D */