]> git.localhorst.tv Git - blank.git/blobdiff - src/chunk.cpp
don't render chunk that are outside clip space
[blank.git] / src / chunk.cpp
index e928a2199b80b2c007ef27d89446e9b41347fb85..514431cbdd636209368d86127cf812d5facfcad7 100644 (file)
@@ -9,7 +9,6 @@ namespace blank {
 Chunk::Chunk()
 : blocks(Size())
 , model()
-, transform(1.0f)
 , dirty(false) {
 
 }
@@ -17,7 +16,6 @@ Chunk::Chunk()
 Chunk::Chunk(Chunk &&other)
 : blocks(std::move(other.blocks))
 , model(std::move(other.model))
-, transform(other.transform)
 , dirty(other.dirty) {
 
 }
@@ -25,7 +23,6 @@ Chunk::Chunk(Chunk &&other)
 Chunk &Chunk::operator =(Chunk &&other) {
        blocks = std::move(other.blocks);
        model = std::move(other.model);
-       transform = other.transform;
        dirty = other.dirty;
        return *this;
 }
@@ -46,8 +43,7 @@ bool Chunk::Intersection(
        float *dist,
        glm::vec3 *normal) const {
        { // rough check
-               const AABB bb{{0, 0, 0}, {Width(), Height(), Depth()}};
-               if (!blank::Intersection(ray, bb, M)) {
+               if (!blank::Intersection(ray, Bounds(), M)) {
                        return false;
                }
        }
@@ -99,7 +95,10 @@ bool Chunk::Intersection(
 
 void Chunk::Position(const glm::vec3 &pos) {
        position = pos;
-       transform = glm::translate(pos * Extent());
+}
+
+glm::mat4 Chunk::Transform(const glm::vec3 &offset) const {
+       return glm::translate((position - offset) * Extent());
 }