Add GetDistance(angle)
This commit is contained in:
parent
2ff984b5bc
commit
bcbec5da32
12
Sensing.cpp
12
Sensing.cpp
@ -165,3 +165,15 @@ bool Sensing::SwitchOn(float fromAngle, float toAngle) {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Sensor.h"
|
|
||||||
#include "Placement.h"
|
#include "Placement.h"
|
||||||
|
#include "Sensor.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -20,6 +20,9 @@ struct SensorPlacement {
|
|||||||
SensorPlacement(Switch* switchSensor, Vector2 direction);
|
SensorPlacement(Switch* switchSensor, Vector2 direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// class Perception : public Sensing {
|
||||||
|
// }
|
||||||
|
|
||||||
class Sensing {
|
class Sensing {
|
||||||
public:
|
public:
|
||||||
/// @brief Setup sensing
|
/// @brief Setup sensing
|
||||||
@ -65,6 +68,7 @@ class Sensing {
|
|||||||
float DistanceDown(float angle);
|
float DistanceDown(float angle);
|
||||||
|
|
||||||
float Distance(float leftAngle, float rightAngle);
|
float Distance(float leftAngle, float rightAngle);
|
||||||
|
float GetDistance(float angle);
|
||||||
|
|
||||||
bool SwitchOn(float fromAngle, float toAngle);
|
bool SwitchOn(float fromAngle, float toAngle);
|
||||||
|
|
||||||
@ -73,3 +77,5 @@ class Sensing {
|
|||||||
Placement* sensorPlacements = nullptr;
|
Placement* sensorPlacements = nullptr;
|
||||||
unsigned int sensorCount = 0;
|
unsigned int sensorCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using Perception = Sensing;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user