Skip to content

Commit

Permalink
Added point_in_parallelogram()
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxyOfJungle committed Jun 20, 2023
1 parent 00eff70 commit 6997375
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/// @desc This function returns a boolean (true or false) depending on whether the position is inside a triangle.
/// @param {real} px The x position, example: mouse_x.
/// @param {real} py The y position, example: mouse_y.
/// @param {real} x The x origin of the cone
/// @param {real} y The y origin of the cone
/// @param {real} x The x origin of the cone.
/// @param {real} y The y origin of the cone.
/// @param {real} angle The cone angle/direction.
/// @param {real} dist The cone distance.
/// @param {real} fov The cone field of view.
Expand All @@ -21,8 +21,8 @@ function point_in_cone(px, py, x, y, angle, dist, fov) {
/// @desc This function returns a boolean (true or false) depending on whether the position is inside a arc.
/// @param {real} px The x position, example: mouse_x.
/// @param {real} py The y position, example: mouse_y.
/// @param {real} x The x origin of the cone
/// @param {real} y The y origin of the cone
/// @param {real} x The x origin of the cone.
/// @param {real} y The y origin of the cone.
/// @param {real} angle The cone angle/direction.
/// @param {real} dist The cone distance.
/// @param {real} fov The cone field of view.
Expand All @@ -31,6 +31,19 @@ function point_in_arc(px, py, x, y, angle, dist, fov) {
return (point_distance(px, py, x, y) < dist && abs(angle_difference(angle, point_direction(x, y, px, py))) < fov/2);
}

/// @desc Checks if a point is inside a parallelogram.
/// @param {real} x The x position to check.
/// @param {real} y The y position to check.
/// @param {array} parallelogram Parallelogram points.
/// @returns {bool}
function point_in_parallelogram(px, py, parallelogram) {
// in first
if (point_in_triangle(px, py, parallelogram[0], parallelogram[1], parallelogram[2], parallelogram[3], parallelogram[6], parallelogram[7])) return true;
// in second
if (point_in_triangle(px, py, parallelogram[4], parallelogram[5], parallelogram[2], parallelogram[3], parallelogram[6], parallelogram[7])) return true;
return false;
}

/// @desc This function is used to check collisions without slope support.
/// @param {real} hspd The horizontal vector speed.
/// @param {real} vspd The vertical vector speed.
Expand Down
8 changes: 0 additions & 8 deletions scripts/__tgm_zunused/__tgm_zunused.gml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
// );
//}

//function point_in_parallelogram(px, py, parallelogram) {
// // in first
// if point_in_triangle(px, py, parallelogram[0], parallelogram[1], parallelogram[2], parallelogram[3], parallelogram[6], parallelogram[7]) return true;
// // in second
// if point_in_triangle(px, py, parallelogram[4], parallelogram[5], parallelogram[2], parallelogram[3], parallelogram[6], parallelogram[7]) return true;
// return false;
//}

//function raycast_hit_point_2d(origin_x, origin_y, object, angle, distance, precise=false, ray_precision=4) {
// var _xo = origin_x,
// _yo = origin_y,
Expand Down

0 comments on commit 6997375

Please sign in to comment.