feat: add camera and player class

This commit is contained in:
2026-03-06 22:07:26 +08:00
parent 02127c1e01
commit 05a62e7443
6 changed files with 221 additions and 143 deletions

View File

@@ -6,24 +6,30 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
class Player;
class Camera {
private:
bool m_firseMouse = true;
Player* m_player;
float m_lastMouseX, m_lastMouseY;
glm::vec3 m_cameraPos;
public:
Camera();
void updateMoveCamera();
void cameraInit(Player* player);
void updateCursorPositionCamera(double xpos, double ypos);
const glm::mat4 getCameraLookAt() const;
struct MoveState {
bool forward = false;
bool back = false;
bool left = false;
bool right = false;
bool down = false;
bool up = false;
};
void updateMoveCamera();
void cameraInit();
void changeView(float offsetX, float offsetY);
void updateCursorPositionCamera(double xpos, double ypos);
glm::mat4 getCameraLookAt();
void updateCameraKey(int key, int action);

View File

@@ -0,0 +1,41 @@
#pragma once
#include <glm/glm.hpp>
struct MoveState {
bool forward = false;
bool back = false;
bool left = false;
bool right = false;
bool down = false;
bool up = false;
};
class Player {
private:
float m_yaw;
float m_pitch;
float m_sensitivity = 0.05f;
float m_speed = 0.1f;
// player is tow block tall, the pos is the lower pos
glm::vec3 m_playerPos;
glm::vec3 m_front = glm::vec3(0, 0, -1);
glm::vec3 m_right;
MoveState m_moveState;
public:
Player();
const glm::vec3& getFront() const;
const glm::vec3& getPlayerPos() const;
const MoveState& getMoveState() const;
void setPlayerPos(const glm::vec3& pos);
void update(float deltaTime);
void updateFrontVec(float offsetX, float offsetY);
void updatePlayerMoveState(int key, int action);
};