-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandaloneMain.cpp
96 lines (69 loc) · 2.08 KB
/
StandaloneMain.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
#include "CommonInterfaces/CommonExampleInterface.h"
#include "Utils/b3Clock.h"
#include "FrameworkGuiHelper.h"
#include "FrameworkRenderInterface.h"
#include "SimpleFrameworkApp.h"
#include "framework.h"
static CommonExampleInterface * example = nullptr;
static b3MouseMoveCallback prevMouseMoveCallback = nullptr;
static b3MouseButtonCallback prevMouseButtonCallback = nullptr;
static void OnMouseMove(float x, float y)
{
const bool handled = example->mouseMoveCallback(x, y);
if (!handled)
{
if (prevMouseMoveCallback)
prevMouseMoveCallback(x, y);
}
}
static void OnMouseDown(int button, int state, float x, float y)
{
const bool handled = example->mouseButtonCallback(button, state, x, y);
if (!handled)
{
if (prevMouseButtonCallback)
prevMouseButtonCallback(button, state, x, y);
}
}
int main(int argc, char * argv[])
{
setupPaths(CHIBI_RESOURCE_PATHS);
SimpleFrameworkApp * app = new SimpleFrameworkApp("Bullet Standalone Example", 1024, 768, true);
prevMouseButtonCallback = app->m_window->getMouseButtonCallback();
prevMouseMoveCallback = app->m_window->getMouseMoveCallback();
app->m_window->setMouseButtonCallback((b3MouseButtonCallback)OnMouseDown);
app->m_window->setMouseMoveCallback((b3MouseMoveCallback)OnMouseMove);
FrameworkGUIHelperInterface gui;
gui.m_renderInterface = app->m_renderer;
gui.m_appInterface = app;
CommonExampleOptions options(&gui);
example = StandaloneExampleCreateFunc(options);
example->processCommandLineArgs(argc, argv);
example->initPhysics();
example->resetCamera();
b3Clock clock;
for (;;)
{
if (app->m_window->requestedExit())
break;
app->m_renderer->init();
app->m_renderer->updateCamera(app->getUpAxis());
float dt = clock.getTimeInSeconds();
if (dt < .1f)
dt = .1f;
example->stepSimulation(dt);
clock.reset();
example->physicsDebugDraw(~0);
//example->renderScene();
DrawGridData dg;
dg.upAxis = app->getUpAxis();
app->drawGrid(dg);
app->swapBuffer();
}
example->exitPhysics();
delete example;
example = nullptr;
delete app;
app = nullptr;
return 0;
}