-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (66 loc) · 2.11 KB
/
main.cpp
File metadata and controls
70 lines (66 loc) · 2.11 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
#include <iostream>
#include <fstream>
#include "include/Berry3D.h"
Berry3D::Berry3D berry3D("Berry3D");
Berry3D::Scene scene;
Berry3D::FreeCamera camera;
static void callback(GLFWwindow* win, int key, int scancode, int action, int mods) {
switch (key) {
case GLFW_KEY_W:
camera.forward(1);
break;
case GLFW_KEY_S:
camera.forward(-1);
break;
case GLFW_KEY_A:
camera.left(1);
break;
case GLFW_KEY_D:
camera.left(-1);
break;
case GLFW_KEY_UP:
camera.rotate(Berry3D::Vector3(PI / 90, 0, 0));
break;
case GLFW_KEY_DOWN:
camera.rotate(Berry3D::Vector3(-PI / 90, 0, 0));
break;
case GLFW_KEY_LEFT:
camera.rotate(Berry3D::Vector3(0, PI / 90, 0));
break;
case GLFW_KEY_RIGHT:
camera.rotate(Berry3D::Vector3(0, -PI / 90, 0));
break;
case GLFW_KEY_I:
std::cout << camera.position.x << ", " << camera.position.y << ", " << camera.position.z << std::endl;
std::cout << camera.rotation.x << ", " << camera.rotation.y << ", " << camera.rotation.z << std::endl;
break;
}
}
float theta = 0;
auto la = new Berry3D::Light(Berry3D::Color(0, 2, 0), Berry3D::Vector3(0, 10, 10));
auto lb = new Berry3D::Light(Berry3D::Color(0, 0, 2), Berry3D::Vector3(0, 10, 0));
int main() {
scene.use(&camera);
berry3D.use(&scene);
berry3D.setKeyEvent(callback);
scene.setAmbientLight(Berry3D::Color(0, 1, 0));
scene.addLight(la);
scene.addLight(lb);
Berry3D::ObjLoader objLoader("torus.obj");
auto obj = objLoader.load();
obj->scale(.01f);
obj->rotate(Berry3D::Vector3(0, 0, M_PI_2));
scene.push(obj);
Berry3D::BinContent bc{};
obj->tobe4(bc);
auto fp = fopen( "ring.be4d" , "w" );
fwrite(bc.content, bc.len , 1, fp);
fclose(fp);
berry3D.render([]() {
la->position.x = 10 * cos(theta);
lb->position.y = 10 * cos(theta + PI);
theta += PI / 90;
});
scene.autoClear();
return 0;
}