Added camera!

- Can be translated locally or moved to a point in the world
 - Rotates locally around local x- and z-axis and around global y-axis.

Added key checks to test camera movement.

Added Quaternions (Inherits from CoordinatesVector<double,4>) with a view to handling the camera orientation.

Added equality operators for CoordinatesVectors.

Removed slow `glutGet()` calls.
Added custom reshape callback as we now store the window parameters to avoid some `glutGet()` calls.

Renamed `KeyStateManager` to `InputStatus` as it handles more than key states now.

Mouse movement callback now captures the cursor, handles its re-centering and when the cursor enters the window far away from its last position.

TODO : Consider limiting rotations for the camera (Prevents flipping the head around)
This commit is contained in:
Teo-CD 2019-10-28 23:45:44 +01:00 committed by trotFunky
parent e79f88bb9b
commit 4a5b0f5829
11 changed files with 494 additions and 174 deletions

44
src/Camera.h Normal file
View file

@ -0,0 +1,44 @@
//
// Created by trotfunky on 19/10/2019.
//
#ifndef TESTS_OPENGL_CAMERA_H
#define TESTS_OPENGL_CAMERA_H
#include <cmath>
#include <GL/glu.h>
#include "Quaternion.h"
#include "Vectors.h"
class Camera {
public:
Camera(const Vec3d& eye_pos,const Vec3d& look_direction,const Vec3d& up_vector);
/// Translates the camera relative to its current position and look direction.
/// \param translation Translation where x is pointing in the direction of vision.
void translate(const Vec3d& translation);
/// Rotates the gaze around its local x and z but around global y, relatively to the current orientation.
/// This is to provide a coherent movement in regards to mouse movement.
/// \param rotation Angles are radians to rotate about each axis.
void rotate(const Vec3d& rotation);
/// Calls the gluLookAt function for the camera.
void look();
void set_position(const Vec3d& eye_pos);
private:
Vec3d eye;
Vec3d gaze;
Vec3d gaze_up;
/// Quaternion from the world coordinates to the local coordinates
Quaternion rotation_quaternion;
/// Compute rotation quaternion from the global coordinates to the local coordinates.
/// As per https://math.stackexchange.com/questions/2122668/calculate-orientation-quaternion-given-two-axes-of-a-coordinate-system
void compute_base_change();
};
#endif //TESTS_OPENGL_CAMERA_H