handmade/include/camera.h

72 lines
2.2 KiB
C
Raw Normal View History

#pragma once
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/mat4x4.hpp>
/**
* Default camera values
*/
#define DEFAULT_CAMERA_YAW (-90.0f)
#define DEFAULT_CAMERA_PITCH (0.0f)
#define DEFAULT_CAMERA_ROLL (0.0f)
#define DEFAULT_CAMERA_SPEED (1.0f)
#define DEFAULT_CAMERA_SENSITIVITY (1.0f)
#define DEFAULT_CAMERA_JOYSENSITIVITY (1.0f)
#define DEFAULT_CAMERA_ZOOM (45.0f)
/*
* Decelerate at gravity speed (9.8 m/s) / ???
*/
#define DEFAULT_CAMERA_DECELERATIONSPEED (0.98f)
#define DEFAULT_CAMERA_MOUSEDECELERATIONSPEED (0.098f)
class Camera
{
/**
* An abstract camera class that processes input and calculates the corresponding
*/
glm::vec3 Position;
glm::vec3 Front;
glm::vec3 Right;
glm::vec3 Up;
glm::vec3 WorldUp;
/** Euler Angles, Vectors and Matrices for use in OpenGL. */
glm::vec3 Angles;
/* XXX Maybe we shouldn't let the camera move? */
glm::vec3 Direction; /* Position movement */
glm::vec2 ViewDirection; /* Yaw, Pitch movement */
void updateCameraVectors (void);
public:
/**
* Defines several possible options for camera movement.
* Used as abstraction to stay away from window-system specific input methods
*/
enum Movement
{
FORWARD, BACKWARD, LEFT, RIGHT, UP, DOWN, CW, CCW, NONE
};
/** Camera options */
float MovementSpeed, MouseSensitivity, Zoom;
float DecelerationSpeed, ViewDecelerationSpeed, JoystickSensitivity;
float zNear, zFar;
Camera (
const glm::vec3 position = glm::vec3(0.0f, 0.0f, 1.0f)
, const glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f)
, const float yaw = DEFAULT_CAMERA_YAW
, const float pitch = DEFAULT_CAMERA_PITCH
, const float roll = DEFAULT_CAMERA_ROLL);
glm::mat4 GetViewMatrix (const bool constrainPitch = true);
void ProcessJoystickMovement (const float xoffset, const float yoffset, const float deltaTime);
void ProcessKeyboard (const Camera::Movement direction, const float deltaTime);
void ProcessMouseMovement (const float xoffset, const float yoffset, const float deltaTime);
void ProcessMouseScroll (const float xoffset, const float yoffset, const float deltaTime);
};