Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int tracelinetoplane_behindplane;
- vector TraceLineToPlane(vector line_start, vector line_end, vector plane_normal, vector plane_point)
- {
- tracelinetoplane_behindplane = FALSE;
- vector v = line_end-line_start;
- vector n = plane_normal;
- float d = -(plane_normal*plane_point);
- // dot products
- float dot1 = n*v;
- float dot2 = n*line_start;
- if(plane_normal*(line_end-plane_point) > 0) // the end isn't on or behind the plane (ignores reverse intersection, and non-intersections)
- return line_end;
- else
- if(plane_normal*(line_start-plane_point) <= 0) // both ends are behind the plane (or on it)
- {
- tracelinetoplane_behindplane = TRUE;
- return line_end;
- }
- // line is parallel with plane
- if(dot1 == 0)
- return line_end; // return original end point
- float t = -(dot2 + d) / dot1;
- return line_start + (t * v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement