Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (62 loc) · 1.79 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (62 loc) · 1.79 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
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <random>
#include <vector>
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "shader.hpp"
#include "VAO.hpp"
#include "VBO.hpp"
#include "EBO.hpp"
#include "helper.hpp"
#include "stb_image.hpp"
#include "texture.hpp"
#include "camera.hpp"
#include "model.hpp"
int main()
{
if (windowinit(SCR_WIDTH, SCR_HEIGHT, "Moj OpenGL Prozor") != 0) return -1;
terrainDataInit();
glPatchParameteri(GL_PATCH_VERTICES, NUM_PATCH_PTS);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
lastFrame = glfwGetTime(); // otherwise the first deltaTime contains the whole loading time
while (!glfwWindowShouldClose(window))
{
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
processInput(window);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
float groundHeight = getTerrainHeight(camera.Position.x, camera.Position.z);
handleY(camera.Position);
//dy=0;
if (camera.Position.y<groundHeight+1.0f) {
camera.Position.y = groundHeight+1.0f;
if (camera.Position.y < 4.0f) dy = 0.0f;
is_on_ground = true;
}
else {
is_on_ground = false;
if (camera.Position.y > 4.0f) dy-=30.0f*deltaTime; // gravity per second (was 0.5 per frame, i.e. 30/s at 60 FPS)
}
//printf("%f\n", dy);
//printf("%f,%f,%f\n", camera.Position.x, camera.Position.y, camera.Position.z);
drawTerrain(currentFrame);
drawModels(currentFrame);
if (camera.Position.y > 3.3f) {
drawWater(currentFrame);
drawWindows();
}
else {
drawWindows();
drawWater(currentFrame);
}
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}