chore: remove dead code

This commit is contained in:
2026-03-05 21:25:12 +08:00
parent f56e5aaa51
commit 02127c1e01
4 changed files with 58 additions and 87 deletions

View File

@@ -37,7 +37,7 @@ void updateMoveCamera() {
void cameraInit() { 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) { void changeView(float offsetX, float offsetY) {

View File

@@ -23,62 +23,59 @@ bool blockPresent[WORLD_SIZE_X][WORLD_SIZE_Z] = {false};
GLuint renderingProgram; GLuint renderingProgram;
GLuint vao[numVAOs]; GLuint vao[numVAOs];
GLuint vbo[numVBOs]; GLuint vbo[numVBOs];
GLuint pyrTexture; GLuint mvLoc, projLoc;
float cubLocX, cubLocY, cubLocZ;
float pyLocX, pyLocY, pyLocZ;
GLuint mvLoc, projLoc, tfLoc;
int width ,height; int width ,height;
float aspect; float aspect;
glm::mat4 pMat, vMat, mMat, mvMat; glm::mat4 pMat, vMat, mMat, mvMat;
float inc = 0.01f; float inc = 0.01f;
float tf = 0.0f; float tf = 0.0f;
glm::mat4 tMat, rMat, sMat; glm::mat4 tMat, rMat;
std::vector<GLuint> grass_block_texture(6); std::vector<GLuint> grass_block_texture(6);
void setupVertices(void) { void setupVertices(void) {
float verticesPos[108] = { float verticesPos[108] = {
// ===== 前面 (z = +1) ===== // ===== front (z = +1) =====
-0.5f, -0.5f, 0.5f, // 左下 -0.5f, -0.5f, 0.5f, // bottom left
-0.5f, 0.5f, 0.5f, // 左上 -0.5f, 0.5f, 0.5f, // top left
0.5f, 0.5f, 0.5f, // 右上 0.5f, 0.5f, 0.5f, // top right
0.5f, 0.5f, 0.5f, // 右上 0.5f, 0.5f, 0.5f, // top right
0.5f, -0.5f, 0.5f, // 右下 0.5f, -0.5f, 0.5f, // bottom right
-0.5f, -0.5f, 0.5f, // 左下 -0.5f, -0.5f, 0.5f, // bottom left
// ===== 右面 (x = +1) ===== // ===== right (x = +1) =====
0.5f, -0.5f, 0.5f, // 前下 0.5f, -0.5f, 0.5f, // bottom front
0.5f, -0.5f, -0.5f, // 后下 0.5f, -0.5f, -0.5f, // bottom back
0.5f, 0.5f, -0.5f, // 后上 0.5f, 0.5f, -0.5f, // top back
0.5f, 0.5f, -0.5f, // 后上 0.5f, 0.5f, -0.5f, // top back
0.5f, 0.5f, 0.5f, // 前上 0.5f, 0.5f, 0.5f, // top front
0.5f, -0.5f, 0.5f, // 前下 0.5f, -0.5f, 0.5f, // bottom front
// ===== 后面 (z = -1) ===== // ===== back (z = -1) =====
-0.5f, -0.5f, -0.5f, // 左下 -0.5f, -0.5f, -0.5f, // bottom left
0.5f, -0.5f, -0.5f, // 右下 0.5f, -0.5f, -0.5f, // bottom right
0.5f, 0.5f, -0.5f, // 右上 0.5f, 0.5f, -0.5f, // top right
0.5f, 0.5f, -0.5f, // 右上 0.5f, 0.5f, -0.5f, // top right
-0.5f, 0.5f, -0.5f, // 左上 -0.5f, 0.5f, -0.5f, // top left
-0.5f, -0.5f, -0.5f, // 左下 -0.5f, -0.5f, -0.5f, // bottom left
// ===== 左面 (x = -1) ===== // ===== left (x = -1) =====
-0.5f, -0.5f, -0.5f, // 后下 -0.5f, -0.5f, -0.5f, // bottom back
-0.5f, -0.5f, 0.5f, // 前下 -0.5f, -0.5f, 0.5f, // bottom front
-0.5f, 0.5f, 0.5f, // 前上 -0.5f, 0.5f, 0.5f, // top front
-0.5f, 0.5f, 0.5f, // 前上 -0.5f, 0.5f, 0.5f, // top front
-0.5f, 0.5f, -0.5f, // 后上 -0.5f, 0.5f, -0.5f, // top back
-0.5f, -0.5f, -0.5f, // 后下 -0.5f, -0.5f, -0.5f, // bottom back
// ===== 上面 (y = +1) ===== // ===== top (y = +1) =====
-0.5f, 0.5f, -0.5f, // 后左 -0.5f, 0.5f, -0.5f, // back left
0.5f, 0.5f, -0.5f, // 后右 0.5f, 0.5f, -0.5f, // back right
0.5f, 0.5f, 0.5f, // 前右 0.5f, 0.5f, 0.5f, // front right
0.5f, 0.5f, 0.5f, // 前右 0.5f, 0.5f, 0.5f, // front right
-0.5f, 0.5f, 0.5f, // 前左 -0.5f, 0.5f, 0.5f, // front left
-0.5f, 0.5f, -0.5f, // 后左 -0.5f, 0.5f, -0.5f, // back left
// ===== 下面 (y = -1) ===== // ===== bottom (y = -1) =====
-0.5f, -0.5f, 0.5f, // 前左 -0.5f, -0.5f, 0.5f, // front left
0.5f, -0.5f, 0.5f, // 前右 0.5f, -0.5f, 0.5f, // front right
0.5f, -0.5f, -0.5f, // 后右 0.5f, -0.5f, -0.5f, // back right
0.5f, -0.5f, -0.5f, // 后右 0.5f, -0.5f, -0.5f, // back right
-0.5f, -0.5f, -0.5f, // 后左 -0.5f, -0.5f, -0.5f, // back left
-0.5f, -0.5f, 0.5f // 前左 -0.5f, -0.5f, 0.5f // front left
}; };
float tex_coords[72] { float tex_coords[72] {
@@ -156,12 +153,9 @@ GLuint createShaderProgram() {
void init(GLFWwindow* window) { void init(GLFWwindow* window) {
renderingProgram = createShaderProgram(); renderingProgram = createShaderProgram();
cubLocX = 0.0f; mvLoc = glGetUniformLocation(renderingProgram, "mv_matrix");
cubLocY = -2.0f; projLoc = glGetUniformLocation(renderingProgram, "proj_matrix");
cubLocZ = 0.0f;
pyLocX = 0.0f;
pyLocY = -2.0f;
pyLocZ = -20.0f;
cameraInit(); cameraInit();
glfwGetFramebufferSize(window, &width, &height); glfwGetFramebufferSize(window, &width, &height);
aspect = (float)width / (float)height; aspect = (float)width / (float)height;
@@ -220,28 +214,8 @@ void display(GLFWwindow* window, double currentTime) {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
glUseProgram(renderingProgram); 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]); glBindVertexArray(vao[0]);
//sMat = glm::scale(glm::mat4(1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
@@ -252,13 +226,13 @@ void display(GLFWwindow* window, double currentTime) {
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
for (int x = -16; x < 16; x++) { for (int x = 0; x < WORLD_SIZE_X; x++) {
for (int z = -16; z < 16; z++) { for (int z = 0; z < WORLD_SIZE_Z; z++) {
int ix = x + 16; int wx = x - WORLD_SIZE_X / 2;
int iz = z + 16; 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(); vMat = getCameraLookAt();
mvMat = vMat * mMat; mvMat = vMat * mMat;
glUniformMatrix4fv(mvLoc, 1, GL_FALSE, glm::value_ptr(mvMat)); 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}; 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; drawFace[0] = false;
} }
if (x < 15 && blockPresent[ix + 1][iz]) { if (x < WORLD_SIZE_X - 1 && blockPresent[x + 1][z]) {
drawFace[1] = false; drawFace[1] = false;
} }
if (z > -16 && blockPresent[ix][iz + 1]) { if (z > 0 && blockPresent[x][z - 1]) {
drawFace[2] = false; drawFace[2] = false;
} }
if (x > -16 && blockPresent[ix - 1][iz]) { if (x > 0 && blockPresent[x - 1][z]) {
drawFace[3] = false; drawFace[3] = false;
} }

View File

@@ -1,7 +1,6 @@
#version 430 #version 430
in vec2 tc; in vec2 tc;
in vec4 varyingColor;
out vec4 color; out vec4 color;
layout (binding = 0) uniform sampler2D samp; layout (binding = 0) uniform sampler2D samp;

View File

@@ -12,14 +12,12 @@ mat4 buildTranslate(float x, float y, float z);
uniform mat4 mv_matrix; uniform mat4 mv_matrix;
uniform mat4 proj_matrix; uniform mat4 proj_matrix;
out vec4 varyingColor;
layout (binding = 0) uniform sampler2D samp; layout (binding = 0) uniform sampler2D samp;
void main(void) { void main(void) {
gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0); gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0);
tc = texCoord; 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) { mat4 buildTranslate(float x, float y, float z) {