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>
893 lines
27 KiB
C++
893 lines
27 KiB
C++
//===========================================================================//
|
|
// File: boxsolid.cc //
|
|
// Project: MUNGA Brick: Spatializer Library //
|
|
// Contents: Implementation details of bounding-box collision subtypes //
|
|
//---------------------------------------------------------------------------//
|
|
// Date Who Modification //
|
|
// -------- --- ---------------------------------------------------------- //
|
|
// 01/11/95 JMA Initial port back to C++ //
|
|
//---------------------------------------------------------------------------//
|
|
// Copyright (C) 1993-1995, Virtual World Entertainment, Inc. //
|
|
// All Rights reserved worldwide //
|
|
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL //
|
|
//===========================================================================//
|
|
|
|
#include <munga.hpp>
|
|
#pragma hdrstop
|
|
|
|
#if !defined(BOXSOLID_HPP)
|
|
# include <boxsolid.hpp>
|
|
#endif
|
|
|
|
#if !defined(PLANE_HPP)
|
|
# include <plane.hpp>
|
|
#endif
|
|
|
|
extern Logical
|
|
BoxedRampContainsLine(
|
|
Line *line,
|
|
const Plane& plane,
|
|
Scalar enters,
|
|
Scalar leaves
|
|
);
|
|
|
|
//#############################################################################
|
|
//################# BoxedWedgeFacingNegativeZAndPositiveX ###############
|
|
//#############################################################################
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingNegativeZAndPositiveX::BoxedWedgeFacingNegativeZAndPositiveX(
|
|
const ExtentBox &extents,
|
|
BoxedSolid::Material material,
|
|
Simulation *owner,
|
|
BoxedSolid *next_solid
|
|
):
|
|
BoxedSolid(
|
|
extents,
|
|
WedgeFacingNegativeZAndPositiveXType,
|
|
material,
|
|
owner,
|
|
next_solid
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingNegativeZAndPositiveX::~BoxedWedgeFacingNegativeZAndPositiveX()
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndPositiveX::IntersectsBounded(
|
|
const ExtentBox &extents
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&extents);
|
|
|
|
Verify(minX <= extents.minX);
|
|
Verify(maxX >= extents.maxX);
|
|
Verify(minY <= extents.minY);
|
|
Verify(maxY >= extents.maxY);
|
|
Verify(minZ <= extents.minZ);
|
|
Verify(maxZ >= extents.maxZ);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = extents.maxX - minX;
|
|
Scalar z = extents.minZ - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise >= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndPositiveX::ContainsBounded(const Point3D &point)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(maxY >= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - minX;
|
|
Scalar z = point.z - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise >= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Scalar
|
|
BoxedWedgeFacingNegativeZAndPositiveX::FindDistanceBelowBounded(
|
|
const Point3D &point
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the NW corner the ramp is placed
|
|
// at the origin
|
|
//------------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - minX;
|
|
Scalar z = point.z - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
if (x*rise >= z*run)
|
|
{
|
|
x = point.y - maxY;
|
|
return Max(x,0.0f);
|
|
}
|
|
return -1.0f;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndPositiveX::HitByBounded(
|
|
Line *line,
|
|
Scalar enters,
|
|
Scalar leaves
|
|
)
|
|
{
|
|
Plane
|
|
ramp;
|
|
|
|
ramp.normal.x = minZ - maxZ;
|
|
ramp.normal.y = 0.0f;
|
|
ramp.normal.z = maxX - minX;
|
|
|
|
//
|
|
//-----------------------------
|
|
// Scale the vector to a normal
|
|
//-----------------------------
|
|
//
|
|
Scalar temp = ramp.normal.x*ramp.normal.x + ramp.normal.z*ramp.normal.z;
|
|
Verify(!Small_Enough(temp));
|
|
temp = Sqrt(temp);
|
|
ramp.normal.x /= temp;
|
|
ramp.normal.z /= temp;
|
|
ramp.offset = maxX*ramp.normal.x + maxZ*ramp.normal.z;
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// Now that we have added a new plane into the definition of the convex
|
|
// polyhedron, call a common ramp line collider
|
|
//---------------------------------------------------------------------
|
|
//
|
|
return BoxedRampContainsLine(line, ramp, enters, leaves);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndPositiveX::TestInstance() const
|
|
{
|
|
return solidType == WedgeFacingNegativeZAndPositiveXType;
|
|
}
|
|
|
|
//#############################################################################
|
|
//################# BoxedWedgeFacingPositiveZAndNegativeX ###############
|
|
//#############################################################################
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingPositiveZAndNegativeX::BoxedWedgeFacingPositiveZAndNegativeX(
|
|
const ExtentBox &extents,
|
|
BoxedSolid::Material material,
|
|
Simulation *owner,
|
|
BoxedSolid *next_solid
|
|
):
|
|
BoxedSolid(
|
|
extents,
|
|
WedgeFacingPositiveZAndNegativeXType,
|
|
material,
|
|
owner,
|
|
next_solid
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingPositiveZAndNegativeX::~BoxedWedgeFacingPositiveZAndNegativeX()
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndNegativeX::IntersectsBounded(
|
|
const ExtentBox &extents
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&extents);
|
|
|
|
Verify(minX <= extents.minX);
|
|
Verify(maxX >= extents.maxX);
|
|
Verify(minY <= extents.minY);
|
|
Verify(maxY >= extents.maxY);
|
|
Verify(minZ <= extents.minZ);
|
|
Verify(maxZ >= extents.maxZ);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = minZ - maxZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = extents.minX - maxX;
|
|
Scalar z = extents.maxZ - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise >= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndNegativeX::ContainsBounded(const Point3D &point)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(maxY >= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = minZ - maxZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - maxX;
|
|
Scalar z = point.z - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise >= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Scalar
|
|
BoxedWedgeFacingPositiveZAndNegativeX::FindDistanceBelowBounded(
|
|
const Point3D &point
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the NW corner the ramp is placed
|
|
// at the origin
|
|
//------------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = minZ - maxZ;
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - maxX;
|
|
Scalar z = point.z - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more positive than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run >= z/x yields
|
|
// rise*x >= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
if (x*rise >= z*run)
|
|
{
|
|
x = point.y - maxY;
|
|
return Max(x,0.0f);
|
|
}
|
|
return -1.0f;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndNegativeX::HitByBounded(
|
|
Line *line,
|
|
Scalar enters,
|
|
Scalar leaves
|
|
)
|
|
{
|
|
Plane
|
|
ramp;
|
|
|
|
ramp.normal.x = maxZ - minZ;
|
|
ramp.normal.y = 0.0f;
|
|
ramp.normal.z = minX - maxX;
|
|
|
|
//
|
|
//-----------------------------
|
|
// Scale the vector to a normal
|
|
//-----------------------------
|
|
//
|
|
Scalar temp = ramp.normal.x*ramp.normal.x + ramp.normal.z*ramp.normal.z;
|
|
Verify(!Small_Enough(temp));
|
|
temp = Sqrt(temp);
|
|
ramp.normal.x /= temp;
|
|
ramp.normal.z /= temp;
|
|
ramp.offset = maxX*ramp.normal.x + maxZ*ramp.normal.z;
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// Now that we have added a new plane into the definition of the convex
|
|
// polyhedron, call a common ramp line collider
|
|
//---------------------------------------------------------------------
|
|
//
|
|
return BoxedRampContainsLine(line, ramp, enters, leaves);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndNegativeX::TestInstance() const
|
|
{
|
|
return solidType == WedgeFacingPositiveZAndNegativeXType;
|
|
}
|
|
|
|
//#############################################################################
|
|
//################# BoxedWedgeFacingPositiveZAndPositiveX ###############
|
|
//#############################################################################
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingPositiveZAndPositiveX::BoxedWedgeFacingPositiveZAndPositiveX(
|
|
const ExtentBox &extents,
|
|
BoxedSolid::Material material,
|
|
Simulation *owner,
|
|
BoxedSolid *next_solid
|
|
):
|
|
BoxedSolid(
|
|
extents,
|
|
WedgeFacingPositiveZAndPositiveXType,
|
|
material,
|
|
owner,
|
|
next_solid
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingPositiveZAndPositiveX::~BoxedWedgeFacingPositiveZAndPositiveX()
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndPositiveX::IntersectsBounded(
|
|
const ExtentBox &extents
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&extents);
|
|
|
|
Verify(minX <= extents.minX);
|
|
Verify(maxX >= extents.maxX);
|
|
Verify(minY <= extents.minY);
|
|
Verify(maxY >= extents.maxY);
|
|
Verify(minZ <= extents.minZ);
|
|
Verify(maxZ >= extents.maxZ);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = minZ - maxZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = extents.maxX - minX;
|
|
Scalar z = extents.maxZ - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise <= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndPositiveX::ContainsBounded(const Point3D &point)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(maxY >= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = minZ - maxZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - minX;
|
|
Scalar z = point.z - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise <= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Scalar
|
|
BoxedWedgeFacingPositiveZAndPositiveX::FindDistanceBelowBounded(
|
|
const Point3D &point
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the NW corner the ramp is placed
|
|
// at the origin
|
|
//------------------------------------------------------------------------
|
|
//
|
|
Scalar run = maxX - minX;
|
|
Scalar rise = minZ - maxZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - minX;
|
|
Scalar z = point.z - maxZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
if (x*rise <= z*run)
|
|
{
|
|
x = point.y - maxY;
|
|
return Max(x,0.0f);
|
|
}
|
|
return -1.0f;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndPositiveX::HitByBounded(
|
|
Line *line,
|
|
Scalar enters,
|
|
Scalar leaves
|
|
)
|
|
{
|
|
Plane
|
|
ramp;
|
|
|
|
ramp.normal.x = minZ - maxZ;
|
|
ramp.normal.y = 0.0f;
|
|
ramp.normal.z = minX - maxX;
|
|
|
|
//
|
|
//-----------------------------
|
|
// Scale the vector to a normal
|
|
//-----------------------------
|
|
//
|
|
Scalar temp = ramp.normal.x*ramp.normal.x + ramp.normal.z*ramp.normal.z;
|
|
Verify(!Small_Enough(temp));
|
|
temp = Sqrt(temp);
|
|
ramp.normal.x /= temp;
|
|
ramp.normal.z /= temp;
|
|
ramp.offset = maxX*ramp.normal.x + minZ*ramp.normal.z;
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// Now that we have added a new plane into the definition of the convex
|
|
// polyhedron, call a common ramp line collider
|
|
//---------------------------------------------------------------------
|
|
//
|
|
return BoxedRampContainsLine(line, ramp, enters, leaves);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingPositiveZAndPositiveX::TestInstance() const
|
|
{
|
|
return solidType == WedgeFacingPositiveZAndPositiveXType;
|
|
}
|
|
|
|
//#############################################################################
|
|
//################# BoxedWedgeFacingNegativeZAndNegativeX ###############
|
|
//#############################################################################
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingNegativeZAndNegativeX::BoxedWedgeFacingNegativeZAndNegativeX(
|
|
const ExtentBox &extents,
|
|
BoxedSolid::Material material,
|
|
Simulation *owner,
|
|
BoxedSolid *next_solid
|
|
):
|
|
BoxedSolid(
|
|
extents,
|
|
WedgeFacingNegativeZAndNegativeXType,
|
|
material,
|
|
owner,
|
|
next_solid
|
|
)
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
BoxedWedgeFacingNegativeZAndNegativeX::~BoxedWedgeFacingNegativeZAndNegativeX()
|
|
{
|
|
Check_Pointer(this);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndNegativeX::IntersectsBounded(
|
|
const ExtentBox &extents
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&extents);
|
|
|
|
Verify(minX <= extents.minX);
|
|
Verify(maxX >= extents.maxX);
|
|
Verify(minY <= extents.minY);
|
|
Verify(maxY >= extents.maxY);
|
|
Verify(minZ <= extents.minZ);
|
|
Verify(maxZ >= extents.maxZ);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = extents.minX - maxX;
|
|
Scalar z = extents.minZ - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise <= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndNegativeX::ContainsBounded(const Point3D &point)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(maxY >= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//----------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the base of the ramp is placed
|
|
// at the origin
|
|
//----------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - maxX;
|
|
Scalar z = point.z - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
return x*rise <= z*run;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Scalar
|
|
BoxedWedgeFacingNegativeZAndNegativeX::FindDistanceBelowBounded(
|
|
const Point3D &point
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&point);
|
|
|
|
Verify(minX <= point.x);
|
|
Verify(maxX >= point.x);
|
|
Verify(minY <= point.y);
|
|
Verify(minZ <= point.z);
|
|
Verify(maxZ >= point.z);
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// Calculate the "slope" of the ramp when the NW corner the ramp is placed
|
|
// at the origin
|
|
//------------------------------------------------------------------------
|
|
//
|
|
Scalar run = minX - maxX;
|
|
Scalar rise = maxZ - minZ;
|
|
Verify(!Small_Enough(run));
|
|
|
|
//
|
|
//-------------------------------------------------------------------
|
|
// Calculate the "slope" of the line from the base of the ramp to the
|
|
// lower-north edge of the block
|
|
//-------------------------------------------------------------------
|
|
//
|
|
Scalar x = point.x - maxX;
|
|
Scalar z = point.z - minZ;
|
|
|
|
//
|
|
//------------------------------------------------------------------------
|
|
// If the slope rise/run is more negative than z/x slope, then the extent
|
|
// box of the disk has clipped the ramp. Note that rise/run <= z/x yields
|
|
// rise*x <= z*run, which avoids any divide-by-0 errors.
|
|
//------------------------------------------------------------------------
|
|
//
|
|
if (x*rise <= z*run)
|
|
{
|
|
x = point.y - maxY;
|
|
return Max(x,0.0f);
|
|
}
|
|
return -1.0f;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndNegativeX::HitByBounded(
|
|
Line *line,
|
|
Scalar enters,
|
|
Scalar leaves
|
|
)
|
|
{
|
|
Plane
|
|
ramp;
|
|
|
|
ramp.normal.x = maxZ - minZ;
|
|
ramp.normal.y = 0.0f;
|
|
ramp.normal.z = maxX - minX;
|
|
|
|
//
|
|
//-----------------------------
|
|
// Scale the vector to a normal
|
|
//-----------------------------
|
|
//
|
|
Scalar temp = ramp.normal.x*ramp.normal.x + ramp.normal.z*ramp.normal.z;
|
|
Verify(!Small_Enough(temp));
|
|
temp = Sqrt(temp);
|
|
ramp.normal.x /= temp;
|
|
ramp.normal.z /= temp;
|
|
ramp.offset = minX*ramp.normal.x + maxZ*ramp.normal.z;
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// Now that we have added a new plane into the definition of the convex
|
|
// polyhedron, call a common ramp line collider
|
|
//---------------------------------------------------------------------
|
|
//
|
|
return BoxedRampContainsLine(line, ramp, enters, leaves);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
//
|
|
Logical
|
|
BoxedWedgeFacingNegativeZAndNegativeX::TestInstance() const
|
|
{
|
|
return solidType == WedgeFacingNegativeZAndNegativeXType;
|
|
}
|
|
|