Decompile fn_07842 (C3dAttr::RayDistance)
Batch #16323 by youko: 0 byte-identical, 1 confirmed by peer review. - fn_07842 C3dAttr::RayDistance: logic confirmed by peer review Peer-reviewed-by: eAthena, Yommy, Toshiro Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
parent
bac6aa213b
commit
dbeb2d7edd
1 changed files with 31 additions and 13 deletions
|
|
@ -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<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;
|
||||
const int dx = column - this->width / 2;
|
||||
const int dz = row - this->height / 2;
|
||||
const float left = static_cast<float>(dx) * size;
|
||||
const float right = static_cast<float>(dx + 1) * size;
|
||||
const float top = static_cast<float>(dz) * size;
|
||||
const float bottom = static_cast<float>(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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue