Files
BT412/engine/MUNGA/VECTOR3D.cpp
T
arcattackandClaude Opus 4.8 7b7d465e5e Initial commit: bt411 -- standalone Windows BattleTech (Tesla 4.10 port)
Clean, self-contained extraction of the BattleTech-specific work from the
reverse-engineering workspace -- engine + game + content + build, with nothing
from Red Planet or the raw archive dumps. Builds green (Win32) and runs the
single-player drive->animate->target->fire->damage->destroy loop out of the box.

Layout:
  engine/   MUNGA + MUNGA_L4 shared 2007 engine, carrying our BT render/loader
            work (bgfload/L4D3D/L4VIDEO: BSL bit-slice decode, LOD/ground/shadow
            models) + image codec; the minimal rp/ headers the audio HAL needs
  game/     reconstructed BT logic + surviving-original BT source + fwd shims
            + WinMain launcher
  content/  full runtime tree (BTL4.RES, VIDEO/, GAUGE/, AUDIO/, eggs, BTDPL.INI)
  docs/     format specs + reconstruction ledgers
  reference/ raw Ghidra pseudocode (recon source-of-truth) + decomp exporter
  tools/    MP console emulator + map/resource scanners

One top-level CMake builds munga_engine lib + bt410_l4 game lib + btl4.exe.
All paths relativized (186 fwd shims + ~437 CMake abs paths -> repo-relative);
DXSDK is the one external, overridable via -DDXSDK. Verified: builds to a
byte-identical 2.27MB exe and runs combat (TARGET DESTROYED, 0 crashes) against
the bundled content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 21:03:40 -05:00

327 lines
8.4 KiB
C++

#pragma hdrstop
#include <iomanip>
#include "vector3d.h"
#include "linmtrx.h"
#include "cstr.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AbstractVector3D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if defined(USE_SIGNATURE)
int
Is_Signature_Bad(const volatile AbstractVector3D *)
{
return False;
}
#endif
//
//###########################################################################
//###########################################################################
//
AbstractVector3D& AbstractVector3D::operator=(const AbstractVector3D &vector)
{
x = vector.x;
y = vector.y;
z = vector.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Logical Small_Enough(const AbstractVector3D &V, Scalar e)
{
return Small_Enough(V.x,e) && Small_Enough(V.y,e) && Small_Enough(V.z,e);
}
//
//###########################################################################
//###########################################################################
//
Logical Close_Enough(const AbstractVector3D &V1, const AbstractVector3D &V2, Scalar e)
{
return Close_Enough(V1.x,V2.x,e) && Close_Enough(V1.y,V2.y,e) && Close_Enough(V1.z,V2.z,e);
}
//
//###########################################################################
//###########################################################################
//
Logical AbstractVector3D::TestInstance() const
{
return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector3D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const Vector3D Vector3D::Identity(0.0f, 0.0f, 0.0f);
//
//###########################################################################
//###########################################################################
//
inline Vector3D& Vector3D::operator = (const LBE3Vector3D &vector)
{
x = vector.x;
y = vector.z;
z = vector.y;
return *this;
}
//
//###########################################################################
//###########################################################################
//
inline Vector3D& Vector3D::operator = (const TIVector3D &vector)
{
x = vector.x;
y = vector.y;
z = -vector.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Negate(const Vector3D &V)
{
x = -V.x;
y = -V.y;
z = -V.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Add(const Vector3D& V1, const Vector3D& V2)
{
x = V1.x + V2.x;
y = V1.y + V2.y;
z = V1.z + V2.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::AddScaled(const Vector3D& V1, const Vector3D& V2, Scalar scale)
{
x = V1.x + V2.x*scale;
y = V1.y + V2.y*scale;
z = V1.z + V2.z*scale;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Subtract(const Vector3D& V1, const Vector3D& V2)
{
x = V1.x - V2.x;
y = V1.y - V2.y;
z = V1.z - V2.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Cross(const Vector3D& v1, const Vector3D& v2)
{
Verify(this != &v1);
Verify(this != &v2);
x = v1.y * v2.z - v1.z * v2.y;
y = v1.z * v2.x - v1.x * v2.z;
z = v1.x * v2.y - v1.y * v2.x;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Multiply(const Vector3D& V, Scalar Scale)
{
x = V.x * Scale;
y = V.y * Scale;
z = V.z * Scale;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Multiply(const Vector3D& V1, const Vector3D& V2)
{
x = V1.x * V2.x;
y = V1.y * V2.y;
z = V1.z * V2.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Divide(const Vector3D& V, Scalar Scale)
{
Verify(!Small_Enough(Scale));
x = V.x / Scale;
y = V.y / Scale;
z = V.z / Scale;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Divide(const Vector3D& V1, const Vector3D& V2)
{
Verify(!Small_Enough(V2.x));
Verify(!Small_Enough(V2.y));
Verify(!Small_Enough(V2.z));
x = V1.x / V2.x;
y = V1.y / V2.y;
z = V1.z / V2.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Multiply(const Vector3D& v, const AffineMatrix& m)
{
Verify(this != &v);
x = v.x * m(0,0) + v.y * m(1,0) + v.z * m(2,0);
y = v.x * m(0,1) + v.y * m(1,1) + v.z * m(2,1);
z = v.x * m(0,2) + v.y * m(1,2) + v.z * m(2,2);
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::MultiplyByInverse(const Vector3D& v, const LinearMatrix& m)
{
Verify(this != &v);
x = v.x * m(0,0) + v.y * m(0,1) + v.z * m(0,2);
y = v.x * m(1,0) + v.y * m(1,1) + v.z * m(1,2);
z = v.x * m(2,0) + v.y * m(2,1) + v.z * m(2,2);
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Normalize(const Vector3D &V)
{
Scalar len = V.Length();
Verify(len);
x = V.x / len;
y = V.y / len;
z = V.z / len;
return *this;
}
//
//###########################################################################
//###########################################################################
//
Vector3D& Vector3D::Combine(const Vector3D& V1, Scalar t1, const Vector3D& V2, Scalar t2)
{
x = t1 * V1.x + t2 * V2.x;
y = t1 * V1.y + t2 * V2.y;
z = t1 * V1.z + t2 * V2.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
std::ostream& operator<<(std::ostream& Stream, const Vector3D& V)
{
return Stream << std::setprecision(4) << '<' << V.x << ',' << V.y << ',' << V.z << '>';
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector3D functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###########################################################################
//###########################################################################
//
void Convert_From_Ascii(const char *str, Vector3D *vector_3D)
{
Check_Signature(vector_3D);
CString parse_string(str);
vector_3D->x = atof(parse_string.GetNthToken(0));
vector_3D->y = atof(parse_string.GetNthToken(1));
vector_3D->z = atof(parse_string.GetNthToken(2));
}
//
//###########################################################################
//###########################################################################
//
LBE3Vector3D& LBE3Vector3D::operator=(const Vector3D& vector)
{
x = vector.x;
y = vector.z;
z = vector.y;
return *this;
}
//
//###########################################################################
//###########################################################################
//
LBE3Vector3D& LBE3Vector3D::operator=(const TIVector3D &vector)
{
x = vector.x;
y = -vector.z;
z = vector.y;
return *this;
}
//
//###########################################################################
//###########################################################################
//
TIVector3D& TIVector3D::operator=(const Vector3D &vector)
{
x = vector.x;
y = vector.y;
z = -vector.z;
return *this;
}
//
//###########################################################################
//###########################################################################
//
TIVector3D& TIVector3D::operator=(const LBE3Vector3D &vector)
{
x = vector.x;
y = vector.z;
z = -vector.y;
return *this;
}