summaryrefslogtreecommitdiffstats
path: root/src/AssetManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AssetManager.cpp')
-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));