Implement dynamically enabling layer/interaction rendering.

Refs #2.
This commit is contained in:
2018-03-29 14:56:17 +02:00
parent 1ffbfda2d9
commit 59ecb91713
2 changed files with 31 additions and 12 deletions

View File

@@ -9,6 +9,11 @@
using namespace fmri; using namespace fmri;
static inline void toggle(bool& b)
{
b = !b;
}
static float getFPS() static float getFPS()
{ {
static int frames = 0; static int frames = 0;
@@ -27,7 +32,7 @@ static float getFPS()
return fps; return fps;
} }
void RenderingState::move(unsigned char key) void RenderingState::move(unsigned char key, bool sprint)
{ {
float speed = 0.5f; float speed = 0.5f;
std::array<float, 3> dir; std::array<float, 3> dir;
@@ -49,7 +54,7 @@ void RenderingState::move(unsigned char key)
speed *= -1; speed *= -1;
} }
if (glutGetModifiers() & GLUT_ACTIVE_SHIFT) { if (sprint) {
speed *= 2; speed *= 2;
} }
@@ -65,14 +70,21 @@ void RenderingState::handleKey(unsigned char x)
case 'a': case 'a':
case 's': case 's':
case 'd': case 'd':
move(x); move(x, false);
break; break;
case 'W': case 'W':
case 'A': case 'A':
case 'S': case 'S':
case 'D': case 'D':
move(static_cast<unsigned char>(std::tolower(x))); move(static_cast<unsigned char>(std::tolower(x)), true);
break;
case 'l':
toggle(options.renderLayers);
break;
case 'i':
toggle(options.renderInteractions);
break; break;
case 'q': case 'q':
@@ -204,8 +216,10 @@ void RenderingState::render(float time) const
for (auto i : Range(currentData->size())) { for (auto i : Range(currentData->size())) {
glPushMatrix(); glPushMatrix();
renderLayerName(currentData->at(i).name()); renderLayerName(currentData->at(i).name());
layerVisualisations[i]->render(); if (options.renderLayers) {
if (i < interactionAnimations.size() && interactionAnimations[i]) { layerVisualisations[i]->render();
}
if (options.renderInteractions && i < interactionAnimations.size() && interactionAnimations[i]) {
interactionAnimations[i]->draw(time); interactionAnimations[i]->draw(time);
} }
@@ -229,10 +243,13 @@ void RenderingState::renderOverlayText() const
if (options.showHelp) { if (options.showHelp) {
overlayText << "Controls:\n" overlayText << "Controls:\n"
"WASD: move\n" "wasd: move\n"
"shift: move faster\n" "shift: move faster\n"
"F1: toggle this help message\n" "F1: toggle this help message\n"
"F2: toggle debug info\n"; "F2: toggle debug info\n"
"l: toggle layers visible\n"
"i: toggle interactions visible\n"
"q: quit\n";
} }
glLoadIdentity(); glLoadIdentity();
@@ -273,12 +290,12 @@ void RenderingState::handleSpecialKey(int key)
break; break;
case GLUT_KEY_F1: case GLUT_KEY_F1:
options.showHelp = !options.showHelp; toggle(options.showHelp);
glutPostRedisplay(); glutPostRedisplay();
break; break;
case GLUT_KEY_F2: case GLUT_KEY_F2:
options.showDebug = !options.showDebug; toggle(options.showDebug);
break; break;
default: default:

View File

@@ -46,6 +46,8 @@ namespace fmri
struct { struct {
bool showDebug = false; bool showDebug = false;
bool showHelp = true; bool showHelp = true;
bool renderLayers = true;
bool renderInteractions = true;
} options; } options;
std::array<float, 3> pos; std::array<float, 3> pos;
std::array<float, 2> angle; std::array<float, 2> angle;
@@ -59,7 +61,7 @@ namespace fmri
void configureRenderingContext() const; void configureRenderingContext() const;
void move(unsigned char key); void move(unsigned char key, bool sprint);
void updateVisualisers(); void updateVisualisers();
std::string debugInfo() const; std::string debugInfo() const;