Fix camera controls.
Now actually move according to the camera direction, rather than a fixed direction.
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -23,15 +25,20 @@ static void move(unsigned char key)
|
|||||||
{
|
{
|
||||||
float speed = 0.5;
|
float speed = 0.5;
|
||||||
float dir[3];
|
float dir[3];
|
||||||
// Currently very buggy
|
|
||||||
|
const auto yaw = deg2rad(camera.angle[0]);
|
||||||
|
const auto pitch = deg2rad(camera.angle[1]);
|
||||||
|
|
||||||
|
cerr << camera.infoLine() << endl;
|
||||||
|
|
||||||
if (key == 'w' || key == 's') {
|
if (key == 'w' || key == 's') {
|
||||||
dir[0] = 0;
|
dir[0] = sin(yaw) * cos(pitch);
|
||||||
dir[1] = 0;
|
dir[1] = -sin(pitch);
|
||||||
dir[2] = -1;
|
dir[2] = -cos(yaw) * cos(pitch);
|
||||||
} else {
|
} else {
|
||||||
dir[0] = -1;
|
dir[0] = -cos(yaw) * cos(pitch);
|
||||||
dir[1] = 0;
|
dir[1] = -sin(pitch);
|
||||||
dir[2] = 0;
|
dir[2] = sin(yaw) * cos(pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == 's' || key == 'd') {
|
if (key == 's' || key == 'd') {
|
||||||
|
|||||||
Reference in New Issue
Block a user