summaryrefslogtreecommitdiffstats
path: root/src/collision/Collision.cpp
diff options
context:
space:
mode:
authorshfil <filip.gawin@zoho.com>2021-01-24 12:34:40 +0100
committerGitHub <noreply@github.com>2021-01-24 12:34:40 +0100
commit3e6bb267f3d9834a1f341449945cac43563cffc2 (patch)
tree456eb9e035b1876aacd19bc0d09483d1b4124f3d /src/collision/Collision.cpp
parentenable default resolution for vanilla defines (diff)
downloadre3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar.gz
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar.bz2
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar.lz
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar.xz
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.tar.zst
re3-3e6bb267f3d9834a1f341449945cac43563cffc2.zip
Diffstat (limited to '')
-rw-r--r--src/collision/Collision.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp
index 7fb5c30b..396e3b85 100644
--- a/src/collision/Collision.cpp
+++ b/src/collision/Collision.cpp
@@ -2245,12 +2245,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
@@ -2733,4 +2733,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
+}