Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Uses a binary sweep to return the collision point of a line
- function collision_line_point(_x1, _y1, _x2, _y2, _obj, _prec, _notme)
- {
- var _inst = collision_line(_x1, _y1, _x2, _y2, _obj, _prec, _notme),
- _rx = _x2,
- _ry = _y2;
- if (_inst != noone)
- {
- var _t0 = 0,
- _t1 = 1;
- repeat (ceil(log2(point_distance(_x1, _y1, _x2, _y2))) + 1)
- {
- var _t = _t0 + (_t1 - _t0) * 0.5,
- _bx = _x1 + (_x2 - _x1) * _t,
- _by = _y1 + (_y2 - _y1) * _t,
- _ax = _x1 + (_x2 - _x1) * _t0,
- _ay = _y1 + (_y2 - _y1) * _t0,
- _inst2 = collision_line(_ax, _ay, _bx, _by, _obj, _prec, _notme);
- if (_inst2 != noone)
- {
- _inst = _inst2;
- _rx = _bx;
- _ry = _by;
- _t1 = _t;
- }
- else
- {
- _t0 = _t;
- }
- }
- }
- // If there is no hit then _inst will be noone
- return [_inst, _rx, _ry];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement