-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.cpp
74 lines (62 loc) · 1.96 KB
/
viewer.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
#include <iostream>
#include <cmath>
#include <basicgl/Manager.hpp>
#include <cstdlib>
using namespace BasicGL;
using namespace std;
bool translate = false;
void mouseHandler(Mouse mouse, WindowPtr window)
{
ElementPtr object = window->find("object");
if(mouse.move)
{
if(translate)
object->translate( mouse.dx, -mouse.dy );
else
object->rotate( mouse.dy, mouse.dx );
}
if(mouse.scroll != 0)
object->scale(mouse.scroll * 0.02f);
}
void keyboardHandler(Keyboard keyboard, WindowPtr window)
{
if(keyboard.key == 'T' || keyboard.key == 't')
translate = !translate;
else if(keyboard.key == 'F' || keyboard.key == 'f')
{
ElementPtr object = window->find("object");
object->obj.flipYZ = !object->obj.flipYZ;
}
else if(keyboard.key == KEY_ESC)
{
ElementPtr object = window->find("object");
object->moveTo(0, 0, 0);
object->scaleTo(3.0f);
object->rotateTo(0, 0, 0);
}
}
int main(int argc, char *argv[])
{
string objFile = "../src/examples/data/mario.obj";
if(argc > 1)
objFile = string(argv[1]);
cout << "Viewing: " << objFile << endl;
Manager::Init(argc, argv);
Manager::Create("Viewer", MODE_3D);
Manager::SetMouseFunction(mouseHandler);
Manager::SetKeyboardFunction(keyboardHandler);
WindowPtr window = Manager::CurrentWindow();
float zplane = window->ZPlane();
Manager::CreateElement(TEXT)->setText("Flip YZ: F")->textAlign(Align_Left | Align_Bottom)->moveTo(-1.0f, -0.9f, zplane);
Manager::CreateElement(TEXT)->setText("Enable/Disable translate: T")->textAlign(Align_Left | Align_Bottom)->moveTo(-1.0f, -1.0f, zplane);
ElementPtr object = Manager::CreateElement(OBJECT, "object");
object->scaleTo(3.0f);
if(!object->obj.load(objFile))
{
cerr << "Could not open the file" << endl;
exit(0);
}
Manager::Show();
Manager::Destroy();
return 0;
}