summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-11 03:10:33 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-11 03:10:33 +0200
commit809c4766ba13e85546a747fe5e0dbd82e1e6d549 (patch)
tree28c807512b8f76fe3f4555858a9492ff5b6cad39 /src
parentSupport rotation in BlockStates (diff)
downloadAltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar.gz
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar.bz2
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar.lz
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar.xz
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.tar.zst
AltCraft-809c4766ba13e85546a747fe5e0dbd82e1e6d549.zip
Diffstat (limited to '')
-rw-r--r--src/AssetManager.cpp67
-rw-r--r--src/AssetManager.hpp11
-rw-r--r--src/Render.cpp3
-rw-r--r--src/RendererSectionData.cpp60
4 files changed, 134 insertions, 7 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 482a028..2329e8d 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -505,6 +505,7 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) {
BlockFaces blockFaces;
blockFaces.faces = GetAsset<AssetBlockModel>("/minecraft/models/block/error")->blockModel.parsedFaces;
blockFaces.isBlock = GetAsset<AssetBlockModel>("/minecraft/models/block/error")->blockModel.IsBlock;
+ blockFaces.direction = FaceDirection::none;
blockIdToBlockFaces.insert(std::make_pair(block, blockFaces));
return blockIdToBlockFaces.find(block)->second;
}
@@ -530,16 +531,82 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) {
BlockFaces blockFaces;
blockFaces.faces = assetModel->blockModel.parsedFaces;
blockFaces.isBlock = assetModel->blockModel.IsBlock;
+ blockFaces.direction = FaceDirection::west;
if (model.x != 0) {
blockFaces.transform = glm::translate(blockFaces.transform, glm::vec3(0.0f, 0.5f, 0.5f));
blockFaces.transform = glm::rotate(blockFaces.transform, glm::radians((float)model.x), glm::vec3(1.0f, 0.0f, 0.0f));
blockFaces.transform = glm::translate(blockFaces.transform, glm::vec3(0.0f, -0.5f, -0.5f));
+ switch (model.x) {
+ case 90:
+ blockFaces.direction = FaceDirection::down;
+ break;
+ case 180:
+ blockFaces.direction = FaceDirection::east;
+ break;
+ case 270:
+ blockFaces.direction = FaceDirection::up;
+ break;
+ default:
+ break;
+ }
}
if (model.y != 0) {
blockFaces.transform = glm::translate(blockFaces.transform, glm::vec3(0.5f, 0.0f, 0.5f));
blockFaces.transform = glm::rotate(blockFaces.transform, glm::radians((float)model.y), glm::vec3(0.0f, 1.0f, 0.0f));
blockFaces.transform = glm::translate(blockFaces.transform, glm::vec3(-0.5f, 0.0f, -0.5f));
+ switch (model.y) {
+ case 90:
+ switch (blockFaces.direction) {
+ case FaceDirection::west:
+ blockFaces.direction = FaceDirection::north;
+ break;
+ case FaceDirection::up:
+ blockFaces.direction = FaceDirection::up;
+ break;
+ case FaceDirection::east:
+ blockFaces.direction = FaceDirection::south;
+ break;
+ case FaceDirection::down:
+ blockFaces.direction = FaceDirection::down;
+ break;
+ }
+ break;
+ case 180:
+ switch (blockFaces.direction) {
+ case FaceDirection::west:
+ blockFaces.direction = FaceDirection::east;
+ break;
+ case FaceDirection::up:
+ blockFaces.direction = FaceDirection::up;
+ break;
+ case FaceDirection::east:
+ blockFaces.direction = FaceDirection::west;
+ break;
+ case FaceDirection::down:
+ blockFaces.direction = FaceDirection::down;
+ break;
+ }
+ break;
+ case 270:
+ switch (blockFaces.direction) {
+ case FaceDirection::west:
+ blockFaces.direction = FaceDirection::south;
+ break;
+ case FaceDirection::up:
+ blockFaces.direction = FaceDirection::up;
+ break;
+ case FaceDirection::east:
+ blockFaces.direction = FaceDirection::north;
+ break;
+ case FaceDirection::down:
+ blockFaces.direction = FaceDirection::down;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
}
blockIdToBlockFaces.insert(std::make_pair(block, blockFaces));
diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp
index 28cafb0..1996c9e 100644
--- a/src/AssetManager.hpp
+++ b/src/AssetManager.hpp
@@ -24,6 +24,16 @@ enum FaceDirection {
none,
};
+static const Vector FaceDirectionVector[] = {
+ Vector(0,-1,0),
+ Vector(0,1,0),
+ Vector(0,0,-1),
+ Vector(0,0,1),
+ Vector(-1,0,0),
+ Vector(1,0,0),
+ Vector(0,0,0)
+};
+
struct ParsedFace {
FaceDirection visibility;
glm::mat4 transform;
@@ -36,6 +46,7 @@ struct BlockFaces {
glm::mat4 transform;
std::vector<ParsedFace> faces;
bool isBlock;
+ FaceDirection direction;
};
struct BlockModel {
diff --git a/src/Render.cpp b/src/Render.cpp
index c1f7f2c..7f11dd9 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -419,6 +419,9 @@ void Render::RenderGui() {
world->GameStatePtr()->world.GetBlockId(world->GameStatePtr()->selectedBlock).id,
world->GameStatePtr()->world.GetBlockId(world->GameStatePtr()->selectedBlock).state,
AssetManager::GetAssetNameByBlockId(BlockId{ world->GameStatePtr()->world.GetBlockId(world->GameStatePtr()->selectedBlock).id,0 }).c_str());
+
+ ImGui::Text("Selected block direction: %d",
+ AssetManager::GetBlockModelByBlockId(world->GameStatePtr()->world.GetBlockId(world->GameStatePtr()->selectedBlock)).direction);
}
ImGui::End();
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index 6a6a7c0..245dc95 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -141,13 +141,59 @@ std::array<unsigned char, 4096> GetBlockVisibilityData(const SectionsData &secti
auto blockModelWest = GetInternalBlockModel(blockIdWest, idModels);
auto blockModelEast = GetInternalBlockModel(blockIdEast, idModels);
- value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 0;
- value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 1;
- value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 2;
- value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 3;
- value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 4;
- value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 5;
-
+ switch (GetInternalBlockModel(GetBlockId(x, y, z, blockIdData), idModels)->direction) {
+ case FaceDirection::west:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 0;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 1;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 2;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 3;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 4;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 5;
+ break;
+ case FaceDirection::east:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 0;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 1;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 3;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 2;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 5;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 4;
+ break;
+ case FaceDirection::up:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 4;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 5;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 2;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 3;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 1;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 0;
+ break;
+ case FaceDirection::down:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 4;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 5;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 2;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 3;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 0;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 1;
+ break;
+ case FaceDirection::north:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 0;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 1;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 5;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 4;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 2;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 3;
+ break;
+ case FaceDirection::south:
+ value |= (blockIdDown.id != 0 && !blockModelDown->faces.empty() && blockModelDown->isBlock) << 0;
+ value |= (blockIdUp.id != 0 && !blockModelUp->faces.empty() && blockModelUp->isBlock) << 1;
+ value |= (blockIdNorth.id != 0 && !blockModelNorth->faces.empty() && blockModelNorth->isBlock) << 4;
+ value |= (blockIdSouth.id != 0 && !blockModelSouth->faces.empty() && blockModelSouth->isBlock) << 5;
+ value |= (blockIdWest.id != 0 && !blockModelWest->faces.empty() && blockModelWest->isBlock) << 3;
+ value |= (blockIdEast.id != 0 && !blockModelEast->faces.empty() && blockModelEast->isBlock) << 2;
+ break;
+ case FaceDirection::none:
+ value = 0;
+ break;
+ }
arr[y * 256 + z * 16 + x] = value;
}
}