-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
181 lines (156 loc) · 6.39 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
#include "libs.hpp"
#include "loaders/loaders.hpp"
#include "utils/controls.hpp"
#include "utils/skybox.hpp"
#include "objects/lightcube.hpp"
#include "engine.hpp"
#include "objects/NURBS/NURBS.hpp"
#include "objects/anim/AnimMesh.hpp"
#include "objects/anim/Animation.hpp"
#include "objects/anim/Animator.hpp"
#include "objects/tess/tess.hpp"
#include "objects/particle/particle.hpp"
int main()
{
// load
Renderer renderer = Renderer();
// disable vsync
// glfwSwapInterval(0);
Camera camera = Camera(75.0f, 1.0f, 0.1f, 200.0f);
//ortho camera
/*
float w = 1024/100;
float h = 768/100;
camera = Camera(w/ -2, w/ 2, h / -2, h / 2, 0.1f, 500.0f);
*/
PointerlockControls controls = PointerlockControls(renderer.getWindow(), &camera);
controls.Lock();
Scene scene = Scene();
Skybox skybox = Skybox({
"assets/skybox/right.png",
"assets/skybox/left.png",
"assets/skybox/top.png",
"assets/skybox/bottom.png",
"assets/skybox/front.png",
"assets/skybox/back.png",
});
skybox.attachShader(LoadShaders("shaders/sky.vert", "shaders/sky.frag"));
Texture *texture = new Texture("assets/murlok.png");
Geometry *geometry = new Geometry("assets/murlok.obj");
Mesh *mesh = new Mesh(texture, geometry);
mesh->debug = true;
mesh->attachShader(LoadShaders("shaders/cyber/cyber.vert",
"shaders/cyber/cyber.frag",
"shaders/cyber/cyber.geom",
"shaders/cyber/cyber.tcs.glsl",
"shaders/cyber/cyber.tes.glsl"));
mesh->scale = glm::vec3(10, 10, 10);
AnimMesh *mesh2 = new AnimMesh("assets/dancing_vampire.dae");
mesh2 = mesh2->getChildren()[0];
mesh2->setTexture(new Texture("assets/Vampire_diffuse.png"));
mesh2->scale = glm::vec3(3, 3, 3);
mesh2->position = glm::vec3(0, 0, 10);
Animation dance = Animation("assets/dancing_vampire.dae",mesh2);
Animator animator(&dance);
//some other model
Texture *texture3 = new Texture("assets/uvgrid.png");
Geometry *geometry3 = new Geometry("assets/dino.obj");
Mesh *mesh3 = new Mesh(texture3, geometry3);
mesh3->debug = true;
mesh3->attachShader(LoadShaders("shaders/cyber/cyber.vert",
"shaders/cyber/cyber.frag",
"shaders/cyber/cyber.geom",
"shaders/cyber/cyber.tcs.glsl",
"shaders/cyber/cyber.tes.glsl"));
//mesh3->attachShader(LoadShaders("shaders/main.vert", "shaders/maincopy.frag"));
mesh3->drawtype = GL_TRIANGLES;
mesh3->scale = glm::vec3(3, 3, 3);
mesh3->position = glm::vec3(20, 0, 10);
//draw circle
std::vector<glm::vec3> points = std::vector<glm::vec3>();
std::vector<glm::vec3> normals = std::vector<glm::vec3>();
std::vector<glm::vec2> uvs = std::vector<glm::vec2>();
for (float i = 0; i < 360; i += 10)
{
float ii = glm::radians(i);
float prev_ii = glm::radians(i - 10);
auto currPoint = glm::vec3(cos(ii) * 10, sin(ii) * 10, 0);
auto prevPoint = glm::vec3(cos(prev_ii) * 10, sin(prev_ii) * 10, 0);
auto center = glm::vec3(0, 0, 0);
points.push_back(currPoint);
points.push_back(prevPoint);
points.push_back(center);
normals.push_back(glm::vec3(0, 0, 1));
normals.push_back(glm::vec3(0, 1, 1));
normals.push_back(glm::vec3(1, 1, 1));
uvs.push_back(glm::vec2(cos(ii) , sin(ii) ));
uvs.push_back(glm::vec2(cos(prev_ii) , sin(prev_ii) ));
uvs.push_back(glm::vec2(0.5, 0.5));
}
Geometry *geometry2 = new Geometry(points, uvs, normals);
Mesh *mesh4 = new Mesh(new Texture("assets/uwu.png"), geometry2);
mesh4->moveRelative(glm::vec3(0, 0, -8));
mesh4->attachShader(LoadShaders("shaders/main.vert", "shaders/maincopy.frag"));
scene.addMesh(mesh4);
Geometry *geometry5 = new Geometry("assets/arrow.obj");
Mesh *mesh5 = new Mesh(new Texture(255,255,0), geometry5);
mesh5->moveRelative(glm::vec3(-5, 0, -5));
mesh5->rotation = glm::vec3(3.14159/2, 0, 3.14159/2);
mesh5->scale = glm::vec3(1, 5, 1);
mesh5->attachShader(LoadShaders("shaders/main.vert", "shaders/maincopy.frag"));
scene.addMesh(mesh5);
Mesh *mesh6 = new Mesh(new Texture(0,0,255), geometry5);
mesh6->moveRelative(glm::vec3(0, 0, 0));
mesh6->rotation = glm::vec3(0, 3.14159/2, 3.14159/2);
mesh6->scale = glm::vec3(1, 5, 1);
mesh6->attachShader(LoadShaders("shaders/main.vert", "shaders/maincopy.frag"));
scene.addMesh(mesh6);
std::vector<glm::vec3> pointss = {
glm::vec3(-0.9f, -0.9f, 0),
glm::vec3(-0.5f, 1.0f, 0),
glm::vec3( 0.5f, 1.0f, 0),
glm::vec3( 0.5f, -0.5f, 0),
glm::vec3( 0.5f, -0.5f, 0),
glm::vec3(-0.5f, -1.0f, 0),
glm::vec3(-0.5f, -0.5f, 0),
glm::vec3( 0.5f, 0.5f, 0),
};
Bezier* b = new Bezier(pointss);
Particle *particleEmitter = new Particle();
particleEmitter->drawtype = GL_LINE_STRIP;
scene.addMesh(particleEmitter);
scene.addMesh(mesh);
scene.addMesh(mesh2);
scene.addMesh(mesh3);
scene.addMesh(&skybox);
//scene.addMesh(b);
glDisable(GL_CULL_FACE);
mesh->moveRelative(glm::vec3(15, 0, -10));
mesh2->position = glm::vec3(0, 0, 0);
/*renderer.setGLCallback([]() {
glClear(GL_DEPTH_BUFFER_BIT);
});*/
// render
float integal = 0;
while (!renderer.shouldClose())
{
// clear returns time delta
float tick = renderer.Clear() * 100;
if (tick != tick || tick > 10 || tick < 0)
tick = 0;
integal += tick;
animator.UpdateAnimation(tick*0.01);
particleEmitter->update(tick*0.01);
//animator2.UpdateAnimation(tick*0.01);
//animation matrix load
mesh2->transforms = animator.GetFinalBoneMatrices();
//mesh3->transforms = animator2.GetFinalBoneMatrices();
//cout << endl;
// circle move cube around dino
//mesh2->rotation.y += 0.1f;
//mesh2->moveRelative(glm::vec3(0, 0, tick * 0.1f));
camera.position += controls.getVelocity() * (0.4f * tick);
renderer.Render(&scene, &camera);
// cout << camera.position.x << ", " << camera.position.y << ", " << camera.position.z << endl;
}
}