voxspatium/src/Camera.h

89 lines
2.8 KiB
C++

// Voxspatium Engine - Voxel Planets engine
// Copyright (C) 2018 Evert "Diamond" Prants <evert@lunasqu.ee>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef __CAMERA_H__
#define __CAMERA_H__
#include "util/Common.h"
#include "Shader.h"
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
enum Camera_Movement {
FORWARD,
BACKWARD,
LEFT,
RIGHT
};
// Default camera values
const GLfloat YAW = -90.0f;
const GLfloat PITCH = 0.0f;
const GLfloat ROLL = 0.0f;
const GLfloat SPEED = 3.0f;
const GLfloat SENSITIVTY = 0.25f;
const GLfloat ZOOM = 45.0f;
class Camera
{
public:
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), GLfloat yaw = YAW, GLfloat pitch = PITCH, GLfloat roll = ROLL);
Camera(GLfloat posX, GLfloat posY, GLfloat posZ, GLfloat upX, GLfloat upY, GLfloat upZ, GLfloat yaw, GLfloat pitch, GLfloat roll);
~Camera();
glm::mat4 getViewMatrix(void);
void processKeyboard(Camera_Movement direction, GLfloat deltaTime);
void processMouseMovement(GLfloat xoffset, GLfloat yoffset, GLboolean constrainPitch);
void processMouseScroll(GLfloat yoffset);
void shaderViewProjection(Shader& shader);
inline GLfloat getFOV() const { return m_zoom; }
inline glm::vec3 getPosition(void) const { return m_position; }
bool frustumContainsPoint(const glm::vec3 &point) const;
int frustumContainsSphere(const glm::vec3 &position, const double radius) const;
int frustumContainsBox(const glm::vec3 &min, const glm::vec3 &max) const;
int frustumContainsPolygon(const std::vector<glm::vec3> &points) const;
private:
glm::vec3 m_position;
glm::vec3 m_front;
glm::vec3 m_up;
glm::vec3 m_right;
glm::vec3 m_worldUp;
// Eular Angles
GLfloat m_yaw;
GLfloat m_pitch;
GLfloat m_roll;
// Camera options
GLfloat m_movementSpeed;
GLfloat m_mouseSensitivity;
GLfloat m_zoom;
// The Projection Matrix
glm::mat4 m_projection;
// Frustum Culling
glm::vec4 m_planes[6];
float frustumDistanceToPlane(const int plane, const glm::vec3 &point) const;
void updateCameraVectors(void);
void updateProjection(void);
void updateFrustum(void);
};
#endif // __CAMERA_H__