Fix CCollision::DistToLine

This commit is contained in:
shfil 2021-01-24 12:34:40 +01:00 committed by GitHub
parent 5183d7cf0f
commit 3e6bb267f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}