From 22319eadfc50e31d434b124117c7791103764410 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 8 Mar 2015 11:50:35 +0100 Subject: [PATCH] prepare block models for rotation --- src/world.cpp | 9 +++++---- src/world.hpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/world.cpp b/src/world.cpp index aea6ec2..aa65bef 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -104,7 +104,8 @@ bool Chunk::Intersection( } float cur_dist; glm::vec3 cur_norm; - if (blocks[id].type->shape->Intersects(ray, glm::translate(M, glm::vec3(x, y, z)), cur_dist, cur_norm)) { + glm::vec3 pos(float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f); + if (blocks[id].type->shape->Intersects(ray, glm::translate(M, pos), cur_dist, cur_norm)) { if (cur_dist < closest_dist) { closest_id = id; closest_dist = cur_dist; @@ -160,9 +161,9 @@ void Chunk::Update() { World::World() : blockType() -, blockShape({{ 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }}) -, stairShape({{ 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }}, { 0.5f, 0.5f }) -, slabShape({{ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.5f, 1.0f }}) +, blockShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}) +, stairShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f }) +, slabShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }}) , chunks() { blockType.Add(BlockType{ true, { 1.0f, 1.0f, 1.0f }, &blockShape }); // white block blockType.Add(BlockType{ true, { 1.0f, 1.0f, 1.0f }, &stairShape }); // white stair diff --git a/src/world.hpp b/src/world.hpp index 738e6f0..ebdfdf4 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -113,16 +113,16 @@ public: pos.z >= 0 && pos.z < Depth(); } static constexpr int ToIndex(const glm::vec3 &pos) { - return pos.x + pos.y * Width() + pos.z * Width() * Height(); + return int(pos.x) + int(pos.y) * Width() + int(pos.z) * Width() * Height(); } static constexpr bool InBounds(int idx) { return idx >= 0 && idx < Size(); } static glm::vec3 ToCoords(int idx) { return glm::vec3( - idx % Width(), - (idx / Width()) % Height(), - idx / (Width() * Height()) + 0.5f + idx % Width(), + 0.5f + (idx / Width()) % Height(), + 0.5f + idx / (Width() * Height()) ); } -- 2.39.2