Created
July 2, 2021 17:16
-
-
Save squircledev/7b5a9e4db02b69b6c5db5b8347404e64 to your computer and use it in GitHub Desktop.
seg/line/ray in plane collision math GML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sd_seg_in_plane(_r0, _r1, _plane) | |
{ | |
var _ab = vec3_subtract(_r0, _r1); | |
var _pn = sd_plane_get_normal(_plane); | |
var _pd = sd_plane_get_distance(_plane); | |
var _t = (_pd - vec3_dot(_pn, _r0)) / vec3_dot(_pn, _ab); | |
if(_t >= 0 and _t <= 1) | |
{ | |
var _q = vec3_add(_r0, vec3_scale(_ab, _t)); | |
return sd_collision_return(true, _plane, _q); | |
} | |
else | |
{ | |
return sd_collision_return(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment