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>
394 lines
9.1 KiB
C++
394 lines
9.1 KiB
C++
//===========================================================================//
|
|
// File: vector4d.cc //
|
|
// Project: MUNGA Brick: Math Library //
|
|
// Contents: Implementation details 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 //
|
|
//===========================================================================//
|
|
|
|
#include <munga.hpp>
|
|
#pragma hdrstop
|
|
|
|
#if !defined(VECTOR4D_HPP)
|
|
#include <vector4d.hpp>
|
|
#endif
|
|
|
|
#if !defined(MATRIX_HPP)
|
|
# include <matrix.hpp>
|
|
#endif
|
|
|
|
#if !defined(POINT3D_HPP)
|
|
# include <point3d.hpp>
|
|
#endif
|
|
|
|
#if !defined(AFFNMTRX_HPP)
|
|
# include <affnmtrx.hpp>
|
|
#endif
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector4D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
const Vector4D
|
|
Vector4D::Identity(0.0f,0.0f,0.0f,0.0f);
|
|
|
|
#if defined(USE_SIGNATURE)
|
|
int
|
|
Is_Signature_Bad(const volatile Vector4D *)
|
|
{
|
|
return False;
|
|
}
|
|
#endif
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::operator=(const Vector4D &v)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
|
|
x = v.x;
|
|
y = v.y;
|
|
z = v.z;
|
|
w = v.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::operator=(const Vector3D &v)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
|
|
x = v.x;
|
|
y = v.y;
|
|
z = v.z;
|
|
w = 0.0f;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::operator=(const Point3D &p)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&p);
|
|
|
|
x = p.x;
|
|
y = p.y;
|
|
z = p.z;
|
|
w = 1.0f;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Logical
|
|
Small_Enough(const Vector4D &V,Scalar e)
|
|
{
|
|
Check(&V);
|
|
return
|
|
Small_Enough(V.x,e)
|
|
&& Small_Enough(V.y,e)
|
|
&& Small_Enough(V.z,e)
|
|
&& Small_Enough(V.w,e);
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Logical
|
|
Close_Enough(const Vector4D &V1, const Vector4D &V2, Scalar e)
|
|
{
|
|
Check(&V1);
|
|
Check(&V2);
|
|
return
|
|
Close_Enough(V1.x,V2.x,e)
|
|
&& Close_Enough(V1.y,V2.y,e)
|
|
&& Close_Enough(V1.z,V2.z,e)
|
|
&& Close_Enough(V1.w,V2.w,e);
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Negate(const Vector4D &V)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V);
|
|
|
|
x = -V.x;
|
|
y = -V.y;
|
|
z = -V.z;
|
|
w = -V.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Add(const Vector4D& V1,const Vector4D& V2)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V1);
|
|
Check(&V2);
|
|
|
|
x = V1.x + V2.x;
|
|
y = V1.y + V2.y;
|
|
z = V1.z + V2.z;
|
|
w = V1.w + V2.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Subtract(const Vector4D& V1,const Vector4D& V2)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V1);
|
|
Check(&V2);
|
|
|
|
x = V1.x - V2.x;
|
|
y = V1.y - V2.y;
|
|
z = V1.z - V2.z;
|
|
w = V1.w - V2.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(const Vector4D& V,Scalar Scale)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V);
|
|
|
|
x = V.x * Scale;
|
|
y = V.y * Scale;
|
|
z = V.z * Scale;
|
|
w = V.w * Scale;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(const Vector4D& V1,const Vector4D& V2)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V1);
|
|
Check(&V2);
|
|
|
|
x = V1.x * V2.x;
|
|
y = V1.y * V2.y;
|
|
z = V1.z * V2.z;
|
|
w = V1.w * V2.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Divide(const Vector4D& V,Scalar Scale)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V);
|
|
Verify(!Small_Enough(Scale));
|
|
|
|
x = V.x / Scale;
|
|
y = V.y / Scale;
|
|
z = V.z / Scale;
|
|
w = V.w / Scale;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Divide(const Vector4D& V1,const Vector4D& V2)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V1);
|
|
Check(&V2);
|
|
|
|
Verify(!Small_Enough(V1.x));
|
|
Verify(!Small_Enough(V1.y));
|
|
Verify(!Small_Enough(V1.z));
|
|
Verify(!Small_Enough(V1.w));
|
|
|
|
x = V1.x / V2.x;
|
|
y = V1.y / V2.y;
|
|
z = V1.z / V2.z;
|
|
w = V1.w / V2.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(
|
|
const Vector4D& v,
|
|
const AffineMatrix& m
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
Check(&m);
|
|
Verify(this != &v);
|
|
|
|
x = v.x*m(0,0) + v.y*m(1,0) + v.z*m(2,0) + v.w*m(3,0);
|
|
y = v.x*m(0,1) + v.y*m(1,1) + v.z*m(2,1) + v.w*m(3,1);
|
|
z = v.x*m(0,2) + v.y*m(1,2) + v.z*m(2,2) + v.w*m(3,2);
|
|
w = v.w;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(
|
|
const Vector4D& v,
|
|
const Matrix4x4& m
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
Check(&m);
|
|
Verify(this != &v);
|
|
|
|
x = v.x*m(0,0) + v.y*m(1,0) + v.z*m(2,0) + v.w*m(3,0);
|
|
y = v.x*m(0,1) + v.y*m(1,1) + v.z*m(2,1) + v.w*m(3,1);
|
|
z = v.x*m(0,2) + v.y*m(1,2) + v.z*m(2,2) + v.w*m(3,2);
|
|
w = v.x*m(0,3) + v.y*m(1,3) + v.z*m(2,3) + v.w*m(3,3);
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(
|
|
const Vector3D& v,
|
|
const Matrix4x4& m
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
Check(&m);
|
|
|
|
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);
|
|
w = v.x*m(0,3) + v.y*m(1,3) + v.z*m(2,3);
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Multiply(
|
|
const Point3D& v,
|
|
const Matrix4x4& m
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
Check(&m);
|
|
|
|
x = v.x*m(0,0) + v.y*m(1,0) + v.z*m(2,0) + m(3,0);
|
|
y = v.x*m(0,1) + v.y*m(1,1) + v.z*m(2,1) + m(3,1);
|
|
z = v.x*m(0,2) + v.y*m(1,2) + v.z*m(2,2) + m(3,2);
|
|
w = v.x*m(0,3) + v.y*m(1,3) + v.z*m(2,3) + m(3,3);
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Vector4D&
|
|
Vector4D::Combine(
|
|
const Vector4D& V1,
|
|
Scalar t1,
|
|
const Vector4D& V2,
|
|
Scalar t2
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&V1);
|
|
Check(&V2);
|
|
|
|
x = V1.x*t1 + V2.x*t2;
|
|
y = V1.y*t1 + V2.y*t2;
|
|
z = V1.z*t1 + V2.z*t2;
|
|
w = V1.w*t1 + V2.w*t2;
|
|
return *this;
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
ostream&
|
|
operator<<(ostream& Stream, const Vector4D& V)
|
|
{
|
|
Check(&V);
|
|
return Stream << setprecision(4) << '<' << V.x << ','
|
|
<< V.y << ',' << V.z << ',' << V.w << '>';
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
//###########################################################################
|
|
//
|
|
Logical
|
|
Vector4D::TestInstance() const
|
|
{
|
|
return True;
|
|
}
|
|
|
|
#if defined(TEST_CLASS)
|
|
# include "vector4d.tcp"
|
|
#endif
|
|
|
|
|