OpenMiner/include/gl/Camera.hpp

73 lines
1.6 KiB
C++
Raw Normal View History

2014-12-18 07:02:48 +01:00
/*
* =====================================================================================
*
* Filename: Camera.hpp
*
2018-06-05 01:24:54 +02:00
* Description:
2014-12-18 07:02:48 +01:00
*
* Created: 16/12/2014 12:21:03
*
2018-06-05 16:17:40 +02:00
* Author: Quentin Bazin, <quent42340@gmail.com>
2014-12-18 07:02:48 +01:00
*
* =====================================================================================
*/
#ifndef CAMERA_HPP_
#define CAMERA_HPP_
#include <cmath>
#include <glm/glm.hpp>
#ifndef RADIANS_PER_DEGREES
2018-06-05 16:17:40 +02:00
#define RADIANS_PER_DEGREES (M_PI / 180.0f)
#endif
2014-12-18 07:02:48 +01:00
2018-06-18 12:24:46 +02:00
class World;
2014-12-18 07:02:48 +01:00
class Camera {
public:
Camera();
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
void turnH(float angle);
void turnV(float angle);
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
void move(float direction);
2018-06-05 01:24:54 +02:00
2018-06-18 12:24:46 +02:00
glm::mat4 processInputs(const World &world);
void checkCollisions(const World &world);
2018-06-14 04:19:16 +02:00
void update();
2018-06-05 01:24:54 +02:00
2014-12-23 16:15:44 +01:00
float pointTargetedX() const { return m_x + cos(m_angleH * RADIANS_PER_DEGREES) * cos(m_angleV * RADIANS_PER_DEGREES); }
float pointTargetedY() const { return m_y + sin(m_angleV * RADIANS_PER_DEGREES); }
float pointTargetedZ() const { return m_z + sin(m_angleH * RADIANS_PER_DEGREES) * cos(m_angleV * RADIANS_PER_DEGREES) - 0.00001; }
2018-06-05 01:24:54 +02:00
2014-12-26 00:39:10 +01:00
static Camera &getInstance() {
static Camera instance;
return instance;
}
2018-06-05 01:24:54 +02:00
2014-12-26 00:39:10 +01:00
float x() const { return m_x; }
float y() const { return m_y; }
float z() const { return m_z; }
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
private:
2018-06-18 12:24:46 +02:00
void testPoint(const World &world, glm::vec3 pos, glm::vec3 &speed);
2014-12-18 07:02:48 +01:00
glm::mat4 m_viewMatrix;
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
float m_x;
float m_y;
float m_z;
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
float m_angleH;
float m_angleV;
2018-06-05 01:24:54 +02:00
2018-06-18 12:24:46 +02:00
glm::vec3 m_velocity{0};
bool m_isJumping = false;
const float m_gravity = 0.001;
const float m_jumpSpeed = 0.07f;
2014-12-18 07:02:48 +01:00
};
#endif // CAMERA_HPP_