handmade/include/camera.h

73 lines
2.1 KiB
C
Raw Normal View History

#pragma once
#include <glm/glm.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)
#define DEFAULT_CAMERA_ZNEAR (0.1f)
#define DEFAULT_CAMERA_ZFAR (1000.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 WorldUp;
/**
* ... Euler Angles, Vectors and Matrices for use in OpenGL. */
glm::vec3 Right;
glm::vec3 Up;
glm::vec3 Angles;
/* TODO combine with Object */
glm::vec3 Direction; /* Position movement */
glm::vec3 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, JoystickSensitivity, DecelerationSpeed, ViewDecelerationSpeed;
float Zoom, 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, const float, const float);
void ProcessKeyboard (const Camera::Movement, const float);
void ProcessMouseMovement (const float, const float, const float);
void ProcessMouseScroll (const float, const float, const float);
};