-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
128 lines (103 loc) · 2.72 KB
/
Copy pathmain.cpp
File metadata and controls
128 lines (103 loc) · 2.72 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
#include "game.cpp"
#include <cmath>
#include <vector>
struct Player
{
RayCaster caster;
struct Keybindings
{
char* moveup = "w";
char* movedown = "s";
char* moveleft = "a";
char* moveright = "d";
char* rotateleft = "q";
char* rotateright = "e";
} keys;
}player;
struct Map
{
std::vector<Line> walls;
}map;
const int WIDTH = 500;
const int HEIGHT = 500;
void place_walls()
{
map.walls.push_back(Line( 0, 0, WIDTH, 0));
map.walls.push_back(Line(WIDTH, 0, WIDTH, HEIGHT));
map.walls.push_back(Line(WIDTH, HEIGHT, 0, HEIGHT));
map.walls.push_back(Line( 0, HEIGHT, 0, 0));
map.walls.push_back(Line( WIDTH/4, HEIGHT/4, 3*WIDTH/4, HEIGHT/4));
map.walls.push_back(Line(3*WIDTH/4, HEIGHT/4, 3*WIDTH/4, 3*HEIGHT/4));
map.walls.push_back(Line(3*WIDTH/4, 3*HEIGHT/4, WIDTH/4, 3*HEIGHT/4));
map.walls.push_back(Line( WIDTH/4, 3*HEIGHT/4, WIDTH/4, HEIGHT/4));
}
void place_player()
{
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
for (const auto& wall : map.walls)
{
wall.show();
}
// You'll need to handle mouse input differently in OpenGL.
// Replace mouseX and mouseY with appropriate input handling.
// caster.update(mouseX, mouseY);
//player.caster.show();
player.caster.look(map.walls);
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, w, h, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'w':
player.caster.move(0, -25); // Move particle up
break;
case 's':
player.caster.move(0, 25); // Move particle down
break;
case 'a':
player.caster.move(-25, 0); // Move particle left
break;
case 'd':
player.caster.move(25, 0); // Move particle right
break;
}
glutPostRedisplay(); // Request redraw
}
void mouse(int button, int state, int x, int y) {
printf("Call MouseFunc : ati %s butonul %s in pozitia %d %d\n",
(state == GLUT_DOWN) ? "apasat" : "eliberat",
(button == GLUT_LEFT_BUTTON) ?
"stang" :
((button == GLUT_RIGHT_BUTTON) ? "drept": "mijlociu"),
x, y);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("2D Ray Casting");
place_walls();
place_player();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}