Implement rudimentary camera movement controls.

This commit is contained in:
2017-10-20 15:42:31 +02:00
parent 501a59d00b
commit f0937f253d
3 changed files with 60 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ static void show_info_log(
LOG(INFO) << log.get() << endl; LOG(INFO) << log.get() << endl;
} }
GLuint fmri::loadTexture(DType const *data, unsigned int width, unsigned int height) GLuint fmri::loadTexture(DType const *data, int width, int height)
{ {
// Load and scale texture // Load and scale texture
vector<DType> textureBuffer(data, data + (width * height)); vector<DType> textureBuffer(data, data + (width * height));

View File

@@ -13,7 +13,7 @@ namespace fmri {
* @param height * @param height
* @return A texture reference. * @return A texture reference.
*/ */
GLuint loadTexture(DType const * data, unsigned int width, unsigned int height); GLuint loadTexture(DType const * data, int width, int height);
/** /**
* *

View File

@@ -4,7 +4,6 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
#include <map> #include <map>
#include <tuple>
#include "LayerData.hpp" #include "LayerData.hpp"
#include "Options.hpp" #include "Options.hpp"
@@ -14,11 +13,20 @@
using namespace std; using namespace std;
using namespace fmri; using namespace fmri;
struct { struct
{
optional<vector<string>> labels; optional<vector<string>> labels;
vector<vector<LayerData>> data; vector<vector<LayerData>> data;
float angle = 0; float angle = 0;
map<tuple<string, int, int>, GLuint> textureMap; map<tuple<string, int, int>, GLuint> textureMap;
struct
{
float pitch = 0;
float yaw = 0;
float x = 0, y = 0, z = 0;
} camera;
} rendererData; } rendererData;
static vector<vector<LayerData>> getSimulationData(const Options &options) static vector<vector<LayerData>> getSimulationData(const Options &options)
@@ -51,8 +59,8 @@ static void render()
// Reset transformations // Reset transformations
glLoadIdentity(); glLoadIdentity();
// Set the camera // Set the camera
gluLookAt( 0.0f, 0.0f, 10.0f, gluLookAt(rendererData.camera.x, rendererData.camera.y, rendererData.camera.z - 10,
0.0f, 0.0f, 0.0f, rendererData.camera.x, rendererData.camera.y, rendererData.camera.z,
0.0f, 1.0f, 0.0f); 0.0f, 1.0f, 0.0f);
glRotatef(rendererData.angle, 0.0f, 1.0f, 0.0f); glRotatef(rendererData.angle, 0.0f, 1.0f, 0.0f);
@@ -100,9 +108,41 @@ static void reloadTextures(unsigned dataIndex)
} }
} }
static void handleKeys(unsigned char key, int, int)
{
constexpr float rotationScaling = 0.2f;
constexpr float movementScaling = 0.2f;
switch (key) {
case 'a':
// TODO: handle rotations
rendererData.camera.x += movementScaling;
break;
case 'd':
rendererData.camera.x -= rotationScaling;
break;
case 'w':
rendererData.camera.z += movementScaling;
break;
case 's':
rendererData.camera.z -= movementScaling;
break;
case 'q':
// Utility quit function.
exit(0);
default:
LOG(INFO) << "Received key: " << key << endl;
break;
}
}
int main(int argc, char * argv[]) { int main(int argc, char *argv[])
{
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler(); google::InstallFailureSignalHandler();
@@ -119,6 +159,7 @@ int main(int argc, char * argv[]) {
glutDisplayFunc(render); glutDisplayFunc(render);
glutIdleFunc(render); glutIdleFunc(render);
glutReshapeFunc(changeWindowSize); glutReshapeFunc(changeWindowSize);
glutKeyboardFunc(handleKeys);
glewInit(); glewInit();
if (!GLEW_VERSION_2_0) { if (!GLEW_VERSION_2_0) {