diff --git a/Sensing.cpp b/Sensing.cpp index acc9e27..56b7723 100644 --- a/Sensing.cpp +++ b/Sensing.cpp @@ -164,4 +164,16 @@ bool Sensing::SwitchOn(float fromAngle, float toAngle) { } } return false; +} + +float Sensing::GetDistance(float angle) { + for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) { + Placement placement = sensorPlacements[sensorIx]; + float placementAngle = placement.direction.x; + if (placementAngle == angle) { + DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing; + return distanceSensor->GetDistance(); + } + } + return INFINITY; } \ No newline at end of file diff --git a/Sensing.h b/Sensing.h index 0319403..4f7f47b 100644 --- a/Sensing.h +++ b/Sensing.h @@ -1,7 +1,7 @@ #pragma once -#include "Sensor.h" #include "Placement.h" +#include "Sensor.h" #include @@ -20,6 +20,9 @@ struct SensorPlacement { SensorPlacement(Switch* switchSensor, Vector2 direction); }; +// class Perception : public Sensing { +// } + class Sensing { public: /// @brief Setup sensing @@ -65,6 +68,7 @@ class Sensing { float DistanceDown(float angle); float Distance(float leftAngle, float rightAngle); + float GetDistance(float angle); bool SwitchOn(float fromAngle, float toAngle); @@ -73,3 +77,5 @@ class Sensing { Placement* sensorPlacements = nullptr; unsigned int sensorCount = 0; }; + +using Perception = Sensing;