Advertisement
SongJo

Gamemaker - Room Coordinates to Quadrilateral Coordinates

Mar 25th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Quadrilateral Coordinates
  2. // Top Left
  3. X[0,0] = 50;
  4. Y[0,0] = 0;
  5.  
  6. // Top Right
  7. X[1,0] = room_width - 100;
  8. Y[1,0] = 0;
  9.  
  10. // Bottom Left
  11. X[0,1] = 0;
  12. Y[0,1] = room_height - 100;
  13.  
  14. // Bottom Right
  15. X[1,1] = room_width;
  16. Y[1,1] = room_height;
  17.  
  18. // Translate mouse coordinates from room space to quadrilateral space
  19. // Get mouse position in room space as a percentage
  20. var xReal = 100 / room_width * mouse_x;
  21. var yReal = 100 / room_height * mouse_y;
  22.  
  23. // Get the length of the top of the quadrilateral
  24. var len1 = point_distance(X[0,0],Y[0,0], X[1,0],Y[1,0]);
  25. // Get the angle between the top left and top right points
  26. var dir1 = point_direction(X[0,0],Y[0,0], X[1,0],Y[1,0]);
  27.  
  28. // Get the length of the bottom of the quadrilateral
  29. var len2 = point_distance(X[0,1],Y[0,1], X[1,1],Y[1,1]);
  30. // Get the angle between the bottom left and bottom right points
  31. var dir2 = point_direction(X[0,1],Y[0,1], X[1,1],Y[1,1]);
  32.  
  33. // Set a point along the top of the quadrilateral to represent where the mouse is in relation to the room
  34. var x1 = X[0,0] + lengthdir_x(len1 / 100 * xReal, dir1);
  35. var y1 = Y[0,0] + lengthdir_y(len1 / 100 * xReal, dir1);
  36.  
  37. // Set a point along the bottom of the quadrilateral to represent where the mouse is in relation to the room
  38. var x2 = X[0,1] + lengthdir_x(len2 / 100 * xReal, dir2);
  39. var y2 = Y[0,1] + lengthdir_y(len2 / 100 * xReal, dir2);
  40.  
  41. // Get the length of the left side of the quadrilateral
  42. len1 = point_distance(X[0,0],Y[0,0], X[0,1],Y[0,1]);
  43. // Get the angle between the top left and bottom left points
  44. dir1 = point_direction(X[0,0],Y[0,0], X[0,1],Y[0,1]);
  45.  
  46. // Get the length of the right side of the quadrilateral
  47. len2 = point_distance(X[1,0],Y[1,0], X[1,1],Y[1,1]);
  48. // Get the angle between the top right and bottom right points
  49. dir2 = point_direction(X[1,0],Y[1,0], X[1,1],Y[1,1]);
  50.  
  51. // Set a point along the left side of the quadrilateral to represent where the mouse is in relation to the room
  52. var x3 = X[0,0] + lengthdir_x(len1 / 100 * yReal, dir1);
  53. var y3 = Y[0,0] + lengthdir_y(len1 / 100 * yReal, dir1);
  54.  
  55. // Set a point along the right side of the quadrilateral to represent where the mouse is in relation to the room
  56. var x4 = X[1,0] + lengthdir_x(len2 / 100 * yReal, dir2);
  57. var y4 = Y[1,0] + lengthdir_y(len2 / 100 * yReal, dir2);
  58.  
  59. // Get the distance between the points just created and change its length based on the xReal percentage
  60. len1 = point_distance(x1,y1, x2,y2) / 100 * yReal;
  61. // Get the angle between the points just created
  62. dir1 = point_direction(x1,y1, x2,y2);
  63.  
  64. // The final coordinates of the mouse from room space to quadrilateral space
  65. var xx = x1 + lengthdir_x(len1, dir1);
  66. var yy = y1 + lengthdir_y(len1, dir1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement