mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat: player rendering (#27)
* refactor(player): extract player rendering into PlayerRenderer class Move player rendering code from Renderer to new PlayerRenderer class. Add normal and tangent vertex attributes for improved per-pixel lighting. * feat(player-renderer): add shadow rendering and include local player data * feat(gameplay): add player yaw/pitch synchronization and rendering * refactor(player_renderer): split rendering into per-body-part VAOs and VBOs Move `PlayerVertex` struct to header and replace single VAO/VBO with arrays of 6 parts. Implement head pitch rotation in `render()` and `shadow_render()` by applying a separate model matrix for the head (index 0). Remove old `vao()` and `sum()` accessors. Adjust model translation for consistency. * feat(player): add texture mapping to player model using skin * fix(player-renderer): correct player rendering rotation and texture coordinates * feat(gameplay): add player gait system with limb animation * fix(player): update leg UVs and remove yaw wrap Update left and right leg UV coordinates to align with updated player texture. Remove yaw modulo operation to allow unrestricted yaw rotation beyond 360 degrees. * feat(camera): add third-person perspective and walk animation - Introduce Perspective enum (FIRST_PERSON, THIRD_PERSON_BACK, THIRD_PERSON_FRONT) and m_front member for camera direction. - Handle F5 key to cycle perspectives. - Add angle and walk_time to ClientPlayer for walking animation. - Update player rendering to skip local player only in first person and fix rotation sign. - Remove redundant player info reporting; update player data with animation angle. * fix(camera): replace magic number with constant and fix missing break * fix(client-player): stop sprinting on forward key release * feat: add camera collision and sphere collision for world * fix(skin): update player001 texture * refactor(gameplay): improve thread safety and remove debug logging * refactor(shaders): extract shadow and normal logic into include files and add lighting to player shaders * chore(shader): remove unused uniforms cameraPos and specularStrength * fix: inlcude <array> header
This commit is contained in:
@@ -14,6 +14,7 @@ constexpr int CROSS_PLANE_SIZE = 16;
|
||||
constexpr int BLOCK_ITEM_SIZE = 16;
|
||||
constexpr int UI_SIZE = 16;
|
||||
constexpr int BLOCK_STATUS_SIZE = 16;
|
||||
constexpr int SKIN_SIZE = 64;
|
||||
|
||||
unsigned char* generate_flat_normal_map(int width = BLOCK_NORMAL_SIZE,
|
||||
int height = BLOCK_NORMAL_SIZE) {
|
||||
@@ -44,6 +45,7 @@ void TextureManager::delet_texture() {
|
||||
for (auto& id : m_item_textures) {
|
||||
glDeleteTextures(1, &id);
|
||||
}
|
||||
glDeleteTextures(1, &m_skin);
|
||||
Logger::info("Successfully delete all texture");
|
||||
}
|
||||
}
|
||||
@@ -67,6 +69,8 @@ const std::vector<GLuint>& TextureManager::item_textures() const {
|
||||
return m_item_textures;
|
||||
}
|
||||
|
||||
GLuint TextureManager::get_skin() const { return m_skin; }
|
||||
|
||||
void TextureManager::load_block_status(unsigned id) {
|
||||
|
||||
ASSERT_MSG(id < MAX_BLOCK_STATUS, "Exceed the max status sum limit");
|
||||
@@ -279,6 +283,31 @@ void TextureManager::init_ui() {
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
void TextureManager::init_skin() {
|
||||
|
||||
glGenTextures(1, &m_skin);
|
||||
glBindTexture(GL_TEXTURE_2D, m_skin);
|
||||
std::string path = "texture/skin/player001.png";
|
||||
unsigned char* image_data = nullptr;
|
||||
image_data = (Tools::load_image_data(path));
|
||||
glBindTexture(GL_TEXTURE_2D, m_skin);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SKIN_SIZE, SKIN_SIZE, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, image_data);
|
||||
Tools::delete_image_data(image_data);
|
||||
glBindTexture(GL_TEXTURE_2D, m_skin);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR_MIPMAP_LINEAR);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
if (m_aniso >= 1) {
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY,
|
||||
static_cast<GLfloat>(m_aniso));
|
||||
}
|
||||
}
|
||||
|
||||
void TextureManager::init_block_status() {
|
||||
glGenTextures(1, &m_block_status_array);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array);
|
||||
@@ -315,6 +344,7 @@ void TextureManager::init_texture() {
|
||||
init_block();
|
||||
init_block_status();
|
||||
init_ui();
|
||||
init_skin();
|
||||
m_init = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user