Implement movement with the mouse.

This commit is contained in:
2018-04-11 13:03:34 +02:00
parent 0145391450
commit 63e487afce
3 changed files with 44 additions and 10 deletions

View File

@@ -32,7 +32,8 @@ static float getFPS()
return fps; return fps;
} }
static void updatePointSize(float dir) { static void updatePointSize(float dir)
{
float size, granularity; float size, granularity;
glGetFloatv(GL_POINT_SIZE, &size); glGetFloatv(GL_POINT_SIZE, &size);
glGetFloatv(GL_POINT_SIZE_GRANULARITY, &granularity); glGetFloatv(GL_POINT_SIZE_GRANULARITY, &granularity);
@@ -163,9 +164,12 @@ RenderingState &RenderingState::instance()
void RenderingState::registerControls() void RenderingState::registerControls()
{ {
reset(); reset();
glutPassiveMotionFunc([](int x, int y) { auto motionFunc = [](int x, int y) {
RenderingState::instance().handleMouseAt(x, y); RenderingState::instance().handleMouseAt(x, y);
}); };
glutPassiveMotionFunc(motionFunc);
glutMotionFunc(motionFunc);
glutKeyboardFunc([](auto key, auto, auto) { glutKeyboardFunc([](auto key, auto, auto) {
RenderingState::instance().handleKey(key); RenderingState::instance().handleKey(key);
}); });
@@ -174,13 +178,26 @@ void RenderingState::registerControls()
RenderingState::instance().render(time); RenderingState::instance().render(time);
}); });
glutIdleFunc([]() { glutIdleFunc([]() {
checkGLErrors(); RenderingState::instance().idleFunc();
throttleIdleFunc();
glutPostRedisplay();
}); });
glutSpecialFunc([](int key, int, int) { glutSpecialFunc([](int key, int, int) {
RenderingState::instance().handleSpecialKey(key); 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) void RenderingState::handleMouseAt(int x, int y)
@@ -381,3 +398,17 @@ float RenderingState::layerAlpha() const
{ {
return options.layerAlpha; 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();
}

View File

@@ -68,6 +68,8 @@ namespace fmri
float layerAlpha; float layerAlpha;
float interactionAlpha; float interactionAlpha;
Color pathColor; Color pathColor;
bool mouse_1_pressed = false;
bool mouse_2_pressed = false;
} options; } options;
std::array<float, 3> pos; std::array<float, 3> pos;
std::array<float, 2> angle; std::array<float, 2> angle;
@@ -83,6 +85,7 @@ namespace fmri
void move(unsigned char key, bool sprint); void move(unsigned char key, bool sprint);
void updateVisualisers(); void updateVisualisers();
void idleFunc();
std::string debugInfo() const; std::string debugInfo() const;
void renderOverlayText() const; void renderOverlayText() const;