forked from markaren/threepp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (54 loc) · 1.84 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
#include "threepp/extras/imgui/imgui_context.hpp"
#include "threepp/threepp.hpp"
using namespace threepp;
int main() {
Canvas canvas;
GLRenderer renderer(canvas);
renderer.setClearColor(Color::aliceblue);
auto camera = PerspectiveCamera::create();
camera->position.z = 5;
OrbitControls controls{camera, canvas};
auto scene = Scene::create();
auto group = Group::create();
scene->add(group);
{
auto geometry = BoxGeometry::create();
auto material = MeshBasicMaterial::create();
material->color = Color::green;
auto mesh = Mesh::create(geometry, material);
mesh->position.x = -1;
group->add(mesh);
}
{
auto geometry = BoxGeometry::create();
auto material = MeshBasicMaterial::create();
material->color = Color::blue;
auto mesh = Mesh::create(geometry, material);
mesh->position.x = 1;
group->add(mesh);
}
renderer.enableTextRendering();
auto& textHandle = renderer.textHandle("Hello World");
textHandle.setPosition(0, canvas.getSize().height - 30);
textHandle.scale = 2;
std::array<float, 3> posBuf{};
imgui_functional_context ui(canvas.window_ptr(), [&] {
ImGui::SetNextWindowPos({0, 0}, 0, {0, 0});
ImGui::SetNextWindowSize({230, 0}, 0);
ImGui::Begin("Demo");
ImGui::SliderFloat3("position", posBuf.data(), -1.f, 1.f);
controls.enabled = !ImGui::IsWindowHovered();
ImGui::End();
});
canvas.onWindowResize([&](WindowSize size) {
camera->aspect = size.getAspect();
camera->updateProjectionMatrix();
renderer.setSize(size);
textHandle.setPosition(0, size.height - 30);
});
canvas.animate([&] {
renderer.render(scene, camera);
ui.render();
group->position.fromArray(posBuf);
});
}