Skip to content

Commit

Permalink
xCollide: xSphereHitsBox and xBoxHitsSphere (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
escape209 authored Aug 15, 2024
1 parent a377f7d commit 7965a3c
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/SB/Core/x/xCollide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7965a3c

Please sign in to comment.