Batch #10268 by ragnarok-clanker: forced by an admin (17 lower score(s), 85 changed function(s)); checked with 222 compiled unit(s), including every includer of Source/Client/Mode/CGameMode.h, Source/Contents/Camera/CameraFrame.h, Source/Contents/Ground/TerrainHeight.h, Source/Contents/World/World.h, Source/Resource/World/TerrainResource.h.
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#include "Resource/World/TerrainResource.h"
|
|
#include "Utility/Math/RayTriangle.h"
|
|
|
|
// OFFSET: 0x00749300
|
|
// FUNCTION: fn_07842
|
|
float C3dAttr::RayDistance(const float* ray, int column, int row) const {
|
|
const TerrainHeightCell* cell = this->CellAt(column, row);
|
|
|
|
if (!cell) {
|
|
return 0.0f;
|
|
}
|
|
|
|
const float size = static_cast<float>(this->cellSize);
|
|
const int x = column - this->width / 2;
|
|
const int z = row - this->height / 2;
|
|
const float left = static_cast<float>(x) * size;
|
|
const float right = static_cast<float>(x + 1) * size;
|
|
const float top = static_cast<float>(z) * size;
|
|
const float bottom = static_cast<float>(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;
|
|
float u;
|
|
float v;
|
|
float distance;
|
|
|
|
if (IntersectRayTriangle(ray, first, second, third, u, v, distance)) {
|
|
nearest = distance < nearest ? distance : nearest;
|
|
}
|
|
|
|
if (IntersectRayTriangle(ray, second, fourth, third, u, v, distance)) {
|
|
nearest = distance < nearest ? distance : nearest;
|
|
}
|
|
|
|
return nearest;
|
|
}
|