2018-06-27 05:09:30 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* 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"
|
2018-06-27 05:09:30 +02:00
|
|
|
#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;
|
|
|
|
|
2018-06-27 05:09:30 +02:00
|
|
|
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; }
|
|
|
|
|
2018-06-27 05:09:30 +02:00
|
|
|
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;
|
|
|
|
|
2018-07-07 15:46:02 +02:00
|
|
|
Inventory m_inventory{9, 4};
|
2018-06-27 05:09:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYER_HPP_
|