feat: add run and walk gait

This commit is contained in:
2026-04-05 21:47:32 +08:00
parent 061b72b740
commit 82f0e1deae
7 changed files with 51 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ constexpr int CHUCK_SIZE = 16;
constexpr int DISTANCE = 16;
constexpr int MAX_BLOCK_STATUS = 1;
constexpr int MAX_CHARACTER = 128;
constexpr float FOV = 70.0f;
constexpr float NORMAL_FOV = 70.0f;
constexpr int SEED = 999;

View File

@@ -9,10 +9,17 @@
#include <optional>
#include <string>
enum class Gait{
WALK,
RUN
};
class World;
class Player {
private:
constexpr static float WALK_SPEED = 4.5f;
constexpr static float RUN_SPEED = 7.0f;
constexpr static float ACCELERATION = 10.0f;
constexpr static float DECELERATION = 15.0f;
constexpr static float G = 22.5f;
@@ -23,8 +30,7 @@ private:
float m_sensitivity = 0.15f;
//float max_speed = 4.5f;
float max_speed = 7.5f;
float max_speed = WALK_SPEED;
float y_speed = 0.0f;
bool can_up = true;
@@ -41,6 +47,7 @@ private:
glm::vec3 m_front {0, 0, -1};
glm::vec3 m_right {0, 0, 0};
glm::vec3 m_size {0.6f, 1.8f, 0.6f};
Gait m_gait = Gait::WALK;
MoveState m_move_state {};
std::optional<LookBlock> m_look_block = std::nullopt;
@@ -61,6 +68,7 @@ public:
~Player();
AABB get_aabb() const;
const glm::vec3& get_front() const;
const Gait& get_gait() const;
const std::optional<LookBlock>& get_look_block_pos() const;
const glm::vec3& get_player_pos() const;
const MoveState& get_move_state() const;

View File

@@ -19,7 +19,6 @@ private:
std::pair<int, int> chunk_pos(int world_x, int world_z);
void gen_chunks();
public:

View File

@@ -19,6 +19,7 @@ public:
void init();
const Shader& get_shader(const std::string& name) const;
void render();
void update_fov(float fov);
void update_proj_matrix(float aspect, float width, float height);
private:
@@ -26,6 +27,8 @@ private:
const TextureManager& m_texture_manager;
World& m_world;
float m_aspect = 0.0f;
float m_fov = NORMAL_FOV;
glm::mat4 m_p_mat, m_v_mat, m_m_mat, m_mv_mat, m_mvp_mat;
GLuint m_mv_loc;