Recast: add helper function to calculate slope angle from 2 points

This commit is contained in:
Kawe Mazidjatari 2024-08-09 12:49:11 +02:00
parent 24e09b4b6c
commit 1a393e6330
2 changed files with 19 additions and 0 deletions

View File

@ -386,6 +386,12 @@ inline bool rdOverlapBounds(const float* amin, const float* amax,
return overlap;
}
/// Derives the slope angle from 2 points.
/// @param[in] v1 The start vector. [(x, y, z)]
/// @param[in] v2 The end vector. [(x, y, z)]
/// @return The slope angle between the 2 points.
float rdCalcSlopeAngle(const float* v1, const float* v2);
/// Derives the closest point on a triangle from the specified reference point.
/// @param[out] closest The closest point on the triangle.
/// @param[in] p The reference point from which to test. [(x, y, z)]

View File

@ -21,6 +21,19 @@
//////////////////////////////////////////////////////////////////////////////////////////
float rdCalcSlopeAngle(const float* v1, const float* v2)
{
const float deltaX = v2[0] - v1[0];
const float deltaY = v2[1] - v1[1];
const float deltaZ = v2[2] - v1[2];
const float horizontalDistance = rdMathSqrtf((deltaX*deltaX)+(deltaY*deltaY));
const float slopeAngleRadians = rdMathAtan2f(deltaZ, horizontalDistance);
const float slopeAngleDegrees = slopeAngleRadians*(180.0f/RD_PI);
return slopeAngleDegrees;
}
void rdClosestPtPointTriangle(float* closest, const float* p,
const float* a, const float* b, const float* c)
{