Files
wowdecomp/Engine/Source/Tempest/CAaSphere.cpp
T
SatyandClaude Opus 5.5 a09c429bd3 Tempest pass 1: readable field names, class-named files, math classes
- Field names from the 12340 type library (x/y/z/w, a0..d3, minY/minX/maxY/maxX, b/t, c/r, n/d, origin/dir)
- Files renamed to match their class; CRay -> C3Ray; C3Segment, CRect, CiRect, C2iVector, C3iVector split out
- MouseEventData, CharacterInfo, M2Bounds moved out of Tempest headers
- 107 functions: C2/C3/C4Vector, C33/C34/C44Matrix, C4Quaternion, C4Plane, CAaBox, CAaSphere, C3Ray, CRect, CiRect, CImVector, NTempest
- 0x4C1C40 is cdecl (q, out): ported as static C44Matrix::FromQuaternion (guessed)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-24 20:46:51 +02:00

129 lines
2.9 KiB
C++

#include <cmath>
#include <cstdint>
#include "Engine/Source/Tempest/CAaSphere.h"
// VERIFY: 96f5035c manual
// OFFSET: 0x007FA140
CAaBox CAaSphere::Box() const {
CAaBox result;
result.b.x = this->c.x - this->r;
result.b.y = this->c.y - this->r;
result.b.z = this->c.z - this->r;
result.t.x = this->c.x + this->r;
result.t.y = this->c.y + this->r;
result.t.z = this->c.z + this->r;
return result;
}
// VERIFY: 34fc52e7 manual
// OFFSET: 0x009855F0
CAaBox CAaSphere::FindExtrema(const CAaSphere* spheres, uint32_t count) {
CAaBox result;
if (!count) {
result.b.x = 0.0f;
result.b.y = 0.0f;
result.b.z = 0.0f;
result.t.x = 0.0f;
result.t.y = 0.0f;
result.t.z = 0.0f;
return result;
}
CAaBox box = spheres[0].Box();
for (uint32_t i = 1; i < count; i++) {
const CAaSphere& sphere = spheres[i];
float maxX = sphere.r + sphere.c.x;
float maxY = sphere.r + sphere.c.y;
float maxZ = sphere.r + sphere.c.z;
float minX = sphere.c.x - sphere.r;
float minY = sphere.c.y - sphere.r;
float minZ = sphere.c.z - sphere.r;
if (box.t.z > maxZ) {
maxZ = box.t.z;
}
if (box.t.y > maxY) {
maxY = box.t.y;
}
if (box.t.x > maxX) {
maxX = box.t.x;
}
if (box.b.z < minZ) {
minZ = box.b.z;
}
if (box.b.y < minY) {
minY = box.b.y;
}
if (box.b.x < minX) {
minX = box.b.x;
}
box.b.x = minX;
box.b.y = minY;
box.b.z = minZ;
box.t.x = maxX;
box.t.y = maxY;
box.t.z = maxZ;
}
result = box;
return result;
}
// VERIFY: 1d040cbb manual
// OFFSET: 0x00985750
CAaSphere CAaSphere::BoundingAccurate(const CAaSphere* spheres, uint32_t count) {
CAaSphere result;
if (!count) {
result.c.x = 0.0f;
result.c.y = 0.0f;
result.c.z = 0.0f;
result.r = 0.0f;
return result;
}
if (count == 1) {
result = spheres[0];
return result;
}
CAaBox box = FindExtrema(spheres, count);
if (box.IsEmpty()) {
result.c = box.b;
result.r = 0.0f;
return result;
}
C3Vector center;
center.x = (box.t.x + box.b.x) * 0.5f;
center.y = (box.t.y + box.b.y) * 0.5f;
center.z = 0.5f * (box.t.z + box.b.z);
float radius = 0.0f;
for (uint32_t i = 0; i < count; i++) {
const CAaSphere& sphere = spheres[i];
float dy = sphere.c.y - center.y;
float dx = sphere.c.x - center.x;
float distance = dx * dx + dy * dy + (sphere.c.z - center.z) * (sphere.c.z - center.z);
float slack = radius - sphere.r;
if (slack < 0.0f || slack * slack < distance) {
radius = sqrt(distance) + sphere.r;
}
}
result.c = center;
result.r = radius;
return result;
}