-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVisionSector_Living.cpp
More file actions
31 lines (27 loc) · 925 Bytes
/
VisionSector_Living.cpp
File metadata and controls
31 lines (27 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "VisionSector_Living.h"
#include "Animal.h"
VisionSector_Living::VisionSector_Living(const Coordinate & center, double & animalAngle, const double & angle1, const double & angle2, int range)
: VisionSector(center, animalAngle, angle1, angle2, range)
{}
void VisionSector_Living::see(const std::vector<std::shared_ptr<Entity> > &entitiesInRangeOfVision, const std::vector<double> &distanceOfEntities)
{
scan(entitiesInRangeOfVision, distanceOfEntities);
double min = -1;
std::shared_ptr<Percepted> indMin;
for(std::shared_ptr<Percepted> p:m_percepted)
{
if(std::dynamic_pointer_cast<Animal>(p->getEntity()) != nullptr && (min == -1 || p->getDistance() < min))
{
indMin = p;
min = p->getDistance();
}
}
if(min == -1)
{
m_nearestPercepted->set(nullptr, 0);
}
else
{
m_nearestPercepted = indMin;
}
}