rodecomp/Source/Contents/Ground/GroundSpatial.cpp
ragnarok-clanker eb47976075 Maintenance: [forced, user-approved] Family G rows 82 (GroundLightingContext), 111 (GroundRenderContext), 109 (GroundSpatial): remove
Batch #10262 by ragnarok-clanker: forced by an admin (1 lower score(s), 22 changed function(s)); checked with 170 compiled unit(s), including every includer of Source/Contents/Ground/GroundGeometry.h, Source/Contents/Ground/GroundRendering.h, Source/Contents/Ground/GroundSpatial.h, Source/Contents/World/WorldModelView.h, Source/Contents/World/WorldSpatialInitialization.h, Source/Contents/World/WorldSpatialTree.h.
2026-11-03 13:50:06 +00:00

72 lines
2.1 KiB
C++

#include "Contents/Ground/GroundGeometry.h"
#include "Utility/Math/ScalarConversion.h"
#include <cmath>
// OFFSET: 0x00ABD8F0
// FUNCTION: fn_17548
GroundQuad::GroundQuad() : texture(nullptr), selected(0) {
for (auto& vertex : this->vertices) {
vertex[0] = 0.0f;
vertex[1] = 0.0f;
vertex[2] = 0.0f;
}
}
// OFFSET: 0x00ABD8A0
// FUNCTION: fn_17547
GroundCell::GroundCell() : corners{}, top(nullptr), side1(nullptr), side2(nullptr), color{255, 255, 255} {
}
// OFFSET: 0x00AC0180
// FUNCTION: fn_17562
void GroundGeometry::SpatialCell(float x, float z, int& column, int& row) const {
const float first = static_cast<float>(std::floor(static_cast<double>(x / this->cellSize)));
column = TruncateToInt(first) + this->width / 2;
const float second = static_cast<float>(std::floor(static_cast<double>(z / this->cellSize)));
row = TruncateToInt(second) + this->height / 2;
}
// OFFSET: 0x00AC0EA0
// FUNCTION: fn_17573
void GroundGeometry::HeightBounds(const int* rectangle, float& minimum, float& maximum) const {
if (rectangle[0] < 0 || rectangle[0] >= this->width || rectangle[2] < 0 || rectangle[2] >= this->width || rectangle[1] < 0 || rectangle[1] >= this->height ||
rectangle[3] < 0 || rectangle[3] >= this->height || rectangle[2] <= rectangle[0] || rectangle[3] <= rectangle[1]) {
minimum = 0.0f;
maximum = 0.0f;
return;
}
minimum = 999999.0f;
maximum = -999999.0f;
int column = rectangle[0];
while (column <= rectangle[2]) {
int row = rectangle[1];
while (row <= rectangle[3]) {
const auto index = static_cast<unsigned>(column) + static_cast<unsigned>(row) * static_cast<unsigned>(this->width);
const GroundQuad* top = this->cells[index].top;
if (top) {
const float heights[4] = {top->vertices[0][1], top->vertices[1][1], top->vertices[2][1], top->vertices[3][1]};
for (float value : heights) {
if (value > maximum) {
maximum = value;
}
}
for (float value : heights) {
if (minimum > value) {
minimum = value;
}
}
}
++row;
}
++column;
}
}