]> git.localhorst.tv Git - blank.git/commitdiff
prepare block models for rotation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 8 Mar 2015 10:50:35 +0000 (11:50 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 8 Mar 2015 10:50:35 +0000 (11:50 +0100)
src/world.cpp
src/world.hpp

index aea6ec2ec8724b0de2dd5b56d8f58453c7769709..aa65bef7a3aa6cb88ae94d6dac2173f1a9b202b6 100644 (file)
@@ -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
index 738e6f0eac8401f1149081a93a8171fe73607046..ebdfdf423414eafa6cb7ad74a17ecd28156a4d00 100644 (file)
@@ -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())
                );
        }