From ee7d79fe93ff6a311ae4068c0e6abe3c44b6db29 Mon Sep 17 00:00:00 2001 From: "@clasher113" Date: Tue, 5 Dec 2023 14:43:08 +0200 Subject: [PATCH] Vertical block rotation --- src/graphics/Font.h | 1 + src/logic/PlayerController.cpp | 14 ++++++-------- src/voxels/Block.cpp | 24 ++++++++++-------------- src/voxels/WorldGenerator.cpp | 4 ++-- src/voxels/voxel.h | 6 ++---- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/graphics/Font.h b/src/graphics/Font.h index e2e73123..1acb6cf9 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -3,6 +3,7 @@ #include #include +#include "../typedefs.h" class Texture; class Batch2D; diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index fd877b3d..3ba8b592 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -223,14 +223,12 @@ void PlayerController::updateInteraction(){ if (def->rotatable){ const string& name = def->rotations.name; if (name == "pipe") { - if (abs(norm.x) > abs(norm.z)){ - if (abs(norm.x) > abs(norm.y)) states = BLOCK_DIR_X; - if (abs(norm.x) < abs(norm.y)) states = BLOCK_DIR_Y; - } - if (abs(norm.x) < abs(norm.z)){ - if (abs(norm.z) > abs(norm.y)) states = BLOCK_DIR_Z; - if (abs(norm.z) < abs(norm.y)) states = BLOCK_DIR_Y; - } + if (norm.x < 0.0f) states = BLOCK_DIR_WEST; + else if (norm.x > 0.0f) states = BLOCK_DIR_EAST; + else if (norm.y > 0.0f) states = BLOCK_DIR_UP; + else if (norm.y < 0.0f) states = BLOCK_DIR_DOWN; + else if (norm.z > 0.0f) states = BLOCK_DIR_NORTH; + else if (norm.z < 0.0f) states = BLOCK_DIR_SOUTH; } else if (name == "pane") { vec3 vec = camera->dir; if (abs(vec.x) > abs(vec.z)){ diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index 6a1997b6..5a83bfa2 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -15,23 +15,19 @@ void CoordSystem::transform(AABB& aabb) { } const BlockRotProfile BlockRotProfile::PIPE {"pipe", { - // Vertical - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}}, - // X-Aligned - {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 0}}, - // Z-Aligned - {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, -1}, {0, 1, 0}}, + { { 1, 0, 0 }, { 0, 0, 1 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1, 0 } }, // North + { { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 1, 0, 0 } }, // East + { { 1, 0, 0 }, { 0, 0,-1 }, { 0, 1, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // South + { { 0,-1, 0 }, { 1, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 0 } }, // West + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }, // Up + { { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1,-1 }, { 0, 1, 1 } }, // Down }}; const BlockRotProfile BlockRotProfile::PANE {"pane", { - // North - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}}, - // East - {{0, 0, -1}, {0, 1, 0}, {1, 0, 0}, {1, 0, 0}, {0, 0, 1}}, - // South - {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, -1}, {1, 0, 1}}, - // West - {{0, 0, 1}, {0, 1, 0}, {-1, 0, 0}, {0, 0, -1}, {1, 0, 0}}, + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }, // North + { { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }, { 0, 0, 1 } }, // East + { {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }, { 1, 0,-1 }, { 1, 0, 1 } }, // South + { { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0,-1 }, { 1, 0, 0 } }, // West }}; Block::Block(std::string name) diff --git a/src/voxels/WorldGenerator.cpp b/src/voxels/WorldGenerator.cpp index 9ef3761c..1cd45ea6 100644 --- a/src/voxels/WorldGenerator.cpp +++ b/src/voxels/WorldGenerator.cpp @@ -206,7 +206,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){ int tree = generate_tree(&noise, &randomtree, heights, humidity, real_x, real_y, real_z, treesTile); if (tree) { id = tree; - states = BLOCK_DIR_PY; + states = BLOCK_DIR_UP; } } if (((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height) && humidity.get(real_x, real_z) < 0.1){ @@ -224,7 +224,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){ } if ((height > SEA_LEVEL+1) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65533)){ id = idWood; - states = BLOCK_DIR_PY; + states = BLOCK_DIR_UP; } voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id; voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = states; diff --git a/src/voxels/voxel.h b/src/voxels/voxel.h index 27ef5ee2..934d6b45 100644 --- a/src/voxels/voxel.h +++ b/src/voxels/voxel.h @@ -3,14 +3,12 @@ #include "../typedefs.h" -#define BLOCK_DIR_X 0x1 -#define BLOCK_DIR_Y 0x0 -#define BLOCK_DIR_Z 0x2 - const int BLOCK_DIR_NORTH = 0x0; const int BLOCK_DIR_WEST = 0x1; const int BLOCK_DIR_SOUTH = 0x2; const int BLOCK_DIR_EAST = 0x3; +const int BLOCK_DIR_UP = 0x4; +const int BLOCK_DIR_DOWN = 0x5; // limited to 16 block orientations const int BLOCK_ROT_MASK = 0xF;