From 916d1c14084ac59e7c539965482679a0f23f5884 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 21 Jun 2024 01:43:26 +0300 Subject: [PATCH] update ModelBatch.box semantics --- src/graphics/render/ModelBatch.cpp | 38 +++++++++++++++--------------- src/graphics/render/ModelBatch.hpp | 8 +++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/graphics/render/ModelBatch.cpp b/src/graphics/render/ModelBatch.cpp index 6ade352a..2e056efc 100644 --- a/src/graphics/render/ModelBatch.cpp +++ b/src/graphics/render/ModelBatch.cpp @@ -48,25 +48,6 @@ ModelBatch::~ModelBatch() { } void ModelBatch::test(glm::vec3 pos, glm::vec3 size) { - float time = static_cast(Window::time()); - pushMatrix(glm::translate(glm::mat4(1.0f), pos)); - pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*7*0.1f), glm::vec3(0,1,0))); - pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*11*0.1f), glm::vec3(1,0,0))); - pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*17*0.1f), glm::vec3(0,0,1))); - pushMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, glm::sin(time*2), 0))); - box({}, size); - box({1.5f,0,0}, size*0.5f); - popMatrix(); - popMatrix(); - popMatrix(); - popMatrix(); - popMatrix(); -} - -void ModelBatch::box(glm::vec3 pos, glm::vec3 size) { - if (index + 36 < capacity*VERTEX_SIZE) { - flush(); - } glm::vec3 gpos = combined * glm::vec4(pos, 1.0f); light_t light = chunks->getLight(gpos.x, gpos.y, gpos.z); glm::vec4 lights ( @@ -76,6 +57,25 @@ void ModelBatch::box(glm::vec3 pos, glm::vec3 size) { Lightmap::extract(light, 3) / 15.0f ); + float time = static_cast(Window::time()); + pushMatrix(glm::translate(glm::mat4(1.0f), pos)); + pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*7*0.1f), glm::vec3(0,1,0))); + pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*11*0.1f), glm::vec3(1,0,0))); + pushMatrix(glm::rotate(glm::mat4(1.0f), glm::sin(time*17*0.1f), glm::vec3(0,0,1))); + pushMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, glm::sin(time*2), 0))); + box({}, size, lights); + box({1.5f,0,0}, size*0.5f, lights); + popMatrix(); + popMatrix(); + popMatrix(); + popMatrix(); + popMatrix(); +} + +void ModelBatch::box(glm::vec3 pos, glm::vec3 size, glm::vec4 lights) { + if (index + 36 < capacity*VERTEX_SIZE) { + flush(); + } plane(pos+Z*size, X*size, Y*size, Z, lights); plane(pos-Z*size, -X*size, Y*size, -Z, lights); diff --git a/src/graphics/render/ModelBatch.hpp b/src/graphics/render/ModelBatch.hpp index 8c791fc0..3028dc0e 100644 --- a/src/graphics/render/ModelBatch.hpp +++ b/src/graphics/render/ModelBatch.hpp @@ -41,7 +41,7 @@ class ModelBatch { uint32_t integer; } compressed; - compressed.integer = (static_cast(light.r * 255) & 0xff) << 24; + compressed.integer = (static_cast(light.r * 255) & 0xff) << 24; compressed.integer |= (static_cast(light.g * 255) & 0xff) << 16; compressed.integer |= (static_cast(light.b * 255) & 0xff) << 8; compressed.integer |= (static_cast(light.a * 255) & 0xff); @@ -49,12 +49,12 @@ class ModelBatch { buffer[index++] = compressed.floating; } - inline void plane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm, glm::vec4 light) { + inline void plane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm, glm::vec4 lights) { norm = rotation * norm; float d = glm::dot(norm, SUN_VECTOR); d = 0.8f + d * 0.2f; - auto color = light * d; + auto color = lights * d; vertex(pos-right-up, {0,0}, color); vertex(pos+right-up, {1,0}, color); @@ -71,7 +71,7 @@ public: void pushMatrix(glm::mat4 matrix); void popMatrix(); - void box(glm::vec3 pos, glm::vec3 size); + void box(glm::vec3 pos, glm::vec3 size, glm::vec4 lights); void test(glm::vec3 pos, glm::vec3 size); void flush();