-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsensor.cpp
More file actions
34 lines (29 loc) · 786 Bytes
/
sensor.cpp
File metadata and controls
34 lines (29 loc) · 786 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
32
33
34
#include "sensor.h"
#include "maze.h"
using namespace std;
bool Sensor::readReferenceMaze(Maze const* refMaze)
{
// compute absolute position of this sensor w.r.t to the mouse on
// which it is mounted
int x = mouse->getX();
int y = mouse->getY();
int theta = (mouse->getTheta() + this->ctheta + 360) % 360;
// sensor always reads at position [1,0] relative to its own
// frame of reference
if (theta == 0) // facing RIGHT
{
return refMaze->isRightWall(x, y);
}
if (theta == 90 ) // facing UP
{
return refMaze->isUpWall(x, y);
}
if (theta == 180) // facing LEFT
{
return refMaze->isLeftWall(x, y);
}
if (theta == 270) // facing DOWN
{
return refMaze->isDownWall(x, y);
}
}