Change line-point intersection check to no longer be constrained to 3D space only
This commit is contained in:
parent
fd282607ae
commit
aea6fb5320
@ -103,15 +103,18 @@ namespace egn{
|
||||
math::vec3<float> ab = (l.point2 - l.point1);
|
||||
math::vec3<float> ac = (r - l.point1);
|
||||
|
||||
//check if the point and line are colinear
|
||||
if(math::fuzzy_neq(math::cross(ab, ac), math::vec3<float>(math::zero_initialize), epsilon))
|
||||
//check if point is within the line segment
|
||||
float c1 = ac * ab;
|
||||
if(c1 < (0 - epsilon))
|
||||
return false;
|
||||
float c2 = ab * ab;
|
||||
if(c2 < (c1 - epsilon))
|
||||
return false;
|
||||
|
||||
//check if the point is between the endpoints of the line segment
|
||||
float value = (ab * ac) / (ab * ab);
|
||||
if(value >= (0.0f - epsilon) && value <= (1.0f + epsilon))
|
||||
return true;
|
||||
return false;
|
||||
//check if the point is zero distance from the line
|
||||
float b = c1 / c2;
|
||||
math::vec3<float> pb = l.point1 + (ab * b);
|
||||
return math::fuzzy_eq(r - pb, math::vec3<float>(math::zero_initialize), epsilon);
|
||||
}
|
||||
bool check_collision(const plane& l, const plane& r, float epsilon){
|
||||
(void)l;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user