Files
wowdecomp/Engine/Source/Tempest/CFrustum.cpp
T
SatyandClaude Opus 5.5 597201ec6a Gx pass 1: device-free leaves, C3Vector ctors, Gx enums into Gx/Types.h
- CGxFormat(), CGxMatrixStack() + Identity, CGxLight(), CGxApiLight::operator= (moved to CGxLight.h),
  CGxPool::Invalidate/Discard, CGxGammaRamp::Set
- Gx.h/Gx.cpp: GxApiSupported, GxVertexSize, GxVertexAttribOffset, GxCalcTexelStrideInBytes + tables
- C3Vector() zero-inits and C3Vector(x, y, z) exists (inline only); CAaBox/C3Ray/CFrustum/Intersect rely on it
- EGxApi/EGxTexFormat/EGxVertexBufferFormat moved to Engine/Source/Gx/Types.h
- struct/class forward declaration mismatches fixed in CGxDevice.h and CGxPool.h

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

159 lines
4.6 KiB
C++

#include <cstdint>
#include "Engine/Source/Tempest/C44Matrix.h"
#include "Engine/Source/Tempest/CAaBox.h"
#include "Engine/Source/Tempest/CAaSphere.h"
#include "Engine/Source/Tempest/CFrustum.h"
// VERIFY: e0dd73d2 auto
// OFFSET: 0x00983990
void CFrustum::Extents(CAaBox& box) {
box = CAaBox::Bounding(this->corners, 8);
}
// VERIFY: 835d8937 auto
// OFFSET: 0x009839E0
uint32_t CFrustum::Cull(const CAaBox& box) {
const C3Vector* extremes[2] = { &box.t, &box.b };
for (uint32_t i = 0; i < 6; i++) {
const C4Plane& plane = this->planes[i];
const C3Vector* x = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.x) >> 31];
const C3Vector* y = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.y) >> 31];
const C3Vector* z = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.z) >> 31];
if (z->z * plane.n.z + y->y * plane.n.y + x->x * plane.n.x + plane.d < -0.019444443f) {
return 0;
}
}
return 3;
}
// VERIFY: 93cc8ec1 auto
// OFFSET: 0x00983A60
uint32_t CFrustum::CullInv(const CAaBox& box) {
const C3Vector* extremes[2] = { &box.t, &box.b };
for (uint32_t i = 0; i < 6; i++) {
const C4Plane& plane = this->planes[i];
const C3Vector* x = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.x) >> 31];
const C3Vector* y = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.y) >> 31];
const C3Vector* z = extremes[*reinterpret_cast<const uint32_t*>(&plane.n.z) >> 31];
if (z->z * plane.n.z + y->y * plane.n.y + x->x * plane.n.x + plane.d > 0.019444443f) {
return 0;
}
}
return 3;
}
// VERIFY: 2f6339ef manual
// OFFSET: 0x00983AE0
void CFrustum::Translate(const C3Vector& v) {
for (uint32_t i = 0; i < 8; i++) {
this->corners[i] += v;
}
for (uint32_t i = 0; i < 6; i++) {
this->planes[i].d = this->planes[i].d - (this->planes[i].n.z * v.z + this->planes[i].n.y * v.y + v.x * this->planes[i].n.x);
}
this->lookPos += v;
this->lookAt += v;
}
// VERIFY: b3982b68 manual
// OFFSET: 0x00983D20
uint32_t CFrustum::Cull(const CAaSphere& sphere) {
float limit = -sphere.r;
for (uint32_t i = 0; i < 6; i++) {
const C4Plane& plane = this->planes[i];
if (plane.n.x * sphere.c.x + plane.n.z * sphere.c.z + plane.n.y * sphere.c.y + plane.d < limit) {
return 0;
}
}
return 3;
}
// VERIFY: 5fea8dd6 manual
// OFFSET: 0x00983D70
void CFrustum::Cull(const C3Vector& point, uint8_t& outside) {
outside = 0;
for (uint32_t i = 0; i < 6; i++) {
const C4Plane& plane = this->planes[i];
if (plane.n.z * point.z + plane.n.y * point.y + point.x * plane.n.x + plane.d < -0.019444443f) {
outside |= 1 << i;
}
}
}
// VERIFY: ccfad69b manual
// OFFSET: 0x00983E70
void CFrustum::CalcPlanesFromCorners() {
this->planes[0].From3Pos(this->corners[1], this->corners[5], this->corners[6]);
this->planes[1].From3Pos(this->corners[0], this->corners[7], this->corners[4]);
this->planes[2].From3Pos(this->corners[0], this->corners[4], this->corners[5]);
this->planes[3].From3Pos(this->corners[3], this->corners[6], this->corners[7]);
this->planes[4].From3Pos(this->corners[5], this->corners[4], this->corners[6]);
this->planes[5].n.x = -this->planes[4].n.x;
this->planes[5].n.y = -this->planes[4].n.y;
this->planes[5].n.z = -this->planes[4].n.z;
this->planes[5].d = -(this->planes[5].n.z * this->corners[2].z + this->planes[5].n.y * this->corners[2].y + this->planes[5].n.x * this->corners[2].x);
}
// VERIFY: 88718e38 auto
// OFFSET: 0x00983F40
void CFrustum::Transform(const C44Matrix& m) {
for (uint32_t i = 0; i < 8; i++) {
this->corners[i] *= m;
}
this->CalcPlanesFromCorners();
this->lookPos *= m;
this->lookAt *= m;
}
// VERIFY: 75e79820 auto
// OFFSET: 0x00983FB0
uint32_t CFrustum::Cull(const C3Vector& center, float radius) {
CAaSphere sphere;
sphere.c = center;
sphere.r = radius;
return this->Cull(sphere);
}
// VERIFY: 6f48db85 manual
// OFFSET: 0x00983FE0
CFrustum::CFrustum(const C3Vector* corners) {
for (uint32_t i = 0; i < 6; i++) {
this->planes[i].n.x = 0.0f;
this->planes[i].n.y = 0.0f;
this->planes[i].n.z = 1.0f;
this->planes[i].d = 0.0f;
}
for (uint32_t i = 0; i < 8; i++) {
this->corners[i] = corners[i];
}
this->CalcPlanesFromCorners();
}
// VERIFY: 6d9a59ac manual
// OFFSET: 0x00984240
void CFrustum::CalcPlanesFromCorners(const C3Vector* corners) {
for (uint32_t i = 0; i < 8; i++) {
this->corners[i] = corners[i];
}
this->CalcPlanesFromCorners();
}