refactor(input): use relative mouse motion and simplify camera mouse update

This commit is contained in:
2026-07-17 11:40:54 +08:00
parent 3d1183e986
commit 7461dd766e
7 changed files with 22 additions and 22 deletions

View File

@@ -13,7 +13,7 @@ class App {
public:
App();
~App();
void handle_cursor_position(float xpos, float ypos);
void handle_mouse_move(float xpos, float ypos, float xrel, float yrel);
void handle_sdl_key(SDL_Event& e);
void handle_sdl_mouse_button(SDL_Event& e);
void handle_window_focus(bool focused);

View File

@@ -39,7 +39,7 @@ public:
void camera_init(ClientPlayer* player);
void hot_reload();
void reset_camera();
void update_cursor_position_camera(double xpos, double ypos);
void update_cursor_position_camera(float offset_x, float offset_y);
const glm::mat4 get_camera_lookat() const;
const glm::vec3& get_camera_pos() const;

View File

@@ -11,8 +11,10 @@ namespace Cubed {
struct MouseMoveEvent {
float xpos;
float ypos;
MouseMoveEvent(float x, float y) : xpos(x), ypos(y) {}
float xrel;
float yrel;
MouseMoveEvent(float x, float y, float dx, float dy)
: xpos(x), ypos(y), xrel(dx), yrel(dy) {}
};
struct MouseButtonEvent {

View File

@@ -41,14 +41,17 @@ public:
void set_vsync(bool enable);
int width() const;
int height() const;
private:
bool m_mouse_enable = true;
bool m_imgui_init = false;
bool m_game_running = false;
SDL_Window* m_window;
SDL_GLContext m_context;
int m_window_width;
int m_window_height;
int m_window_width = 0;
int m_window_height = 0;
Config& m_config;
Camera* m_camera = nullptr;
bool m_imgui_enable = false;