2018-06-27 05:09:30 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2019-01-23 00:04:03 +01:00
|
|
|
* Filename: ClientPlayer.hpp
|
2018-06-27 05:09:30 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Created: 27/06/2018 04:56:19
|
|
|
|
*
|
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
2019-01-23 00:04:03 +01:00
|
|
|
#ifndef CLIENTPLAYER_HPP_
|
|
|
|
#define CLIENTPLAYER_HPP_
|
2018-06-27 05:09:30 +02:00
|
|
|
|
2018-12-25 23:14:39 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
#include <gk/gl/Camera.hpp>
|
|
|
|
|
2019-01-23 00:04:03 +01:00
|
|
|
#include "Player.hpp"
|
2018-06-27 05:09:30 +02:00
|
|
|
|
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
|
|
|
|
|
2019-01-12 19:49:41 +01:00
|
|
|
class ClientWorld;
|
2018-12-25 23:14:39 +01:00
|
|
|
|
2019-01-23 00:04:03 +01:00
|
|
|
class ClientPlayer : public Player {
|
2018-06-27 05:09:30 +02:00
|
|
|
public:
|
2019-01-23 00:04:03 +01:00
|
|
|
ClientPlayer(gk::Camera &camera);
|
2018-12-25 23:14:39 +01:00
|
|
|
|
|
|
|
void turnH(float angle);
|
|
|
|
void turnV(float angle);
|
|
|
|
|
|
|
|
void move(float direction);
|
|
|
|
|
|
|
|
void processInputs();
|
2019-01-12 19:49:41 +01:00
|
|
|
void updatePosition(const ClientWorld &world);
|
2018-12-25 23:14:39 +01:00
|
|
|
|
2019-01-12 19:49:41 +01:00
|
|
|
void checkCollisions(const ClientWorld &world);
|
2018-12-25 23:14:39 +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; }
|
|
|
|
|
2019-01-23 00:04:03 +01:00
|
|
|
static ClientPlayer &getInstance() { return *s_instance; }
|
|
|
|
static void setInstance(ClientPlayer *instance) { s_instance = instance; }
|
2018-12-25 23:14:39 +01:00
|
|
|
|
|
|
|
float x() const { return m_x; }
|
|
|
|
float y() const { return m_y; }
|
|
|
|
float z() const { return m_z; }
|
|
|
|
|
2018-12-30 04:40:05 +01:00
|
|
|
const gk::Camera &camera() { return m_camera; }
|
|
|
|
|
2018-06-27 05:09:30 +02:00
|
|
|
private:
|
2019-01-12 19:49:41 +01:00
|
|
|
void testPoint(const ClientWorld &world, glm::vec3 pos, glm::vec3 &speed);
|
2018-12-25 23:14:39 +01:00
|
|
|
|
2019-01-23 00:04:03 +01:00
|
|
|
static ClientPlayer *s_instance;
|
2018-12-25 23:14:39 +01:00
|
|
|
|
2018-12-30 04:32:29 +01:00
|
|
|
gk::Camera &m_camera;
|
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;
|
2018-12-29 04:51:37 +01:00
|
|
|
const float m_jumpSpeed = 0.06f;
|
2018-06-27 05:09:30 +02:00
|
|
|
};
|
|
|
|
|
2019-01-23 00:04:03 +01:00
|
|
|
#endif // CLIENTPLAYER_HPP_
|