OpenMiner/include/world/Player.hpp

85 lines
1.9 KiB
C++
Raw Normal View History

/*
* =====================================================================================
*
* Filename: Player.hpp
*
* Description:
*
* Created: 27/06/2018 04:56:19
*
* Author: Quentin Bazin, <quent42340@gmail.com>
*
* =====================================================================================
*/
#ifndef PLAYER_HPP_
#define PLAYER_HPP_
2018-12-25 23:14:39 +01:00
#include <cmath>
#include <glm/glm.hpp>
2018-12-26 17:57:46 +01:00
#include "Camera.hpp"
#include "Inventory.hpp"
2018-12-25 23:14:39 +01:00
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef RADIANS_PER_DEGREES
#define RADIANS_PER_DEGREES (M_PI / 180.0f)
#endif
class World;
class Player {
public:
2018-12-25 23:14:39 +01:00
Player();
void turnH(float angle);
void turnV(float angle);
void move(float direction);
void processInputs();
glm::mat4 updatePosition(const World &world);
void checkCollisions(const World &world);
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; }
static Player &getInstance() { return *s_instance; }
static void setInstance(Player *instance) { s_instance = instance; }
float x() const { return m_x; }
float y() const { return m_y; }
float z() const { return m_z; }
Inventory &inventory() { return m_inventory; }
private:
2018-12-25 23:14:39 +01:00
void testPoint(const World &world, glm::vec3 pos, glm::vec3 &speed);
static Player *s_instance;
2018-12-26 17:57:46 +01:00
Camera m_camera{45.0f, 0.1f, 1000.0f};
2018-12-25 23:14:39 +01:00
float m_x;
float m_y;
float m_z;
float m_angleH;
float m_angleV;
glm::vec3 m_velocity{0};
bool m_isJumping = false;
const float m_gravity = 0.001;
const float m_jumpSpeed = 0.07f;
Inventory m_inventory{9, 4};
};
#endif // PLAYER_HPP_