xCollide: xSphereHitsBox and xBoxHitsSphere (#353)

This commit is contained in:
escape209 2024-08-15 18:29:00 +01:00 committed by GitHub
parent a377f7d4b1
commit 7965a3ce42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,6 +87,104 @@ void xCollideInit(xScene* sc)
iCollideInit(sc);
}
U32 xBoxHitsSphere(const xBox* a, const xSphere* b, xCollis* coll)
{
U32 uVar1;
xIsect isx;
iBoxIsectSphere(a, b, &isx);
if (!(isx.penned <= 0.0f))
{
uVar1 = 0;
coll->flags &= 0xfffffffe;
}
else
{
if (isx.contained <= 0.0f)
{
coll->flags |= 0x10;
}
coll->dist = isx.dist;
if (coll->flags & 0x0400)
{
xVec3Copy(&coll->tohit, &isx.norm);
}
if ((coll->flags & 0x800) != 0)
{
if (isx.dist == 0.0f)
{
xVec3Copy(&coll->depen, &g_O3);
}
else
{
xVec3SMul(&coll->depen, &isx.norm, isx.penned / isx.dist);
}
}
if ((coll->flags & 0x1200) != 0)
{
xVec3Normalize(&coll->hdng, &isx.norm);
}
if ((coll->flags & 0x200) != 0)
{
xVec3Inv(&coll->norm, &coll->hdng);
}
uVar1 = 1;
coll->flags |= 1;
}
return uVar1;
}
U32 xSphereHitsBox(const xSphere* a, const xBox* b, xCollis* coll)
{
U32 uVar1;
xIsect isx;
iBoxIsectSphere(b, a, &isx);
if (!(isx.penned <= 0.0f))
{
uVar1 = 0;
coll->flags &= 0xfffffffe;
}
else
{
if (isx.contained <= 0.0f)
{
coll->flags |= 0x10;
}
coll->dist = isx.dist;
if (coll->flags & 0x0400)
{
xVec3Copy(&coll->tohit, &isx.norm);
}
if ((coll->flags & 0x800) != 0)
{
if (isx.dist == 0.0f)
{
xVec3Copy(&coll->depen, &g_O3);
}
else
{
xVec3SMul(&coll->depen, &isx.norm, isx.penned / isx.dist);
}
}
if ((coll->flags & 0x1200) != 0)
{
xVec3Normalize(&coll->hdng, &isx.norm);
}
if ((coll->flags & 0x200) != 0)
{
xVec3Inv(&coll->norm, &coll->hdng);
}
uVar1 = 1;
coll->flags |= 1;
}
return uVar1;
}
U32 xSphereHitsSphere(const xSphere* a, const xSphere* b, xCollis* coll)
{
U32 uVar1;