Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Quadrilateral Coordinates
- // Top Left
- X[0,0] = 50;
- Y[0,0] = 0;
- // Top Right
- X[1,0] = room_width - 100;
- Y[1,0] = 0;
- // Bottom Left
- X[0,1] = 0;
- Y[0,1] = room_height - 100;
- // Bottom Right
- X[1,1] = room_width;
- Y[1,1] = room_height;
- // Translate mouse coordinates from room space to quadrilateral space
- // Get mouse position in room space as a percentage
- var xReal = 100 / room_width * mouse_x;
- var yReal = 100 / room_height * mouse_y;
- // Get the length of the top of the quadrilateral
- var len1 = point_distance(X[0,0],Y[0,0], X[1,0],Y[1,0]);
- // Get the angle between the top left and top right points
- var dir1 = point_direction(X[0,0],Y[0,0], X[1,0],Y[1,0]);
- // Get the length of the bottom of the quadrilateral
- var len2 = point_distance(X[0,1],Y[0,1], X[1,1],Y[1,1]);
- // Get the angle between the bottom left and bottom right points
- var dir2 = point_direction(X[0,1],Y[0,1], X[1,1],Y[1,1]);
- // Set a point along the top of the quadrilateral to represent where the mouse is in relation to the room
- var x1 = X[0,0] + lengthdir_x(len1 / 100 * xReal, dir1);
- var y1 = Y[0,0] + lengthdir_y(len1 / 100 * xReal, dir1);
- // Set a point along the bottom of the quadrilateral to represent where the mouse is in relation to the room
- var x2 = X[0,1] + lengthdir_x(len2 / 100 * xReal, dir2);
- var y2 = Y[0,1] + lengthdir_y(len2 / 100 * xReal, dir2);
- // Get the length of the left side of the quadrilateral
- len1 = point_distance(X[0,0],Y[0,0], X[0,1],Y[0,1]);
- // Get the angle between the top left and bottom left points
- dir1 = point_direction(X[0,0],Y[0,0], X[0,1],Y[0,1]);
- // Get the length of the right side of the quadrilateral
- len2 = point_distance(X[1,0],Y[1,0], X[1,1],Y[1,1]);
- // Get the angle between the top right and bottom right points
- dir2 = point_direction(X[1,0],Y[1,0], X[1,1],Y[1,1]);
- // Set a point along the left side of the quadrilateral to represent where the mouse is in relation to the room
- var x3 = X[0,0] + lengthdir_x(len1 / 100 * yReal, dir1);
- var y3 = Y[0,0] + lengthdir_y(len1 / 100 * yReal, dir1);
- // Set a point along the right side of the quadrilateral to represent where the mouse is in relation to the room
- var x4 = X[1,0] + lengthdir_x(len2 / 100 * yReal, dir2);
- var y4 = Y[1,0] + lengthdir_y(len2 / 100 * yReal, dir2);
- // Get the distance between the points just created and change its length based on the xReal percentage
- len1 = point_distance(x1,y1, x2,y2) / 100 * yReal;
- // Get the angle between the points just created
- dir1 = point_direction(x1,y1, x2,y2);
- // The final coordinates of the mouse from room space to quadrilateral space
- var xx = x1 + lengthdir_x(len1, dir1);
- var yy = y1 + lengthdir_y(len1, dir1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement