Fix coordinate system change

Old code was inverting the X axis, new code inverts the Z axis.
This commit is contained in:
Josiah VanderZee 2022-11-14 15:47:30 -06:00
parent 47a195b4de
commit a326f27f6a
2 changed files with 18 additions and 18 deletions

View File

@ -93,12 +93,12 @@ static core::vector2df readVec2DF(const BufferOffset& readFrom)
static core::vector3df readVec3DF(const BufferOffset& readFrom,
const float scale = 1.0f)
{
// glTF coordinates are right-handed, minetest ones are left-handed
// 1 glTF coordinate is equivalent to 10 Irrlicht coordinates
// glTF's coordinate system is right-handed, Irrlicht's is left-handed
// glTF's +Z axis corresponds to Irrlicht's -Z axis
return core::vector3df(
-scale * readPrimitive<float>(readFrom),
scale * readPrimitive<float>(readFrom),
scale * readPrimitive<float>(BufferOffset(readFrom, sizeof(float))),
scale * readPrimitive<float>(BufferOffset(readFrom, 2 * sizeof(float))));
-scale * readPrimitive<float>(BufferOffset(readFrom, 2 * sizeof(float))));
}
static u16* readIndices(const BufferOffset& readFrom, const std::size_t count)

View File

@ -52,7 +52,7 @@ TEST_CASE("minimal triangle") {
const auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
sm.getMesh()->getMeshBuffer(0)->getVertices());
CHECK(vertices[0].Pos == irr::core::vector3df {0.0f, 0.0f, 0.0f});
CHECK(vertices[1].Pos == irr::core::vector3df {-1.0f, 0.0f, 0.0f});
CHECK(vertices[1].Pos == irr::core::vector3df {1.0f, 0.0f, 0.0f});
CHECK(vertices[2].Pos == irr::core::vector3df {0.0f, 1.0f, 0.0f});
}
@ -74,14 +74,14 @@ TEST_CASE("blender cube") {
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getVertexCount() == 24);
const auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
sm.getMesh()->getMeshBuffer(0)->getVertices());
CHECK(vertices[0].Pos == irr::core::vector3df{10.0f, -10.0f, 10.0f});
CHECK(vertices[3].Pos == irr::core::vector3df{10.0f, 10.0f, 10.0f});
CHECK(vertices[6].Pos == irr::core::vector3df{10.0f, -10.0f, -10.0f});
CHECK(vertices[9].Pos == irr::core::vector3df{10.0f, 10.0f, -10.0f});
CHECK(vertices[12].Pos == irr::core::vector3df{-10.0f, -10.0f, 10.0f});
CHECK(vertices[15].Pos == irr::core::vector3df{-10.0f, 10.0f, 10.0f});
CHECK(vertices[18].Pos == irr::core::vector3df{-10.0f, -10.0f, -10.0f});
CHECK(vertices[21].Pos == irr::core::vector3df{-10.0f, 10.0f, -10.0f});
CHECK(vertices[0].Pos == irr::core::vector3df{-10.0f, -10.0f, -10.0f});
CHECK(vertices[3].Pos == irr::core::vector3df{-10.0f, 10.0f, -10.0f});
CHECK(vertices[6].Pos == irr::core::vector3df{-10.0f, -10.0f, 10.0f});
CHECK(vertices[9].Pos == irr::core::vector3df{-10.0f, 10.0f, 10.0f});
CHECK(vertices[12].Pos == irr::core::vector3df{10.0f, -10.0f, -10.0f});
CHECK(vertices[15].Pos == irr::core::vector3df{10.0f, 10.0f, -10.0f});
CHECK(vertices[18].Pos == irr::core::vector3df{10.0f, -10.0f, 10.0f});
CHECK(vertices[21].Pos == irr::core::vector3df{10.0f, 10.0f, 10.0f});
}
SECTION("vertex indices are correct") {
@ -97,12 +97,12 @@ TEST_CASE("blender cube") {
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getVertexCount() == 24);
const auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
sm.getMesh()->getMeshBuffer(0)->getVertices());
CHECK(vertices[0].Normal == irr::core::vector3df{1.0f, 0.0f, 0.0f});
CHECK(vertices[0].Normal == irr::core::vector3df{-1.0f, 0.0f, 0.0f});
CHECK(vertices[1].Normal == irr::core::vector3df{0.0f, -1.0f, 0.0f});
CHECK(vertices[2].Normal == irr::core::vector3df{0.0f, 0.0f, 1.0f});
CHECK(vertices[3].Normal == irr::core::vector3df{1.0f, 0.0f, 0.0f});
CHECK(vertices[6].Normal == irr::core::vector3df{1.0f, 0.0f, 0.0f});
CHECK(vertices[23].Normal == irr::core::vector3df{-1.0f, 0.0f, 0.0f});
CHECK(vertices[2].Normal == irr::core::vector3df{0.0f, 0.0f, -1.0f});
CHECK(vertices[3].Normal == irr::core::vector3df{-1.0f, 0.0f, 0.0f});
CHECK(vertices[6].Normal == irr::core::vector3df{-1.0f, 0.0f, 0.0f});
CHECK(vertices[23].Normal == irr::core::vector3df{1.0f, 0.0f, 0.0f});
}