Recast: add functions for checking if point is in cylinder and AABB

This commit is contained in:
Kawe Mazidjatari 2024-09-20 16:00:23 +02:00
parent 162f5fb3c7
commit 32f470f2ed
2 changed files with 42 additions and 0 deletions

View File

@ -541,6 +541,21 @@ unsigned char rdClassifyPointOutsideBounds(const float* pt, const float* bmin, c
unsigned char rdClassifyPointInsideBounds(const float* pt, const float* bmin, const float* bmax);
unsigned char rdClassifyDirection(const float* dir, const float* bmin, const float* bmax);
/// Determines if the specified point is inside the axis-aligned bounding box.
/// @param[in] pt The point to check. [(x, y, z)]
/// @param[in] bmin Minimum bounds of the box. [(x, y, z)]
/// @param[in] bmax Maximum bounds of the box. [(x, y, z)]
/// @return True if the point is inside the axis-aligned bounding box.
bool rdPointInAABB(const float* pt, const float* bmin, const float* bmax);
/// Determines if the specified point is inside the cylinder on the xy-plane.
/// @param[in] pt The point to check. [(x, y, z)]
/// @param[in] pos The position of the cylinder. [(x, y, z)]
/// @param[in] radius The radius of the cylinder.
/// @param[in] height The height of the cylinder.
/// @return True if the point is inside the cylinder.
bool rdPointInCylinder(const float* pt, const float* pos, const float radius, const float height);
/// Determines if the specified point is inside the convex polygon on the xy-plane.
/// @param[in] pt The point to check. [(x, y, z)]
/// @param[in] verts The polygon vertices. [(x, y, z) * @p nverts]

View File

@ -329,6 +329,33 @@ bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b
return false;
}
bool rdPointInAABB(const float* pt, const float* bmin, const float* bmax)
{
if (pt[0] >= bmin[0] && pt[0] <= bmax[0] &&
pt[1] >= bmin[1] && pt[1] <= bmax[1] &&
pt[2] >= bmin[2] && pt[2] <= bmax[2])
{
return true;
}
return false;
}
bool rdPointInCylinder(const float* pt, const float* pos, const float radius, const float height)
{
const float dx = pt[0] - pos[0];
const float dy = pt[1] - pos[1];
const float distSquared = dx*dx + dy*dy;
if (distSquared <= radius * radius &&
pt[2] >= pos[2] && pt[2] <= (pos[2] + height))
{
return true;
}
return false;
}
/// @par
///
/// All points are projected onto the xy-plane, so the z-values are ignored.