mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: add functions for checking if point is in cylinder and AABB
This commit is contained in:
parent
162f5fb3c7
commit
32f470f2ed
@ -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]
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user