Files
CydandClaude Opus 4.8 4abbf8879f Initial import of Red Planet v4.10 Win32 source
Imports the current Win32 source for the pod-racing game 'Red Planet',
built on the MUNGA engine and its L4 (Win32/DirectX) platform layer:

- MUNGA / MUNGA_L4: cross-platform engine core and Win32 backend
- RP / RP_L4: Red Planet game logic and Win32 application
- DivLoader, Setup1: asset loader and installer project
- lib, MUNGA_L4/openal, MUNGA_L4/sos: third-party audio dependencies

Removed stale Subversion metadata and added .gitignore/.gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 07:59:51 -05:00

366 lines
7.6 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "vector4d.h"
#include "matrix.h"
#include "point3d.h"
#include "affnmtrx.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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;
}
//
//###########################################################################
//###########################################################################
//
std::ostream& operator<<(std::ostream& Stream, const Vector4D& V)
{
Check(&V);
return Stream << std::setprecision(4) << '<' << V.x << ','
<< V.y << ',' << V.z << ',' << V.w << '>';
}
//
//###########################################################################
//###########################################################################
//
Logical
Vector4D::TestInstance() const
{
return True;
}
#if defined(TEST_CLASS)
# include "vector4d.tcp"
#endif