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