mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: smooth camera movement
This commit is contained in:
@@ -22,7 +22,7 @@ private:
|
|||||||
|
|
||||||
float m_sensitivity = 0.05f;
|
float m_sensitivity = 0.05f;
|
||||||
|
|
||||||
float m_speed = 0.1f;
|
float m_speed = 10.0f;
|
||||||
// player is tow block tall, the pos is the lower pos
|
// player is tow block tall, the pos is the lower pos
|
||||||
glm::vec3 m_player_pos = glm::vec3(0.0f, 5.0f, 0.0f);
|
glm::vec3 m_player_pos = glm::vec3(0.0f, 5.0f, 0.0f);
|
||||||
glm::vec3 m_front = glm::vec3(0, 0, -1);
|
glm::vec3 m_front = glm::vec3(0, 0, -1);
|
||||||
|
|||||||
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
#include <Cubed/gameplay/player.hpp>
|
#include <Cubed/gameplay/player.hpp>
|
||||||
|
|
||||||
static constexpr float UPDATE_TIME = 0.005f;
|
|
||||||
static float current_time = 0.0f;
|
|
||||||
|
|
||||||
|
|
||||||
Player::Player() {
|
Player::Player() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -32,29 +28,25 @@ void Player::set_player_pos(const glm::vec3& pos) {
|
|||||||
|
|
||||||
void Player::update(float delta_time) {
|
void Player::update(float delta_time) {
|
||||||
|
|
||||||
current_time += delta_time;
|
|
||||||
if (current_time < UPDATE_TIME) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
current_time = 0.0f;
|
|
||||||
m_right = glm::normalize(glm::cross(m_front, glm::vec3(0.0f, 1.0f, 0.0f)));
|
m_right = glm::normalize(glm::cross(m_front, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||||
|
float speed = m_speed * delta_time;
|
||||||
if (m_move_state.forward) {
|
if (m_move_state.forward) {
|
||||||
m_player_pos += glm::vec3(m_front.x, 0.0f, m_front.z) * m_speed;
|
m_player_pos += glm::vec3(m_front.x, 0.0f, m_front.z) * speed;
|
||||||
}
|
}
|
||||||
if (m_move_state.back) {
|
if (m_move_state.back) {
|
||||||
m_player_pos -= glm::vec3(m_front.x, 0.0f, m_front.z) * m_speed;
|
m_player_pos -= glm::vec3(m_front.x, 0.0f, m_front.z) * speed;
|
||||||
}
|
}
|
||||||
if (m_move_state.left) {
|
if (m_move_state.left) {
|
||||||
m_player_pos -= glm::vec3(m_right.x, 0.0f, m_right.z) * m_speed;
|
m_player_pos -= glm::vec3(m_right.x, 0.0f, m_right.z) * speed;
|
||||||
}
|
}
|
||||||
if (m_move_state.right) {
|
if (m_move_state.right) {
|
||||||
m_player_pos += glm::vec3(m_right.x, 0.0f, m_right.z) * m_speed;
|
m_player_pos += glm::vec3(m_right.x, 0.0f, m_right.z) * speed;
|
||||||
}
|
}
|
||||||
if (m_move_state.up) {
|
if (m_move_state.up) {
|
||||||
m_player_pos += glm::vec3(0.0f, 1.0f, 0.0f) * m_speed;
|
m_player_pos += glm::vec3(0.0f, 1.0f, 0.0f) * speed;
|
||||||
}
|
}
|
||||||
if (m_move_state.down) {
|
if (m_move_state.down) {
|
||||||
m_player_pos -= glm::vec3(0.0f, 1.0f, 0.0f) * m_speed;
|
m_player_pos -= glm::vec3(0.0f, 1.0f, 0.0f) * speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user