Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.
Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#include "Contents/Ground/GroundSpatial.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 GroundSpatial::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 GroundSpatial::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;
|
|
}
|
|
}
|