From 02127c1e018eb4a6e4e7edb11cff762da2edd624 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Thu, 5 Mar 2026 21:25:12 +0800 Subject: [PATCH] chore: remove dead code --- src/camera.cpp | 2 +- src/main.cpp | 140 ++++++++++++++++----------------------- src/shaders/fShader.glsl | 1 - src/shaders/vShader.glsl | 2 - 4 files changed, 58 insertions(+), 87 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index 48cb570..13afe44 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -37,7 +37,7 @@ void updateMoveCamera() { void cameraInit() { - cameraPos = glm::vec3(0.0f, 0.0f, 5.0f); + cameraPos = glm::vec3(0.0f, 2.0f, 0.0f); } void changeView(float offsetX, float offsetY) { diff --git a/src/main.cpp b/src/main.cpp index de229c6..70c31bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,62 +23,59 @@ bool blockPresent[WORLD_SIZE_X][WORLD_SIZE_Z] = {false}; GLuint renderingProgram; GLuint vao[numVAOs]; GLuint vbo[numVBOs]; -GLuint pyrTexture; -float cubLocX, cubLocY, cubLocZ; -float pyLocX, pyLocY, pyLocZ; -GLuint mvLoc, projLoc, tfLoc; +GLuint mvLoc, projLoc; int width ,height; float aspect; glm::mat4 pMat, vMat, mMat, mvMat; float inc = 0.01f; float tf = 0.0f; -glm::mat4 tMat, rMat, sMat; +glm::mat4 tMat, rMat; std::vector grass_block_texture(6); void setupVertices(void) { float verticesPos[108] = { - // ===== 前面 (z = +1) ===== - -0.5f, -0.5f, 0.5f, // 左下 - -0.5f, 0.5f, 0.5f, // 左上 - 0.5f, 0.5f, 0.5f, // 右上 - 0.5f, 0.5f, 0.5f, // 右上 - 0.5f, -0.5f, 0.5f, // 右下 - -0.5f, -0.5f, 0.5f, // 左下 - // ===== 右面 (x = +1) ===== - 0.5f, -0.5f, 0.5f, // 前下 - 0.5f, -0.5f, -0.5f, // 后下 - 0.5f, 0.5f, -0.5f, // 后上 - 0.5f, 0.5f, -0.5f, // 后上 - 0.5f, 0.5f, 0.5f, // 前上 - 0.5f, -0.5f, 0.5f, // 前下 - // ===== 后面 (z = -1) ===== - -0.5f, -0.5f, -0.5f, // 左下 - 0.5f, -0.5f, -0.5f, // 右下 - 0.5f, 0.5f, -0.5f, // 右上 - 0.5f, 0.5f, -0.5f, // 右上 - -0.5f, 0.5f, -0.5f, // 左上 - -0.5f, -0.5f, -0.5f, // 左下 - // ===== 左面 (x = -1) ===== - -0.5f, -0.5f, -0.5f, // 后下 - -0.5f, -0.5f, 0.5f, // 前下 - -0.5f, 0.5f, 0.5f, // 前上 - -0.5f, 0.5f, 0.5f, // 前上 - -0.5f, 0.5f, -0.5f, // 后上 - -0.5f, -0.5f, -0.5f, // 后下 - // ===== 上面 (y = +1) ===== - -0.5f, 0.5f, -0.5f, // 后左 - 0.5f, 0.5f, -0.5f, // 后右 - 0.5f, 0.5f, 0.5f, // 前右 - 0.5f, 0.5f, 0.5f, // 前右 - -0.5f, 0.5f, 0.5f, // 前左 - -0.5f, 0.5f, -0.5f, // 后左 - // ===== 下面 (y = -1) ===== - -0.5f, -0.5f, 0.5f, // 前左 - 0.5f, -0.5f, 0.5f, // 前右 - 0.5f, -0.5f, -0.5f, // 后右 - 0.5f, -0.5f, -0.5f, // 后右 - -0.5f, -0.5f, -0.5f, // 后左 - -0.5f, -0.5f, 0.5f // 前左 + // ===== front (z = +1) ===== + -0.5f, -0.5f, 0.5f, // bottom left + -0.5f, 0.5f, 0.5f, // top left + 0.5f, 0.5f, 0.5f, // top right + 0.5f, 0.5f, 0.5f, // top right + 0.5f, -0.5f, 0.5f, // bottom right + -0.5f, -0.5f, 0.5f, // bottom left + // ===== right (x = +1) ===== + 0.5f, -0.5f, 0.5f, // bottom front + 0.5f, -0.5f, -0.5f, // bottom back + 0.5f, 0.5f, -0.5f, // top back + 0.5f, 0.5f, -0.5f, // top back + 0.5f, 0.5f, 0.5f, // top front + 0.5f, -0.5f, 0.5f, // bottom front + // ===== back (z = -1) ===== + -0.5f, -0.5f, -0.5f, // bottom left + 0.5f, -0.5f, -0.5f, // bottom right + 0.5f, 0.5f, -0.5f, // top right + 0.5f, 0.5f, -0.5f, // top right + -0.5f, 0.5f, -0.5f, // top left + -0.5f, -0.5f, -0.5f, // bottom left + // ===== left (x = -1) ===== + -0.5f, -0.5f, -0.5f, // bottom back + -0.5f, -0.5f, 0.5f, // bottom front + -0.5f, 0.5f, 0.5f, // top front + -0.5f, 0.5f, 0.5f, // top front + -0.5f, 0.5f, -0.5f, // top back + -0.5f, -0.5f, -0.5f, // bottom back + // ===== top (y = +1) ===== + -0.5f, 0.5f, -0.5f, // back left + 0.5f, 0.5f, -0.5f, // back right + 0.5f, 0.5f, 0.5f, // front right + 0.5f, 0.5f, 0.5f, // front right + -0.5f, 0.5f, 0.5f, // front left + -0.5f, 0.5f, -0.5f, // back left + // ===== bottom (y = -1) ===== + -0.5f, -0.5f, 0.5f, // front left + 0.5f, -0.5f, 0.5f, // front right + 0.5f, -0.5f, -0.5f, // back right + 0.5f, -0.5f, -0.5f, // back right + -0.5f, -0.5f, -0.5f, // back left + -0.5f, -0.5f, 0.5f // front left }; float tex_coords[72] { @@ -155,13 +152,10 @@ GLuint createShaderProgram() { void init(GLFWwindow* window) { renderingProgram = createShaderProgram(); - - cubLocX = 0.0f; - cubLocY = -2.0f; - cubLocZ = 0.0f; - pyLocX = 0.0f; - pyLocY = -2.0f; - pyLocZ = -20.0f; + + mvLoc = glGetUniformLocation(renderingProgram, "mv_matrix"); + projLoc = glGetUniformLocation(renderingProgram, "proj_matrix"); + cameraInit(); glfwGetFramebufferSize(window, &width, &height); aspect = (float)width / (float)height; @@ -220,27 +214,7 @@ void display(GLFWwindow* window, double currentTime) { glClear(GL_DEPTH_BUFFER_BIT); glUseProgram(renderingProgram); - - - - mvLoc = glGetUniformLocation(renderingProgram, "mv_matrix"); - projLoc = glGetUniformLocation(renderingProgram, "proj_matrix"); - - /* - cameraX += inc; - if (cameraX > 1.0f) { - inc = -inc; - } - if (cameraX < -1.0f) { - inc = -inc; - } - */ - - glBindVertexArray(vao[0]); - - //sMat = glm::scale(glm::mat4(1.0f), glm::vec3(0.3f, 0.3f, 0.3f)); - glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); @@ -252,13 +226,13 @@ void display(GLFWwindow* window, double currentTime) { glEnableVertexAttribArray(1); glActiveTexture(GL_TEXTURE0); - for (int x = -16; x < 16; x++) { - for (int z = -16; z < 16; z++) { + for (int x = 0; x < WORLD_SIZE_X; x++) { + for (int z = 0; z < WORLD_SIZE_Z; z++) { - int ix = x + 16; - int iz = z + 16; + int wx = x - WORLD_SIZE_X / 2; + int wz = z - WORLD_SIZE_Z / 2; - mMat = glm::translate(glm::mat4(1.0f), glm::vec3((float)x, 0.0f, (float)z)); + mMat = glm::translate(glm::mat4(1.0f), glm::vec3((float)wx, 0.0f, (float)wz)); vMat = getCameraLookAt(); mvMat = vMat * mMat; glUniformMatrix4fv(mvLoc, 1, GL_FALSE, glm::value_ptr(mvMat)); @@ -266,16 +240,16 @@ void display(GLFWwindow* window, double currentTime) { bool drawFace[6] = {true, true, true, true, true, true}; - if (z < 15 && blockPresent[ix][iz + 1]) { + if (z < WORLD_SIZE_Z - 1&& blockPresent[x][z + 1]) { drawFace[0] = false; } - if (x < 15 && blockPresent[ix + 1][iz]) { + if (x < WORLD_SIZE_X - 1 && blockPresent[x + 1][z]) { drawFace[1] = false; } - if (z > -16 && blockPresent[ix][iz + 1]) { + if (z > 0 && blockPresent[x][z - 1]) { drawFace[2] = false; } - if (x > -16 && blockPresent[ix - 1][iz]) { + if (x > 0 && blockPresent[x - 1][z]) { drawFace[3] = false; } diff --git a/src/shaders/fShader.glsl b/src/shaders/fShader.glsl index 3d55414..a45ba36 100644 --- a/src/shaders/fShader.glsl +++ b/src/shaders/fShader.glsl @@ -1,7 +1,6 @@ #version 430 in vec2 tc; -in vec4 varyingColor; out vec4 color; layout (binding = 0) uniform sampler2D samp; diff --git a/src/shaders/vShader.glsl b/src/shaders/vShader.glsl index 04a8211..cd74ca1 100644 --- a/src/shaders/vShader.glsl +++ b/src/shaders/vShader.glsl @@ -12,14 +12,12 @@ mat4 buildTranslate(float x, float y, float z); uniform mat4 mv_matrix; uniform mat4 proj_matrix; -out vec4 varyingColor; layout (binding = 0) uniform sampler2D samp; void main(void) { gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0); tc = texCoord; - varyingColor = vec4(pos, 1.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); } mat4 buildTranslate(float x, float y, float z) {