Implement movement with the mouse.
This commit is contained in:
@@ -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);
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<float, 3> pos;
|
||||
std::array<float, 2> 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;
|
||||
|
||||
Reference in New Issue
Block a user