Files
TeslaRel410/CODE/RP/MUNGA/PLANE.CPP
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

220 lines
6.0 KiB
C++

//===========================================================================//
// File: plane.cc //
// Project: MUNGA Brick: Math Library //
// Contents: Implementation details for the plane class //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
// 12/01/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(PLANE_HPP)
# include <plane.hpp>
#endif
#if !defined(SPHERE_HPP)
# include <sphere.hpp>
#endif
#if !defined(LINMTRX_HPP)
# include <linmtrx.hpp>
#endif
#if !defined(EXTNTBOX_HPP)
# include <extntbox.hpp>
#endif
//
//#############################################################################
//#############################################################################
//
Plane::Plane(
const Point3D& p0,
const Point3D& p1,
const Point3D& p2
)
{
Vector3D v1,v2;
v1.Subtract(p1, p0);
v2.Subtract(p2, p1);
Vector3D axis;
axis.Cross(v1, v2);
Verify(!Small_Enough(axis.Length()));
normal = axis;
offset = -(normal * p0);
Verify(Small_Enough(DistanceTo(p1)));
Verify(Small_Enough(DistanceTo(p2)));
Check_Fpu();
}
//
//#############################################################################
//#############################################################################
//
Plane&
Plane::Multiply(
const Plane &p,
const LinearMatrix &m
)
{
Check_Pointer(this);
Check(&p);
Check(&m);
normal.x = p.normal.x*m(0,0) + p.normal.y*m(1,0) + p.normal.z*m(2,0);
normal.y = p.normal.x*m(0,1) + p.normal.y*m(1,1) + p.normal.z*m(2,1);
normal.z = p.normal.x*m(0,2) + p.normal.y*m(1,2) + p.normal.z*m(2,2);
offset =
p.normal.x*m(3,0) + p.normal.y*m(3,1) + p.normal.z*m(3,2) + p.offset;
return *this;
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::Contains(const Point3D &point) const
{
return normal * point <= offset;
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::ContainsSomeOf(const Sphere &sphere) const
{
return normal*sphere.center - offset <= sphere.radius;
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::ContainsAllOf(const Sphere &sphere) const
{
return offset - normal*sphere.center >= sphere.radius;
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::ContainsSomeOf(const ExtentBox &box) const
{
Check(this);
Check(&box);
Point3D test;
test.x = (normal.x > 0.0f) ? box.minX : box.maxX;
test.y = (normal.y > 0.0f) ? box.minY : box.maxY;
test.z = (normal.z > 0.0f) ? box.minZ : box.maxZ;
return Contains(test);
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::ContainsAllOf(const ExtentBox &box) const
{
Check(this);
Check(&box);
Point3D test;
test.x = (normal.x < 0.0f) ? box.minX : box.maxX;
test.y = (normal.y < 0.0f) ? box.minY : box.maxY;
test.z = (normal.z < 0.0f) ? box.minZ : box.maxZ;
return Contains(test);
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::Intersect(const Sphere &sphere) const
{
Scalar dist = normal*sphere.center - offset;
return Abs(dist) <= sphere.radius;
}
//
//#############################################################################
//#############################################################################
//
Logical
Plane::Intersect(const ExtentBox &box) const
{
if (!ContainsSomeOf(box))
{
return False;
}
Plane inverse(-normal.x, -normal.y, -normal.z, -offset);
return inverse.ContainsSomeOf(box);
}
//
//#############################################################################
//#############################################################################
//
ostream&
operator<<(ostream& Stream, const Plane &A_Plane)
{
Stream << "\n\tPlane Normal: " << A_Plane.normal;
return Stream << "\n\tOffset: " << -A_Plane.offset;
}
//
//###########################################################################
//###########################################################################
//
Logical
Plane::TestInstance() const
{
return True;
}
Scalar
Plane::CalculateX(Scalar y, Scalar z)
{
Check(this);
Verify(!Small_Enough(normal.x));
Scalar result = (offset - y*normal.y - z*normal.z)/normal.x;
Check_Fpu();
return result;
}
Scalar
Plane::CalculateY(Scalar x, Scalar z)
{
Check(this);
Verify(!Small_Enough(normal.y));
Scalar result = (offset - x*normal.x - z*normal.z)/normal.y;
Check_Fpu();
return result;
}
Scalar
Plane::CalculateZ(Scalar x, Scalar y)
{
Check(this);
Verify(!Small_Enough(normal.z));
Scalar result = (offset - x*normal.x - y*normal.y)/normal.z;
Check_Fpu();
return result;
}