summaryrefslogtreecommitdiffstats
path: root/src/AssetManager.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-20 14:38:11 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-20 14:38:11 +0200
commitbc49bcbb795c45cdb91efc6b03d93e4202e766b2 (patch)
treee3c405dacff7d8d227986d73b65311dcdb3f48a2 /src/AssetManager.cpp
parentCorrect face culling for rotated blocks (diff)
downloadAltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar.gz
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar.bz2
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar.lz
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar.xz
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.tar.zst
AltCraft-bc49bcbb795c45cdb91efc6b03d93e4202e766b2.zip
Diffstat (limited to '')
-rw-r--r--src/AssetManager.cpp87
1 files changed, 16 insertions, 71 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 2329e8d..9231bf3 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -505,7 +505,9 @@ 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;
+ for (int i = 0; i < FaceDirection::none; i++) {
+ blockFaces.faceDirectionVector[i] = FaceDirectionVector[i];
+ }
blockIdToBlockFaces.insert(std::make_pair(block, blockFaces));
return blockIdToBlockFaces.find(block)->second;
}
@@ -531,82 +533,25 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) {
BlockFaces blockFaces;
blockFaces.faces = assetModel->blockModel.parsedFaces;
blockFaces.isBlock = assetModel->blockModel.IsBlock;
- blockFaces.direction = FaceDirection::west;
+ glm::mat4 transform;
+
+ 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));
+ transform = glm::rotate(transform, glm::radians((float)model.y), glm::vec3(0.0f, 1.0f, 0));
+ }
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;
- }
+ transform = glm::rotate(transform, glm::radians((float)model.x), glm::vec3(1.0f, 0.0f, 0));
}
- 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;
- }
+
+ for (int i = 0; i < FaceDirection::none; i++) {
+ glm::vec4 vec = transform * glm::vec4(FaceDirectionVector[i].glm(), 1.0f);
+ blockFaces.faceDirectionVector[i] = Vector(roundf(vec.x), roundf(vec.y), roundf(vec.z));
}
blockIdToBlockFaces.insert(std::make_pair(block, blockFaces));