diff --git a/src/fmri/RenderingState.cpp b/src/fmri/RenderingState.cpp index 9b5128d..1edf14e 100644 --- a/src/fmri/RenderingState.cpp +++ b/src/fmri/RenderingState.cpp @@ -9,7 +9,7 @@ using namespace fmri; -static inline void toggle(bool& b) +static inline void toggle(bool &b) { b = !b; } @@ -32,7 +32,8 @@ static float getFPS() return fps; } -static void updatePointSize(float dir) { +static void updatePointSize(float dir) +{ float size, granularity; glGetFloatv(GL_POINT_SIZE, &size); glGetFloatv(GL_POINT_SIZE_GRANULARITY, &granularity); @@ -127,7 +128,7 @@ void RenderingState::handleKey(unsigned char x) glutPostRedisplay(); } -std::string RenderingState::debugInfo()const +std::string RenderingState::debugInfo() const { std::stringstream buffer; buffer << "Pos(x,y,z) = (" << pos[0] << ", " << pos[1] << ", " << pos[2] << ")\n"; @@ -146,7 +147,7 @@ void RenderingState::reset() angle[1] = 0; } -void RenderingState::configureRenderingContext()const +void RenderingState::configureRenderingContext() const { glLoadIdentity(); glRotatef(angle[1], 1, 0, 0); @@ -163,9 +164,12 @@ RenderingState &RenderingState::instance() void RenderingState::registerControls() { reset(); - glutPassiveMotionFunc([](int x, int y) { + auto motionFunc = [](int x, int y) { RenderingState::instance().handleMouseAt(x, y); - }); + }; + glutPassiveMotionFunc(motionFunc); + glutMotionFunc(motionFunc); + glutKeyboardFunc([](auto key, auto, auto) { RenderingState::instance().handleKey(key); }); @@ -174,13 +178,26 @@ void RenderingState::registerControls() RenderingState::instance().render(time); }); glutIdleFunc([]() { - checkGLErrors(); - throttleIdleFunc(); - glutPostRedisplay(); + RenderingState::instance().idleFunc(); }); glutSpecialFunc([](int key, int, int) { RenderingState::instance().handleSpecialKey(key); }); + glutMouseFunc([](int button, int state, int, int) { + auto& options = RenderingState::instance().options; + switch (button) { + case GLUT_LEFT_BUTTON: + options.mouse_1_pressed = state == GLUT_DOWN; + break; + case GLUT_RIGHT_BUTTON: + options.mouse_2_pressed = state == GLUT_DOWN; + break; + + default: + // Do nothing. + break; + } + }); } void RenderingState::handleMouseAt(int x, int y) @@ -381,3 +398,17 @@ float RenderingState::layerAlpha() const { return options.layerAlpha; } + +void RenderingState::idleFunc() +{ + if (options.mouse_1_pressed) { + move('w', false); + } + if (options.mouse_2_pressed) { + move('s', false); + } + + checkGLErrors(); + throttleIdleFunc(); + glutPostRedisplay(); +} diff --git a/src/fmri/RenderingState.hpp b/src/fmri/RenderingState.hpp index e9d9994..1b725d6 100644 --- a/src/fmri/RenderingState.hpp +++ b/src/fmri/RenderingState.hpp @@ -68,6 +68,8 @@ namespace fmri float layerAlpha; float interactionAlpha; Color pathColor; + bool mouse_1_pressed = false; + bool mouse_2_pressed = false; } options; std::array pos; std::array angle; @@ -83,6 +85,7 @@ namespace fmri void move(unsigned char key, bool sprint); void updateVisualisers(); + void idleFunc(); std::string debugInfo() const; void renderOverlayText() const; diff --git a/src/fmri/main.cpp b/src/fmri/main.cpp index 6a95573..f810f11 100644 --- a/src/fmri/main.cpp +++ b/src/fmri/main.cpp @@ -40,7 +40,7 @@ static void loadSimulationData(const Options &options) if (optLabels) { auto& labels = *optLabels; for (const auto& result : results) { - auto& last = *result.rbegin(); + auto &last = *result.rbegin(); auto bestIndex = std::distance(last.data(), max_element(last.data(), last.data() + last.numEntries())); LOG(INFO) << "Got answer: " << labels[bestIndex] << endl; }