#include "Resource/World/TerrainResource.h" // OFFSET: 0x00749040 // FUNCTION: fn_07840 float C3dAttr::PlaneHeight(float x, float z) const { const float size = static_cast(this->cellSize); const int columns = this->width; const int rows = this->height; const int column = static_cast(((static_cast(columns) * size) * 0.5f + x) / size); const int row = static_cast(((static_cast(rows) * size) * 0.5f + z) / size); const TerrainHeightCell* cell = this->CellAt(column, row); if (!cell) { return 0.0f; } struct Point { Point() : x(0), y(0), z(0) { } float x; float y; float z; }; Point corners[4]; const int dx = column - columns / 2; const int dz = row - rows / 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; Point first; Point second; Point third; first.x = left; first.y = cell->heights[0]; first.z = top; second.x = right; second.y = cell->heights[1]; second.z = top; third.x = left; third.y = cell->heights[2]; third.z = bottom; const float normalX = ((third.z - first.z) * second.y + (second.z - third.z) * first.y) + (first.z - second.z) * third.y; const float normalZ = ((third.y - first.y) * second.x + (second.y - third.y) * first.x) + (first.y - second.y) * third.x; const float constant = (((first.z * third.y - third.z * first.y) * second.x + (third.z * second.y - second.z * third.y) * first.x) + (second.z * first.y - first.z * second.y) * third.x) * -1.0f; const float normalY = ((second.x - third.x) * first.z + (third.x - first.x) * second.z) + (first.x - second.x) * third.z; return ((normalX * x + normalZ * z) + constant) * -1.0f / normalY; }