mirror of
https://codeberg.org/kbruen/y3s2-gui-project.git
synced 2025-02-23 17:49:36 +02:00
Compare commits
No commits in common. "master" and "v1.0.4" have entirely different histories.
8 changed files with 8 additions and 57 deletions
|
@ -7,5 +7,5 @@ X X X
|
||||||
X XXX XXX
|
X XXX XXX
|
||||||
X X
|
X X
|
||||||
XXXXXX X
|
XXXXXX X
|
||||||
XG X
|
X X
|
||||||
XXXXXXXXX
|
XXXXXXXXX
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
XX
|
|
||||||
|
|
||||||
XX XX
|
|
||||||
|
|
||||||
XX
|
|
|
@ -1,5 +0,0 @@
|
||||||
XXXXXXXXXX
|
|
||||||
X X X X
|
|
||||||
X XXX X
|
|
||||||
X X X
|
|
||||||
XXXXXXXXXX
|
|
|
@ -95,9 +95,6 @@ void load_maze(const std::string& path) {
|
||||||
case 'X':
|
case 'X':
|
||||||
row.push_back(1);
|
row.push_back(1);
|
||||||
break;
|
break;
|
||||||
case 'G':
|
|
||||||
row.push_back(2);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
row.push_back(-1);
|
row.push_back(-1);
|
||||||
}
|
}
|
||||||
|
|
41
src/maze.cpp
41
src/maze.cpp
|
@ -12,25 +12,15 @@ MazeScreen::MazeScreen(const std::vector<std::vector<int>>& maze):
|
||||||
maze(maze),
|
maze(maze),
|
||||||
angleX(0),
|
angleX(0),
|
||||||
mouseCapture(false),
|
mouseCapture(false),
|
||||||
posX(9999),
|
posX(1),
|
||||||
posZ(9999),
|
posZ(1) {}
|
||||||
solid(true) {
|
|
||||||
for (int i = 0; i < maze.size(); i++) {
|
|
||||||
for (int j = 0; j < maze[i].size(); j++) {
|
|
||||||
if (maze[i][j] == 0 && j < posZ) {
|
|
||||||
posX = i;
|
|
||||||
posZ = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MazeScreen::display() {
|
void MazeScreen::display() {
|
||||||
glClearColor(0.8, 0.8, 0.8, 1);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
//configures the camera with the position_x and position_z variables
|
||||||
gluLookAt(
|
gluLookAt(
|
||||||
posX,
|
posX,
|
||||||
0,
|
0,
|
||||||
|
@ -45,14 +35,6 @@ void MazeScreen::display() {
|
||||||
|
|
||||||
for (int i = 0; i < maze.size(); i++) {
|
for (int i = 0; i < maze.size(); i++) {
|
||||||
for (int j = 0; j < maze[i].size(); j++) {
|
for (int j = 0; j < maze[i].size(); j++) {
|
||||||
// Draw floor
|
|
||||||
glPushMatrix();
|
|
||||||
glColor3ub(0x33, 0x33, 0x33);
|
|
||||||
glTranslatef(i, -1, j);
|
|
||||||
glutSolidCube(1);
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
float green, blue;
|
|
||||||
switch (maze[i][j]) {
|
switch (maze[i][j]) {
|
||||||
case -1:
|
case -1:
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -67,9 +49,9 @@ void MazeScreen::display() {
|
||||||
glTranslatef(i, 0, j);
|
glTranslatef(i, 0, j);
|
||||||
|
|
||||||
// Scale green by X
|
// Scale green by X
|
||||||
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
|
||||||
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);
|
||||||
glutWireCube(1);
|
glutWireCube(1);
|
||||||
|
@ -78,13 +60,6 @@ void MazeScreen::display() {
|
||||||
glutSolidCube(1);
|
glutSolidCube(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
glPushMatrix();
|
|
||||||
glColor3ub(0xee, 0xee, 0x00);
|
|
||||||
glTranslatef(i, -1, j);
|
|
||||||
glutSolidCube(1);
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +76,7 @@ void MazeScreen::keyboard(unsigned char key, int x, int y) {
|
||||||
glutSetCursor(GLUT_CURSOR_INHERIT);
|
glutSetCursor(GLUT_CURSOR_INHERIT);
|
||||||
}
|
}
|
||||||
else if (key == ' ') {
|
else if (key == ' ') {
|
||||||
solid = false;
|
solid = !solid;
|
||||||
}
|
}
|
||||||
else if (key == 'w') {
|
else if (key == 'w') {
|
||||||
forceX += 1;
|
forceX += 1;
|
||||||
|
@ -131,10 +106,6 @@ void MazeScreen::keyboardUp(unsigned char key, int x, int y) {
|
||||||
else if (key == 'd') {
|
else if (key == 'd') {
|
||||||
forceZ -= 1;
|
forceZ -= 1;
|
||||||
}
|
}
|
||||||
else if (key == ' ') {
|
|
||||||
solid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gameTime;
|
int gameTime;
|
||||||
|
|
|
@ -20,9 +20,3 @@ void NoMazeScreen::display() {
|
||||||
glFlush();
|
glFlush();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoMazeScreen::keyboard(unsigned char key, int x, int y) {
|
|
||||||
if (key == '\e') {
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,5 +4,4 @@
|
||||||
|
|
||||||
struct NoMazeScreen : public GlutEvents {
|
struct NoMazeScreen : public GlutEvents {
|
||||||
virtual void display();
|
virtual void display();
|
||||||
virtual void keyboard(unsigned char key, int x, int y);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Name: y3s2-gui-project
|
Name: y3s2-gui-project
|
||||||
Version: 1.0.7
|
Version: 1.0.4
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: Maze project in OpenGL for Graphics and User Interfaces lecture in year 3, semester 2
|
Summary: Maze project in OpenGL for Graphics and User Interfaces lecture in year 3, semester 2
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue