diff options
author | shfil <filip.gawin@zoho.com> | 2021-01-24 12:35:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 12:35:45 +0100 |
commit | ca1de3cd173efc3e7c838e0dfb167269850e76e0 (patch) | |
tree | fa1460831e7028fc5f28b8cd28982af46e46aeec | |
parent | 4e477a17b2fe603a47956afade96cf0ef615f325 (diff) |
Fix CCollision::DistToLine
-rw-r--r-- | src/collision/Collision.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index 45a15628..bead5183 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -2099,12 +2099,12 @@ CCollision::DistToLine(const CVector *l0, const CVector *l1, const CVector *poin float dot = DotProduct(*point - *l0, *l1 - *l0); // Between 0 and len we're above the line. // if not, calculate distance to endpoint - if(dot <= 0.0f) - return (*point - *l0).Magnitude(); - if(dot >= lensq) - return (*point - *l1).Magnitude(); + if(dot <= 0.0f) return (*point - *l0).Magnitude(); + if(dot >= lensq) return (*point - *l1).Magnitude(); // distance to line - return Sqrt((*point - *l0).MagnitudeSqr() - dot*dot/lensq); + float distSqr = (*point - *l0).MagnitudeSqr() - dot * dot / lensq; + if(distSqr <= 0.f) return 0.f; + return Sqrt(distSqr); } // same as above but also return the point on the line @@ -2571,4 +2571,4 @@ CCollision::DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); -}
\ No newline at end of file +} |