AABB blocks render simplified
This commit is contained in:
@@ -243,22 +243,17 @@ void BlocksRenderer::blockXSprite(int x, int y, int z,
|
|||||||
|
|
||||||
// HINT: texture faces order: {east, west, bottom, top, south, north}
|
// HINT: texture faces order: {east, west, bottom, top, south, north}
|
||||||
|
|
||||||
/* AABB blocks render method (WIP) //FIXME */
|
/* AABB blocks render method (WIP) // TODO: fix lights */
|
||||||
void BlocksRenderer::blockAABB(const ivec3& icoord,
|
void BlocksRenderer::blockAABB(const ivec3& icoord,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const Block* block, ubyte rotation,
|
const Block* block, ubyte rotation,
|
||||||
bool lights) {
|
bool lights) {
|
||||||
AABB inversedHitbox = block->hitbox;
|
AABB hitbox = block->hitbox;
|
||||||
inversedHitbox.a = vec3(1.0f) - inversedHitbox.a;
|
vec3 size = hitbox.size();
|
||||||
inversedHitbox.b = vec3(1.0f) - inversedHitbox.b;
|
|
||||||
|
|
||||||
vec3 size = inversedHitbox.size();
|
vec3 X(1, 0, 0);
|
||||||
vec3 offset = inversedHitbox.min();
|
vec3 Y(0, 1, 0);
|
||||||
|
vec3 Z(0, 0, 1);
|
||||||
ivec3 X(1, 0, 0);
|
|
||||||
ivec3 Y(0, 1, 0);
|
|
||||||
ivec3 Z(0, 0, 1);
|
|
||||||
ivec3 loff(0);
|
|
||||||
vec3 coord(icoord);
|
vec3 coord(icoord);
|
||||||
if (block->rotatable) {
|
if (block->rotatable) {
|
||||||
auto& rotations = block->rotations;
|
auto& rotations = block->rotations;
|
||||||
@@ -266,35 +261,19 @@ void BlocksRenderer::blockAABB(const ivec3& icoord,
|
|||||||
X = orient.axisX;
|
X = orient.axisX;
|
||||||
Y = orient.axisY;
|
Y = orient.axisY;
|
||||||
Z = orient.axisZ;
|
Z = orient.axisZ;
|
||||||
coord += orient.fix;
|
orient.transform(hitbox);
|
||||||
loff -= orient.fix;
|
|
||||||
}
|
}
|
||||||
coord -= vec3(0.5, 0.5f, -0.5f);
|
|
||||||
vec3 fX(X);
|
|
||||||
vec3 fY(Y);
|
|
||||||
vec3 fZ(Z);
|
|
||||||
|
|
||||||
// TODO: simplify this pile of magic calculations and fix 5th arg (laxisZ)
|
coord = vec3(icoord) - vec3(0.5f) + hitbox.center();
|
||||||
face(coord + (1.0f - offset.x - size.x) * fX - (offset.z + size.z) * fZ,
|
|
||||||
X, Y, Z, Z+loff,
|
|
||||||
size.x, size.y, size.z, texfaces[5], lights); // north
|
|
||||||
face(coord + (1.0f - offset.x) * fX - (offset.z + size.z) * fZ,
|
|
||||||
-X, Y, -Z, Z-Z-X+loff,
|
|
||||||
size.x, size.y, 0.0f, texfaces[4], lights); // south
|
|
||||||
|
|
||||||
face(coord + (1.0f - offset.x - size.x) * fX - offset.z * fZ + size.y * fY,
|
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5]); // north
|
||||||
X, -Z, Y, Y-Y+loff,
|
face(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4]); // south
|
||||||
size.x, size.z, 0.0f, texfaces[3], lights); // top
|
|
||||||
face(coord + (1.0f - offset.x) * fX - offset.z * fZ,
|
|
||||||
-X, -Z, -Y, -X-Y+loff,
|
|
||||||
size.x, size.z, 0.0f, texfaces[2], lights); // bottom
|
|
||||||
|
|
||||||
face(coord + (1.0f - offset.x) * fX - offset.z * fZ,
|
face(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3]); // top
|
||||||
-Z, Y, X, X-X+loff,
|
face(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2]); // bottom
|
||||||
size.z, size.y, 0.0f, texfaces[1], lights); // west
|
|
||||||
face(coord + (1.0f - offset.x - size.x) * fX - (offset.z + size.z) * fZ,
|
face(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1]); // west
|
||||||
Z, Y, -X, -X-Y+loff,
|
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0]); // east
|
||||||
size.z, size.y, 0.0f, texfaces[0], lights); // east
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fastest solid shaded blocks render method */
|
/* Fastest solid shaded blocks render method */
|
||||||
|
|||||||
+19
-19
@@ -4,39 +4,39 @@
|
|||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
|
|
||||||
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ, glm::ivec3 fix)
|
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ)
|
||||||
: axisX(axisX), axisY(axisY), axisZ(axisZ), fix(fix)
|
: axisX(axisX), axisY(axisY), axisZ(axisZ)
|
||||||
{
|
{
|
||||||
fix2 = glm::ivec3(0);
|
fix = glm::ivec3(0);
|
||||||
if (isVectorHasNegatives(axisX)) fix2 -= axisX;
|
if (isVectorHasNegatives(axisX)) fix -= axisX;
|
||||||
if (isVectorHasNegatives(axisY)) fix2 -= axisY;
|
if (isVectorHasNegatives(axisY)) fix -= axisY;
|
||||||
if (isVectorHasNegatives(axisZ)) fix2 -= axisZ;
|
if (isVectorHasNegatives(axisZ)) fix -= axisZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoordSystem::transform(AABB& aabb) {
|
void CoordSystem::transform(AABB& aabb) const {
|
||||||
vec3 X(axisX);
|
vec3 X(axisX);
|
||||||
vec3 Y(axisY);
|
vec3 Y(axisY);
|
||||||
vec3 Z(axisZ);
|
vec3 Z(axisZ);
|
||||||
aabb.a = X * aabb.a.x + Y * aabb.a.y + Z * aabb.a.z;
|
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.b = X * aabb.b.x + Y * aabb.b.y + Z * aabb.b.z;
|
||||||
aabb.a += fix2;
|
aabb.a += fix;
|
||||||
aabb.b += fix2;
|
aabb.b += fix;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockRotProfile BlockRotProfile::PIPE {"pipe", {//TODO consexpr or init-time fix calculations
|
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
|
{ { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }}, // North
|
||||||
{ { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }, { 1, 0, -1 }}, // East
|
{ { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }}, // East
|
||||||
{ { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }, { 1, 0, 0 }}, // South
|
{ { -1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }}, // South
|
||||||
{ { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 0, 0 }}, // West
|
{ { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }}, // West
|
||||||
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 } }, // Up
|
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // Up
|
||||||
{ { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }, { 0, 1,-1 } }, // Down
|
{ { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }}, // Down
|
||||||
}};
|
}};
|
||||||
|
|
||||||
const BlockRotProfile BlockRotProfile::PANE {"pane", {
|
const BlockRotProfile BlockRotProfile::PANE {"pane", {
|
||||||
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 }}, // North
|
{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // North
|
||||||
{ { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 0, 0 }}, // East
|
{ { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }}, // East
|
||||||
{ {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }, { 1, 0,-1 }}, // South
|
{ {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }}, // South
|
||||||
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }, { 0, 0,-1 }}, // West
|
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West
|
||||||
}};
|
}};
|
||||||
|
|
||||||
Block::Block(std::string name)
|
Block::Block(std::string name)
|
||||||
|
|||||||
+3
-3
@@ -28,14 +28,14 @@ struct CoordSystem {
|
|||||||
glm::ivec3 axisX;
|
glm::ivec3 axisX;
|
||||||
glm::ivec3 axisY;
|
glm::ivec3 axisY;
|
||||||
glm::ivec3 axisZ;
|
glm::ivec3 axisZ;
|
||||||
|
|
||||||
// Grid 3d position fix offset (for negative vectors)
|
// Grid 3d position fix offset (for negative vectors)
|
||||||
glm::ivec3 fix;
|
glm::ivec3 fix;
|
||||||
glm::ivec3 fix2;
|
|
||||||
|
|
||||||
CoordSystem() = default;
|
CoordSystem() = default;
|
||||||
CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ, glm::ivec3 fix);
|
CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ);
|
||||||
|
|
||||||
void transform(AABB& aabb);
|
void transform(AABB& aabb) const;
|
||||||
|
|
||||||
static bool isVectorHasNegatives(glm::ivec3 vec) {
|
static bool isVectorHasNegatives(glm::ivec3 vec) {
|
||||||
if (vec.x < 0 || vec.y < 0 || vec.z < 0) {
|
if (vec.x < 0 || vec.y < 0 || vec.z < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user