AABB blocks render simplified

This commit is contained in:
MihailRis
2023-12-28 20:03:25 +03:00
parent 3f9e36e682
commit b8d7e89f0b
3 changed files with 41 additions and 62 deletions
+19 -19
View File
@@ -4,39 +4,39 @@
using glm::vec3;
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ, glm::ivec3 fix)
: axisX(axisX), axisY(axisY), axisZ(axisZ), fix(fix)
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ)
: axisX(axisX), axisY(axisY), axisZ(axisZ)
{
fix2 = glm::ivec3(0);
if (isVectorHasNegatives(axisX)) fix2 -= axisX;
if (isVectorHasNegatives(axisY)) fix2 -= axisY;
if (isVectorHasNegatives(axisZ)) fix2 -= axisZ;
fix = glm::ivec3(0);
if (isVectorHasNegatives(axisX)) fix -= axisX;
if (isVectorHasNegatives(axisY)) fix -= axisY;
if (isVectorHasNegatives(axisZ)) fix -= axisZ;
}
void CoordSystem::transform(AABB& aabb) {
void CoordSystem::transform(AABB& aabb) const {
vec3 X(axisX);
vec3 Y(axisY);
vec3 Z(axisZ);
aabb.a = X * aabb.a.x + Y * aabb.a.y + Z * aabb.a.z;
aabb.b = X * aabb.b.x + Y * aabb.b.y + Z * aabb.b.z;
aabb.a += fix2;
aabb.b += fix2;
aabb.a += fix;
aabb.b += fix;
}
const BlockRotProfile BlockRotProfile::PIPE {"pipe", {//TODO consexpr or init-time fix calculations
{ { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, 0, -1 }}, // North
{ { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }, { 1, 0, -1 }}, // East
{ { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }, { 1, 0, 0 }}, // South
{ { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 0, 0 }}, // West
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 } }, // Up
{ { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1,-1 } }, // Down
{ { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }}, // North
{ { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }}, // East
{ { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }}, // South
{ { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }}, // West
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // Up
{ { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }}, // Down
}};
const BlockRotProfile BlockRotProfile::PANE {"pane", {
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }}, // North
{ { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }}, // East
{ {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }, { 1, 0,-1 }}, // South
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0,-1 }}, // West
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // North
{ { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }}, // East
{ {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }}, // South
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West
}};
Block::Block(std::string name)