Signature
stock bool:xs_plane_rayintersect(const Float:plane[], const Float:rayStart[], const Float:rayDir[], Float:out[]){ new Float:a = xs_vec_dot(plane, rayDir); if(a == 0.0) return false; // ray is parallel to plane // if(distance plane<->(rayStart + rayDir) > distance plane<->rayStart) and both have the same sign, the ray // goes away from the plane new Float:rsplusrd[3]; xs_vec_add(rayStart, rayDir, rsplusrd); new Float:dst1 = xs_plane_dst2point(plane, rsplusrd); new Float:dst2 = xs_plane_dst2point(plane, rayStart); if(xs_fabs(dst1) > xs_fabs(dst2) && xs_fsign(dst1) == xs_fsign(dst2)) return false; // out = rayStart - rayDir * ((distance plane<->rayStart) / a) new Float:__tmp[3]; xs_vec_mul_scalar(rayDir, xs_plane_dst2point(plane, rayStart) / a, __tmp); // out = rayStart - tmp xs_vec_sub(rayStart, __tmp, out); return true;}
Description
Checks whether a plane intersects with the ray starting at @rayStart and
going to @rayDir direction.
If it does intersect, outputs the intersection point in @out.
Parameters
- plane — The plane to check intersection with.
- rayStart — The starting point of the ray.
- rayDir — Direction in which the ray is going.
- out — The vector to copy the intersection point to, if it exists.
Returns
true if they intersect, false otherwise.