Advertisement
gmlscripts

draw_rectangle_rotated

Aug 18th, 2018
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// draw_rectangle_rotated(x1, y1, x2, y2, xp, yp, angle, outline)
  2. //
  3. //  Draws a rectangle rotated about a point by a given number of degress.
  4. //
  5. //      x1          x-coordinate of top-left corner
  6. //      y1          y-coordinate of top-left corner
  7. //      x2          x-coordinate of bottom-right corner
  8. //      y2          y-coordinate of bottom-right corner
  9. //      xp          x-coordinate to rotate about
  10. //      xp          y-coordinate to rotate about
  11. //      angle       angle to rotate by in degrees
  12. //      outline     draw filled (false), or outlined (true)
  13. //
  14. /// GMLscripts.com/license
  15. {
  16.     var x1 = argument0,
  17.         y1 = argument1,
  18.         x2 = argument2,
  19.         y2 = argument3,
  20.         xp = argument4,
  21.         yp = argument5,
  22.         angle = argument6,
  23.         outline = argument7;
  24.  
  25.     var w, m;
  26.     //  Get Current World Transformation
  27.     w = matrix_get(matrix_world);
  28.     //  Move Rotation Point to Origin
  29.     m = matrix_multiply(w, matrix_build(-xp, -yp, 0, 0, 0, 0, 1, 1, 1));
  30.     //  Rotate and Move Back
  31.     m = matrix_multiply(m, matrix_build(xp, yp, 0, 0, 0, angle, 1, 1, 1));
  32.     //  Set New World Transformation
  33.     matrix_set(matrix_world, m);
  34.     //  Draw Rectangle
  35.     draw_rectangle(x1, y1, x2, y2, outline);
  36.     //  Restore Old World Transformation
  37.     matrix_set(matrix_world, w);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement