Fix inverted checks in ray intersection functions
All checks were successful
CI / build-and-analyze (push) Successful in 35s
All checks were successful
CI / build-and-analyze (push) Successful in 35s
This commit is contained in:
10
Ray2f.c
10
Ray2f.c
@@ -53,7 +53,7 @@ int CgeRay2fIntersectRay(const float aStart[2], const float aDirection[2],
|
|||||||
float tmp[2];
|
float tmp[2];
|
||||||
float time1, time2;
|
float time1, time2;
|
||||||
|
|
||||||
if (CgeRay2fIntersectTime(aStart, aDirection, bStart, bDirection, &time1, &time2))
|
if (!CgeRay2fIntersectTime(aStart, aDirection, bStart, bDirection, &time1, &time2))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (time1 < 0.0f || time2 < 0.0f)
|
if (time1 < 0.0f || time2 < 0.0f)
|
||||||
@@ -72,7 +72,7 @@ int CgeRay2fIntersectSegment(const float aStart[2], const float aDirection[2],
|
|||||||
float time1, time2;
|
float time1, time2;
|
||||||
|
|
||||||
CgeVec2fSub(bEnd, bStart, tmp);
|
CgeVec2fSub(bEnd, bStart, tmp);
|
||||||
if (CgeRay2fIntersectTime(aStart, aDirection, bStart, tmp, &time1, &time2))
|
if (!CgeRay2fIntersectTime(aStart, aDirection, bStart, tmp, &time1, &time2))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (time1 < 0.0f || time2 < 0.0f || time2 > 1.0f)
|
if (time1 < 0.0f || time2 < 0.0f || time2 > 1.0f)
|
||||||
@@ -113,7 +113,7 @@ int CgeSegment2fIntersectSegment(const float aStart[2], const float aEnd[2],
|
|||||||
|
|
||||||
CgeVec2fSub(aEnd, aStart, tmp1);
|
CgeVec2fSub(aEnd, aStart, tmp1);
|
||||||
CgeVec2fSub(bEnd, bStart, tmp2);
|
CgeVec2fSub(bEnd, bStart, tmp2);
|
||||||
if (CgeRay2fIntersectTime(aStart, tmp1, bStart, tmp2, &time1, &time2))
|
if (!CgeRay2fIntersectTime(aStart, tmp1, bStart, tmp2, &time1, &time2))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (time1 < 0.0f || time1 > 1.0f || time2 < 0.0f || time2 > 1.0f)
|
if (time1 < 0.0f || time1 > 1.0f || time2 < 0.0f || time2 > 1.0f)
|
||||||
@@ -135,7 +135,7 @@ int CgeRay2fIntersectBox2f(const float aStart[2], const float aDirection[2],
|
|||||||
timeFar = 1.0f / 0.0f;
|
timeFar = 1.0f / 0.0f;
|
||||||
|
|
||||||
/* Check if origin inside box */
|
/* Check if origin inside box */
|
||||||
if (!CgeBox2fContains(bMin, bMax, aStart)) {
|
if (CgeBox2fContains(bMin, bMax, aStart)) {
|
||||||
memcpy(out, aStart, sizeof(float) * 2);
|
memcpy(out, aStart, sizeof(float) * 2);
|
||||||
*t = 0.0f;
|
*t = 0.0f;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -182,7 +182,7 @@ int CgeSegment2fIntersectBox2f(const float aStart[2], const float aEnd[2],
|
|||||||
float time;
|
float time;
|
||||||
|
|
||||||
CgeVec2fSub(aEnd, aStart, tmp);
|
CgeVec2fSub(aEnd, aStart, tmp);
|
||||||
if (CgeRay2fIntersectBox2f(aStart, tmp, bMin, bMax, &time, out))
|
if (!CgeRay2fIntersectBox2f(aStart, tmp, bMin, bMax, &time, out))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (time > 1.0f)
|
if (time > 1.0f)
|
||||||
|
|||||||
12
Ray3f.c
12
Ray3f.c
@@ -33,11 +33,11 @@ int CgeRay3fIntersectTriangle(const float start[3], const float direction[3],
|
|||||||
float time;
|
float time;
|
||||||
|
|
||||||
/* Compute plane */
|
/* Compute plane */
|
||||||
if (CgePlaneFromPoints(a, b, c, plane))
|
if (!CgePlaneFromPoints(a, b, c, plane))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Compute intersection point in ray against plane */
|
/* Compute intersection point in ray against plane */
|
||||||
if (CgeRay3fIntersectPlane(start, direction, plane, &time, tmp3))
|
if (!CgeRay3fIntersectPlane(start, direction, plane, &time, tmp3))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Check if point inside rectangle */
|
/* Check if point inside rectangle */
|
||||||
@@ -94,11 +94,11 @@ int CgeSegment3fIntersectTriangle(const float start[3], const float end[3],
|
|||||||
float time;
|
float time;
|
||||||
|
|
||||||
/* Compute plane */
|
/* Compute plane */
|
||||||
if (CgePlaneFromPoints(a, b, c, plane))
|
if (!CgePlaneFromPoints(a, b, c, plane))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Compute intersection point in ray against plane */
|
/* Compute intersection point in ray against plane */
|
||||||
if (CgeSegment3fIntersectPlane(start, end, plane, &time, tmp3))
|
if (!CgeSegment3fIntersectPlane(start, end, plane, &time, tmp3))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Check if point inside rectangle */
|
/* Check if point inside rectangle */
|
||||||
@@ -136,7 +136,7 @@ int CgeRay3fIntersectBox3f(const float aStart[3], const float aDirection[3],
|
|||||||
timeFar = 1.0f / 0.0f;
|
timeFar = 1.0f / 0.0f;
|
||||||
|
|
||||||
/* Check if origin inside box */
|
/* Check if origin inside box */
|
||||||
if (!CgeBox3fContains(bMin, bMax, aStart)) {
|
if (CgeBox3fContains(bMin, bMax, aStart)) {
|
||||||
memcpy(out, aStart, sizeof(float) * 3);
|
memcpy(out, aStart, sizeof(float) * 3);
|
||||||
*t = 0.0f;
|
*t = 0.0f;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -184,7 +184,7 @@ int CgeSegment3fIntersectBox3f(const float aStart[3], const float aEnd[3],
|
|||||||
float time;
|
float time;
|
||||||
|
|
||||||
CgeVec3fSub(aEnd, aStart, tmp);
|
CgeVec3fSub(aEnd, aStart, tmp);
|
||||||
if (CgeRay3fIntersectBox3f(aStart, tmp, bMin, bMax, &time, out))
|
if (!CgeRay3fIntersectBox3f(aStart, tmp, bMin, bMax, &time, out))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (time > 1.0f)
|
if (time > 1.0f)
|
||||||
|
|||||||
Reference in New Issue
Block a user