diff --git a/Source/Contents/Ground/TerrainPicking.cpp b/Source/Contents/Ground/TerrainPicking.cpp index 8fda80f59..418a95f5f 100644 --- a/Source/Contents/Ground/TerrainPicking.cpp +++ b/Source/Contents/Ground/TerrainPicking.cpp @@ -4,33 +4,51 @@ // OFFSET: 0x00749300 // FUNCTION: fn_07842 float C3dAttr::RayDistance(const float* ray, int column, int row) const { + float nearest = 999999.0f; const TerrainHeightCell* cell = this->CellAt(column, row); if (!cell) { return 0.0f; } + struct Point { + // INLINED + Point() : x(0), y(0), z(0) { + } + + float x; + float y; + float z; + }; + Point corners[4]; const float size = static_cast(this->cellSize); - const int x = column - this->width / 2; - const int z = row - this->height / 2; - const float left = static_cast(x) * size; - const float right = static_cast(x + 1) * size; - const float top = static_cast(z) * size; - const float bottom = static_cast(z + 1) * size; - const float first[3] = {left, cell->heights[0], top}; - const float second[3] = {right, cell->heights[1], top}; - const float third[3] = {left, cell->heights[2], bottom}; - const float fourth[3] = {right, cell->heights[3], bottom}; - float nearest = 999999.0f; + const int dx = column - this->width / 2; + const int dz = row - this->height / 2; + const float left = static_cast(dx) * size; + const float right = static_cast(dx + 1) * size; + const float top = static_cast(dz) * size; + const float bottom = static_cast(dz + 1) * size; + corners[0].x = left; + corners[0].y = cell->heights[0]; + corners[0].z = top; + corners[1].x = right; + corners[1].y = cell->heights[1]; + corners[1].z = top; + corners[2].x = left; + corners[2].y = cell->heights[2]; + corners[2].z = bottom; + corners[3].x = right; + corners[3].y = cell->heights[3]; + corners[3].z = bottom; float u; float v; float distance; - if (IntersectRayTriangle(ray, first, second, third, u, v, distance)) { + if (IntersectRayTriangle(ray, &corners[0].x, &corners[1].x, &corners[2].x, u, v, distance)) { nearest = distance < nearest ? distance : nearest; } - if (IntersectRayTriangle(ray, second, fourth, third, u, v, distance)) { + if (IntersectRayTriangle(ray, &corners[1].x, &corners[3].x, &corners[2].x, u, v, distance)) { nearest = distance < nearest ? distance : nearest; }