mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add camera and player class
This commit is contained in:
@@ -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);
|
||||
|
||||
41
include/Cubed/gameplay/player.hpp
Normal file
41
include/Cubed/gameplay/player.hpp
Normal 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);
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user