Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. int tracelinetoplane_behindplane;
  2. vector TraceLineToPlane(vector line_start, vector line_end, vector plane_normal, vector plane_point)
  3. {
  4. tracelinetoplane_behindplane = FALSE;
  5.  
  6. vector v = line_end-line_start;
  7. vector n = plane_normal;
  8. float d = -(plane_normal*plane_point);
  9.  
  10. // dot products
  11. float dot1 = n*v;
  12. float dot2 = n*line_start;
  13.  
  14. if(plane_normal*(line_end-plane_point) > 0) // the end isn't on or behind the plane (ignores reverse intersection, and non-intersections)
  15. return line_end;
  16. else
  17. if(plane_normal*(line_start-plane_point) <= 0) // both ends are behind the plane (or on it)
  18. {
  19. tracelinetoplane_behindplane = TRUE;
  20. return line_end;
  21. }
  22.  
  23. // line is parallel with plane
  24. if(dot1 == 0)
  25. return line_end; // return original end point
  26.  
  27. float t = -(dot2 + d) / dot1;
  28. return line_start + (t * v);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement