namespace blank {
Chunk::Chunk()
-: blocks(Size())
+: blocks()
, model()
-, transform(1.0f)
+, position(0, 0, 0)
, dirty(false) {
}
Chunk::Chunk(Chunk &&other)
: blocks(std::move(other.blocks))
, model(std::move(other.model))
-, transform(other.transform)
, dirty(other.dirty) {
}
Chunk &Chunk::operator =(Chunk &&other) {
blocks = std::move(other.blocks);
model = std::move(other.model);
- transform = other.transform;
dirty = other.dirty;
return *this;
}
+void Chunk::Allocate() {
+ blocks.resize(Size());
+}
+
+
void Chunk::Draw() {
if (dirty) {
Update();
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;
}
}
return true;
}
-void Chunk::Position(const glm::vec3 &pos) {
+void Chunk::Position(const glm::tvec3<int> &pos) {
position = pos;
- transform = glm::translate(pos * Extent());
+}
+
+glm::mat4 Chunk::Transform(const glm::tvec3<int> &offset) const {
+ return glm::translate((position - offset) * Extent());
}