Fix #160 with suggestions from @A-lex-Ra

This commit is contained in:
InfiniteCoder
2024-02-24 17:09:11 +03:00
parent 7ee0c672f0
commit 3edf065550
7 changed files with 63 additions and 82 deletions
+11 -3
View File
@@ -39,8 +39,13 @@ ImageData* BlocksPreview::draw(
glm::vec4(1.0f), !def->rt.emissive);
break;
case BlockModel::aabb:
batch->blockCube(def->hitbox.size() * glm::vec3(size * 0.63f),
texfaces, glm::vec4(1.0f), !def->rt.emissive);
{
glm::vec3 hitbox = glm::vec3();
for (const auto& box : def->hitboxes)
hitbox = glm::max(hitbox, box.size());
batch->blockCube(hitbox * glm::vec3(size * 0.63f),
texfaces, glm::vec4(1.0f), !def->rt.emissive);
}
break;
case BlockModel::custom:
case BlockModel::xsprite: {
@@ -99,7 +104,10 @@ std::unique_ptr<Atlas> BlocksPreview::build(
glm::vec3 offset(0.1f, 0.5f, 0.1f);
if (def->model == BlockModel::aabb) {
offset.y += (1.0f - def->hitbox.size()).y * 0.5f;
glm::vec3 size = glm::vec3(0, 0, 0);
for (const auto& box : def->hitboxes)
size = glm::max(size, box.size());
offset.y += (1.0f - size).y * 0.5f;
}
atlas->getTexture()->bind();
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
+3 -12
View File
@@ -191,18 +191,9 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool hudVisible
const vec3 point = PlayerController::selectedPointPosition;
const vec3 norm = PlayerController::selectedBlockNormal;
std::vector<AABB> hitboxes;
if (!block->hitboxExplicit) {
hitboxes = block->modelBoxes;
} else {
hitboxes = { block->hitbox };
}
if (block->rotatable) {
auto states = PlayerController::selectedBlockStates;
for (auto& hitbox: hitboxes) {
block->rotations.variants[states].transform(hitbox);
}
}
std::vector<AABB>& hitboxes = block->rotatable
? block->rt.hitboxes[PlayerController::selectedBlockStates]
: block->hitboxes;
linesShader->use();
linesShader->uniformMatrix("u_projview", camera->getProjView());