|
|
|
@ -8,8 +8,6 @@
|
|
|
|
|
|
|
|
|
|
#include "utils.hpp" |
|
|
|
|
|
|
|
|
|
constexpr double PI = 3.14159265358979; |
|
|
|
|
|
|
|
|
|
MazeScreen::MazeScreen(const std::vector<std::vector<int>>& maze):
|
|
|
|
|
maze(maze),
|
|
|
|
|
angleX(0),
|
|
|
|
@ -27,9 +25,9 @@ void MazeScreen::display() {
|
|
|
|
|
posX,
|
|
|
|
|
0,
|
|
|
|
|
posZ,
|
|
|
|
|
posX + cos((angleX * PI) / 180) * 3,
|
|
|
|
|
posX + cos(Utils::toRad(angleX)) * 3,
|
|
|
|
|
0,
|
|
|
|
|
posZ - sin((angleX * PI) / 180) * 3,
|
|
|
|
|
posZ - sin(Utils::toRad(angleX)) * 3,
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
0 |
|
|
|
@ -47,18 +45,21 @@ void MazeScreen::display() {
|
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
glPushMatrix(); |
|
|
|
|
|
|
|
|
|
glTranslatef(i, 0, j); |
|
|
|
|
|
|
|
|
|
// Scale green by X
|
|
|
|
|
auto green = Utils::clamp<float>(Utils::nummap<float>(abs(i - posX), 0, 3, 0, 1), 0, 1); |
|
|
|
|
// Scale blue by Z
|
|
|
|
|
auto blue = Utils::clamp<float>(Utils::nummap<float>(abs(j - posZ), 0, 3, 0, 1), 0, 1); |
|
|
|
|
|
|
|
|
|
glColor3f(1, green, blue); |
|
|
|
|
glTranslatef(i, 0, j); |
|
|
|
|
glutWireCube(1); |
|
|
|
|
if (solid) { |
|
|
|
|
glColor3f(1, green, blue); |
|
|
|
|
glutSolidCube(1); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
glutWireCube(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glPopMatrix(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -114,8 +115,8 @@ void MazeScreen::idle() {
|
|
|
|
|
auto deltaTime = (newTime - gameTime) / 1000.0; |
|
|
|
|
gameTime = newTime; |
|
|
|
|
|
|
|
|
|
posX += forceX * deltaTime * cos(angleX * PI / 180) + forceZ * deltaTime * sin(angleX * PI / 180); |
|
|
|
|
posZ += forceZ * deltaTime * cos(angleX * PI / 180) - forceX * deltaTime * sin(angleX * PI / 180); |
|
|
|
|
posX += forceX * deltaTime * cos(Utils::toRad(angleX)) + forceZ * deltaTime * sin(Utils::toRad(angleX)); |
|
|
|
|
posZ += forceZ * deltaTime * cos(Utils::toRad(angleX)) - forceX * deltaTime * sin(Utils::toRad(angleX)); |
|
|
|
|
|
|
|
|
|
glutPostRedisplay(); |
|
|
|
|
} |
|
|
|
|