This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
200 lines (154 loc) · 4.9 KB
/
main.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* Jogo Produzido por Lucas Mello para fins acadêmicos
* UFES - Departamento de Informática
*/
#include <GL/glut.h>
#include <stdlib.h>
#include "GameEngine/Space.h"
#include <vector>
#include <iostream>
#include <cmath>
#include "GameEngine/Map.h"
#include "Controller.h"
#include "GameEngine/ParticipantFactory.h"
#include "Participants/Runners/Runner.h"
#include "Participants/Runners/BasicRunner.h"
#include "Box.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "LoadTexture/image.h"
#include "maps/maps.h"
using namespace std;
double ang=0;
int view_angX=0,view_angY=0;
GLfloat camerapos=5;
extern GLfloat look_angle;
extern GLfloat look_angle_Y;
int window_weight=800;
int window_height=800;
int window_id;
extern Map runningMap;
extern bool debugmode_on;
void drawEixos(float size,float altura=0){
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(0,altura,0);
glVertex3f(size,altura,0);
glEnd();
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex3f(0,altura,0);
glVertex3f(0,size+altura,0);
glEnd();
glColor3f(0,1,1);
glBegin(GL_LINES);
glVertex3f(0,altura,0);
glVertex3f(0,altura,size);
glEnd();
}
extern GLuint RoomWallTexture;
extern GLuint RoomGroundTexture;
void generateTextures(){
glGenTextures(1, &Box::boxtextureid);
glBindTexture(GL_TEXTURE_2D, Box::boxtextureid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
image_load_to_texture("textures/crate.jpeg");
glGenTextures(1, &RoomWallTexture);
glBindTexture(GL_TEXTURE_2D, RoomWallTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
image_load_to_texture("textures/portal-walltexture-4.jpeg");
glGenTextures(1, &RoomGroundTexture);
glBindTexture(GL_TEXTURE_2D, RoomGroundTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
image_load_to_texture("textures/portal2texture-2.jpeg");
}
void OpenGLInit(void)
{
glShadeModel (GL_SMOOTH);
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glClearDepth( 1.0 );
glEnable( GL_DEPTH_TEST );
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
GLfloat lmodel_ambient[] = { 0.25, 0.25, 0.25, 1.0 };
// GLfloat lmodel_ambient[] = { 0, 0, 0, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
generateTextures();
}
void display(){
glEnable(GL_TEXTURE_2D);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(77,1,0.1,60);
glMatrixMode (GL_MODELVIEW);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
const PlayerParticipant* player=runningMap.getPlayer();
gluLookAt (player->getPosition().x, player->getPosition().y *1.2, player->getPosition().z,
player->getPosition().x+cos(look_angle*PI / 180), player->getPosition().y * 1.2 + sin(look_angle_Y *PI/180), player->getPosition().z+sin(look_angle*PI / 180),
0.0, 1.0, 0.0);
if(debugmode_on){
drawEixos(3);
}
runningMap.draw();
#ifdef USE_GLUT_DOUBLE_BUFFERS
glutSwapBuffers();
#else
glFlush ();
#endif
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(77,1,0.1,60);
glMatrixMode (GL_MODELVIEW);
window_weight=w;
window_height=h;
glutWarpPointer(window_weight/2,window_height/2);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
#ifdef USE_GLUT_DOUBLE_BUFFERS
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
#else
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
#endif
glutInitWindowSize (window_weight, window_height);
glutInitWindowPosition (0, 0);
window_id=glutCreateWindow (argv[0]);
OpenGLInit();
runningMap=ConstructMap(1);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutSetKeyRepeat(GLUT_KEY_REPEAT_ON);
glutKeyboardFunc(keyboardPressed);
glutKeyboardUpFunc(keyboardReleased);
glutPassiveMotionFunc(mousePassiveFunc);
glutWarpPointer(window_weight/2,window_height/2);
runningMap.runMap();
createMenu();
glutMainLoop();
return 0;
}