-
Notifications
You must be signed in to change notification settings - Fork 0
/
raycasting.h
57 lines (43 loc) · 1.24 KB
/
raycasting.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef RAYCASTING_RAYCASTING_H
#define RAYCASTING_RAYCASTING_H
#include <cmath>
#include <vector>
#include "ray.h"
namespace rc {
class FieldOfView {
private:
// Angle in degrees
float _degrees;
public:
explicit FieldOfView(float degrees) : _degrees(degrees) {}
float angleInRadians() const {
return _degrees * (M_PI / 180);
}
float angleInDegrees() const {
return _degrees;
}
};
/**
* Responsible for casting and tracing rays.
*/
class Raycaster {
private:
rc::FieldOfView *_fovAngle;
std::vector<Ray> _rays;
public:
explicit Raycaster(float fovAngle) {
_fovAngle = new FieldOfView(fovAngle);
}
~Raycaster() {
delete _fovAngle;
}
public:
std::vector<Ray> rays() const {
return _rays;
};
void castAllRays(float playerRotationAngle, const Map &map, unsigned playerX, unsigned playerY, unsigned numberOfRays);
float getDistanceFromProjectionPlane(size_t screenWidth) const;
const std::vector<unsigned int> &getWallStripHeights(float playerRotationAngle, unsigned d);
};
}
#endif //RAYCASTING_RAYCASTING_H