From ffcc5bd134a147d2ae81b5d1df8e7a6ea4c775af Mon Sep 17 00:00:00 2001 From: Asuro Date: Fri, 20 Jun 2025 03:00:42 +0200 Subject: [PATCH] fix heightmaps --- src/game/Mesh.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/Mesh.cpp b/src/game/Mesh.cpp index 1fc5989..a3389b1 100644 --- a/src/game/Mesh.cpp +++ b/src/game/Mesh.cpp @@ -123,14 +123,14 @@ namespace Game startTime = bx::getHPCounter(); for (uint32_t v = 0; v < HeightMap::Height; ++v) { - float vPos = mesh.MinPos.y + (float)v / HeightMap::Height * mesh.Size.y; + float vPos = mesh.MinPos.z + (float)v / HeightMap::Height * mesh.Size.z; for (uint32_t u = 0; u < HeightMap::Width; ++u) { float uPos = mesh.MinPos.x + (float)u / HeightMap::Width * mesh.Size.x; - Gen::Vec3 rayStart = {uPos, vPos, SIZE_LIMIT}; - Gen::Vec3 rayEnd = {uPos, vPos, -SIZE_LIMIT}; + Gen::Vec3 rayStart = {uPos, mesh.MinPos.y, vPos}; + Gen::Vec3 rayEnd = {uPos, mesh.MaxPos.y, vPos}; Gen::Vec3 ptOut; for (int16_t i = 0; i < indexBufferView.byteLength; i += indexStride * 3) @@ -148,8 +148,8 @@ namespace Game reinterpret_cast(&posBuffer.data[posBufferView.byteOffset + *idxC * posStride]); if (Gen::RayTriangleIntersect(rayStart, rayEnd, *triA, *triB, *triC, ptOut)) { - float len = mesh.MaxPos.z - ptOut.z; - uint8_t val = (uint8_t)(len / mesh.Size.z * UINT8_MAX); + float len = ptOut.y - mesh.MinPos.y; + uint8_t val = (uint8_t)(len / mesh.Size.y * UINT8_MAX); int32_t idx = v * HeightMap::Width + u; if (mesh.Height.Values[idx] < val) { @@ -157,7 +157,7 @@ namespace Game } if (len < 0.0f) { - LOG_ONCE("%f / %f = %u", len, mesh.Size.z, val); + LOG_ONCE("%f / %f = %u", len, mesh.Size.y, val); } } }