Ticket #1193: 1193.diff
File 1193.diff, 2.6 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/maps/random/rmgen/library.js
51 51 return Math.sin(x); 52 52 } 53 53 54 function tan(x)55 {56 return Math.tan(x);57 }58 59 54 function abs(x) { 60 55 return Math.abs(x); 61 56 } … … 596 591 } 597 592 598 593 599 // Function to getthe distance between 2 points594 // Returns the distance between 2 points 600 595 function getDistance(x1, z1, x2, z2) 601 596 { 602 return Math.pow(Math.pow(x1 - x2, 2) + Math.pow(z1 - z2, 2), 1/2) 597 return Math.pow(Math.pow(x1 - x2, 2) + Math.pow(z1 - z2, 2), 1/2); 603 598 } 604 599 605 // Returns the a bgle between two points in radians. --Warning:This can cause sync problems in cross-platform multiplayer games--600 // Returns the angle of the vector between point 1 and point 2. The angle 606 601 function getAngle(x1, z1, x2, z2) 607 602 { 608 var vector = [x2 - x1, z2 - z1]; 609 var output = 0; 610 if (vector[0] !== 0 || vector[1] !== 0) 611 { 612 var output = Math.acos(vector[0]/getDistance(x1, z1, x2, z2)); 613 if (vector[1] > 0) {output = PI + (PI - Math.acos(vector[0]/getDistance(x1, z1, x2, z2)))}; 614 }; 615 return (output + PI/2) % (2*PI); 616 }; 603 return output = Math.atan2(z2 - z1, x2 - x1); 604 } 617 605 618 // Returns the tangent of angle between the line that is created by two points and the X+ axis.619 function get Direction(x1, z1, x2, z2)606 // Returns the gradient of the line between point 1 and 2 in the form dz/dx 607 function getGradient(x1, z1, x2, z2) 620 608 { 621 609 if (x1 == x2) 622 610 { 623 return 100000;611 return Infinity; 624 612 } 625 613 else 626 614 { -
binaries/data/mods/public/globalscripts/Math.js
38 38 sign = -1; 39 39 a *= -1; 40 40 } 41 if (a > 1){ 41 42 if (a > 1) 43 { 42 44 // tan(pi/2 - x) = 1/tan(x) 43 45 inverted = true; 44 46 a = 1/a; 45 47 } 46 if (a > tanPiBy12){ 48 49 if (a > tanPiBy12) 50 { 47 51 // tan(x-pi/6) = (tan(x) - tan(pi/6)) / (1 + tan(pi/6)tan(x)) 48 52 tanPiBy6Shift = Math.PI/6; 49 53 a = (a - tanPiBy6) / (1 + tanPiBy6*a); … … 113 117 return r; 114 118 } 115 119 }; 120 121 Math.acos = function() 122 { 123 error("Math.acos() does not have a synchronization safe implementation"); 124 }; 125 126 Math.asin = function() 127 { 128 error("Math.asin() does not have a synchronization safe implementation"); 129 }; 130 131 Math.tan = function() 132 { 133 error("Math.tan() does not have a synchronization safe implementation"); 134 };