From a326f27f6a43ed5adca68e27d29ac0f8f37cae94 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Mon, 14 Nov 2022 15:47:30 -0600 Subject: [PATCH] Fix coordinate system change Old code was inverting the X axis, new code inverts the Z axis. --- source/Irrlicht/CGLTFMeshFileLoader.cpp | 8 +++--- .../tests/testCGLTFMeshFileLoader.cpp | 28 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/Irrlicht/CGLTFMeshFileLoader.cpp b/source/Irrlicht/CGLTFMeshFileLoader.cpp index 96d3c63f..3e0ee23d 100644 --- a/source/Irrlicht/CGLTFMeshFileLoader.cpp +++ b/source/Irrlicht/CGLTFMeshFileLoader.cpp @@ -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(readFrom), + scale * readPrimitive(readFrom), scale * readPrimitive(BufferOffset(readFrom, sizeof(float))), - scale * readPrimitive(BufferOffset(readFrom, 2 * sizeof(float)))); + -scale * readPrimitive(BufferOffset(readFrom, 2 * sizeof(float)))); } static u16* readIndices(const BufferOffset& readFrom, const std::size_t count) diff --git a/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp b/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp index 74d10f0f..754cfd8d 100644 --- a/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp +++ b/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp @@ -52,7 +52,7 @@ TEST_CASE("minimal triangle") { const auto* vertices = reinterpret_cast( 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( 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( 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}); }