-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
181 lines (129 loc) · 5.1 KB
/
Copy pathmain.cpp
File metadata and controls
181 lines (129 loc) · 5.1 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
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
#include "headers/main.h"
using namespace std;
const int width = 800, height = 800;
bool ico = false;
int main() {
bool wire_frame_mode = false;
Camera Camera(width, height, vec3(0.0f, 0.0f, 2.0f));
Window window("Mexil", width, height);
GLfloat lightVertices[] = {
-0.1f, -0.1f, 0.1f,
-0.1f, -0.1f, -0.1f,
0.1f, -0.1f, -0.1f,
0.1f, -0.1f, 0.1f,
-0.1f, 0.1f, 0.1f,
-0.1f, 0.1f, -0.1f,
0.1f, 0.1f, -0.1f,
0.1f, 0.1f, 0.1f,
};
GLuint lightIndices[] = {
0, 1, 2,
0, 2, 3,
0, 4, 7,
0, 7, 3,
3, 7, 6,
3, 6, 2,
2, 6, 5,
2, 5, 1,
1, 5, 4,
1, 4, 0,
4, 5, 6,
4, 6, 7
};
Shader shader("shaders/vertex_shader.glsl", "shaders/fragment_shader.glsl", "shaders/geometric_shader.glsl");
shader.enable();
shader.setUniformMat4("ml_matrix", mat4::translation(vec3(0.0f, 0.0f, -1.3f)));
vec3 light_pos = vec3(0.0f, 0.0f, 0.0f);
shader.setUniform3f("light_pos", light_pos);
glViewport(0, 0, width, height);
// Very important, do not touch
glEnable(GL_DEPTH_TEST); // Gives us true 3d
//glEnable(GL_BLEND);
//glDisable(GL_LIGHTING);
//glEnable(GL_POINT_SMOOTH);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
////////////////////////////////
//#if ico
/* Icosahedron icosahedron;
TileLayer layer(&shader);
vector<Renderable2D*> IcosahedronFaces;
for (int i=0; i<20; i++) {
icosahedron.subdivide(FaceCoord[indices[i][0]], FaceCoord[indices[i][1]], FaceCoord[indices[i][2]], 1);
for (int j=0; j<icosahedron.getRenderables().size(); j++)
IcosahedronFaces.push_back(icosahedron.getRenderables().at(j));
}
//cout << "Shape faces = " << IcosahedronFaces.size() << endl;
for (int i=0; i<IcosahedronFaces.size(); i++) layer.add(IcosahedronFaces.at(i));*/
//#else
//Terrainface terrain(2, vec3(0.0f, 1.0f, 0.0f));
//terrain.ConstructMesh();
//TileLayer layer(&shader);
//for (int i=0; i<terrain.getRenderables().size(); i++) layer.add(terrain.getRenderables().at(i));
Planet planet(2, 1.0f, 1.0f);
TileLayer layer(&shader);
for (int i=0; i<planet.getRenderables().size(); i++) layer.add(planet.getRenderables().at(i));
//delete terrain;
//#endif
float x, y, angle_y = 0.0f, angle_x = 0.0f;
float x_m=0.0f, z_m=0.0f;
int numb_face = 2;
int numb_face_previous = numb_face;
float roughness=0.0f, strength=0.0f;
float roughness_previous=roughness, strength_previous=strength;
float x_offset=0.0f, y_offset=0.0f, z_offset=0.0f;
float x_offset_previous=x_offset, y_offset_previous=y_offset, z_offset_previous=z_offset;
//#ifdef ico
while(!window.closed()) {
window.clear();
window.RenderGUI(&numb_face, &strength, &roughness, &x_offset, &y_offset, &z_offset);
//window.RenderGUI(&numb_face);
if (numb_face != numb_face_previous || roughness != roughness_previous || strength != strength_previous || x_offset != x_offset_previous || y_offset != y_offset_previous || z_offset != z_offset_previous) {
Planet planet(numb_face, strength, roughness, vec3(x_offset, y_offset, z_offset));
layer.clean_slate();
for (int i=0; i<planet.getRenderables().size(); i++) layer.add(planet.getRenderables().at(i));
numb_face_previous = numb_face;
strength_previous = strength;
roughness_previous = roughness;
x_offset_previous = x_offset;
y_offset_previous = y_offset;
z_offset_previous = z_offset;
}
shader.enable();
Camera.Inputs(window.getWindow()); // Low-key sad
shader.enable();
Camera.Matrix(120.0f, 0.1f, 100.0f, shader, "camMatrix");
shader.enable();
shader.setUniformMat4("pr_matrix", mat4::perspective(100.0f, (float)(window.getWidth()/window.getHeight()), 0.1f, 100.0f));
shader.setUniform3f("light_pos", vec3(x_m, 0, z_m));
if (window.isKeyPressed(GLFW_KEY_ESCAPE)) break;
if (window.isKeyPressed(GLFW_KEY_DOWN)) angle_y -= 2.5f;
if (window.isKeyPressed(GLFW_KEY_UP)) angle_y += 2.5f;
if (window.isKeyPressed(GLFW_KEY_LEFT)) angle_x -= 2.5f;
if (window.isKeyPressed(GLFW_KEY_RIGHT)) angle_x += 2.5f;
if (window.isKeyPressed(GLFW_KEY_W)) z_m += 0.1f;
if (window.isKeyPressed(GLFW_KEY_S)) z_m -= 0.1f;
if (window.isKeyPressed(GLFW_KEY_A)) x_m += 0.1f;
if (window.isKeyPressed(GLFW_KEY_D)) x_m -= 0.1f;
if (angle_y >= 360.0f || angle_y <= -360.0f) angle_y = 0.0f;
if (angle_x >= 360.0f || angle_x <= -360.0f) angle_x = 0.0f;
shader.enable();
shader.setUniformMat4("rt_matrix_x", mat4::rotation(angle_x, vec3(0.0f, 1.0f, 0.0f)) );
shader.setUniformMat4("rt_matrix_y", mat4::rotation(angle_y, vec3(1.0f, 0.0f, 0.0f)) );
window.getMousePosition(x, y);
shader.enable();
layer.render();
window.update();
}
/*#else
SimplexNoise();
#endif*/
return 0;
}
/*if (window.isKeyPressed(GLFW_KEY_DOWN)) angle_y -= 2.5f;
if (window.isKeyPressed(GLFW_KEY_UP)) angle_y += 2.5f;
if (window.isKeyPressed(GLFW_KEY_LEFT)) angle_x -= 2.5f;
if (window.isKeyPressed(GLFW_KEY_RIGHT)) angle_x += 2.5f;*/
//if (angle_y >= 360.0f || angle_y <= -360.0f) angle_y = 0.0f;
//if (angle_x >= 360.0f || angle_x <= -360.0f) angle_x = 0.0f;
//shader.setUniformMat4("ml_matrix", mat4::rotation((y+window.getHeight()/2.0f)*0.3f, vec3(1.0f, 0.0f, 0.0f)));