Files
TeslaRel410/CODE/RP/MUNGA/VECTOR4D.TCP
T
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

141 lines
4.2 KiB
Plaintext

//===========================================================================//
// File: vector4d.tst //
// Project: MUNGA Brick: Math Library //
// Contents: Test code for vector classes //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
// 11/19/94 JMA Initial coding. //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// All Rights reserved worldwide //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
//===========================================================================//
#if !defined(ROTATION_HPP)
#include <rotation.hpp>
#endif
//
//###########################################################################
//###########################################################################
//
Logical
Vector4D::TestClass()
{
DEBUG_STREAM << "Starting Vector4D test...\n";
const Vector4D
a(Identity);
Vector4D
b;
const Vector4D
c(1.0f,2.0f,3.0f,4.0f);
Vector4D
d(2.0f,3.0f,1.0f,4.0f);
Test(!a.x && !a.y && !a.z && !a.w);
Test(c.x == 1.0f && c.y == 2.0f && c.z == 3.0f && c.w == 4.0f);
Test(c[2] == c.z);
Test(a[1] == a.y);
Test(Small_Enough(a));
Test(!a);
b = c;
Test(b.x == c.x && b.y == c.y && b.z == c.z && b.w == c.w);
Test(Close_Enough(b,c));
Test(b == c);
Test(a != b);
Point3D p(3.0f,2.0f,1.0f);
b = p;
Test(b == Vector4D(p.x,p.y,p.z,1.0f));
Vector3D v(-1.0f,3.0f,2.0f);
b = v;
Test(b == Vector4D(v.x,v.y,v.z,0.0f));
b.Negate(c);
Test(b == Vector4D(-c.x,-c.y,-c.z,-c.w));
b.Add(c,d);
Test(b == Vector4D(c.x+d.x,c.y+d.y,c.z+d.z,c.w+d.w));
b = c;
b += d;
Test(b == Vector4D(c.x+d.x,c.y+d.y,c.z+d.z,c.w+d.w));
b.Subtract(d,c);
Test(b == Vector4D(d.x-c.x,d.y-c.y,d.z-c.z,d.w-c.w));
b = d;
b -= c;
Test(b == Vector4D(d.x-c.x,d.y-c.y,d.z-c.z,d.w-c.w));
Scalar f = c*d;
Test(f == c.x*d.x + c.y*d.y + c.z*d.z + c.w*d.w);
f = 2.0f;
b.Multiply(c,f);
Test(b == Vector4D(f*c.x,f*c.y,f*c.z,f*c.w));
b = c;
b *= f;
Test(b == Vector4D(f*c.x,f*c.y,f*c.z,f*c.w));
b.Multiply(c,d);
Test(b == Vector4D(c.x*d.x,c.y*d.y,c.z*d.z,c.w*d.w));
b = c;
b *= d;
Test(b == Vector4D(c.x*d.x,c.y*d.y,c.z*d.z,c.w*d.w));
b.Divide(c,f);
Test(b == Vector4D(c.x/f,c.y/f,c.z/f,c.w/f));
b = c;
b /= f;
Test(b == Vector4D(c.x/f,c.y/f,c.z/f,c.w/f));
b.Divide(c,d);
Test(b == Vector4D(c.x/d.x,c.y/d.y,c.z/d.z,c.w/d.w));
b = c;
b /= d;
Test(b == Vector4D(c.x/d.x,c.y/d.y,c.z/d.z,c.w/d.w));
AffineMatrix m;
EulerAngles r(PI_OVER_4,0.0f,0.0f);
m = r;
m = p;
b.Multiply(c,m);
Test(b == Vector4D(c.x+c.w*m(3,0),c.y*m(1,1)+c.z*m(2,1)+c.w*m(3,1),c.y*m(1,2)+c.z*m(2,2)+c.w*m(3,2),c.w));
b = c;
b *= m;
Test(b == Vector4D(c.x+c.w*m(3,0),c.y*m(1,1)+c.z*m(2,1)+c.w*m(3,1),c.y*m(1,2)+c.z*m(2,2)+c.w*m(3,2),c.w));
Matrix4x4 m2;
m2 = m;
b.Multiply(c,m2);
Test(b == Vector4D(c.x+c.w*m2(3,0),c.y*m2(1,1)+c.z*m2(2,1)+c.w*m2(3,1),c.y*m2(1,2)+c.z*m2(2,2)+c.w*m2(3,2),c.w));
b = c;
b *= m2;
Test(b == Vector4D(c.x+c.w*m2(3,0),c.y*m2(1,1)+c.z*m2(2,1)+c.w*m2(3,1),c.y*m2(1,2)+c.z*m2(2,2)+c.w*m2(3,2),c.w));
b.Multiply(v,m2);
Test(b == Vector4D(v.x,v.y*m2(1,1)+v.z*m2(2,1),v.y*m2(1,2)+v.z*m2(2,2),0.0f));
b.Multiply(p,m2);
Test(b == Vector4D(p.x+m2(3,0),p.y*m2(1,1)+p.z*m2(2,1)+m2(3,1),p.y*m2(1,2)+p.z*m2(2,2)+m2(3,2),1.0f));
Test(!a.LengthSquared());
f = c.LengthSquared();
Test(f == c.x*c.x + c.y*c.y + c.z*c.z + c.w*c.w);
f = c.Length();
Test(Close_Enough(f,Sqrt(c.LengthSquared())));
b.Combine(c,2.0f,d,2.0f);
Test(b == Vector4D(2.0f*(c.x+d.x),2.0f*(c.y+d.y),2.0f*(c.z+d.z),2.0f*(c.w+d.w)));
b.Lerp(c,d,0.5f);
Test(b == Vector4D(0.5f*(c.x+d.x),0.5f*(c.y+d.y),0.5f*(c.z+d.z),0.5f*(c.w+d.w)));
return True;
}