Ticket #1193: 1193.diff

File 1193.diff, 2.6 KB (added by Jonathan Waller, 12 years ago)

These changes should fix the ticket, will wait till after A9 to commit them

  • binaries/data/mods/public/maps/random/rmgen/library.js

     
    5151    return Math.sin(x);
    5252}
    5353
    54 function tan(x)
    55 {
    56     return Math.tan(x);
    57 }
    58 
    5954function abs(x) {
    6055    return Math.abs(x);
    6156}
     
    596591}
    597592
    598593
    599 // Function to get the distance between 2 points
     594// Returns the distance between 2 points
    600595function getDistance(x1, z1, x2, z2)
    601596{
    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);
    603598}
    604599
    605 // Returns the abgle 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
    606601function getAngle(x1, z1, x2, z2)
    607602{
    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}
    617605
    618 // Returns the tangent of angle between the line that is created by two points and the X+ axis.
    619 function getDirection(x1, z1, x2, z2)
     606// Returns the gradient of the line between point 1 and 2 in the form dz/dx
     607function getGradient(x1, z1, x2, z2)
    620608{
    621609    if (x1 == x2)
    622610    {
    623         return 100000;
     611        return Infinity;
    624612    }
    625613    else
    626614    {
  • binaries/data/mods/public/globalscripts/Math.js

     
    3838        sign = -1;
    3939        a *= -1;
    4040    }
    41     if (a > 1){
     41   
     42    if (a > 1)
     43    {
    4244        // tan(pi/2 - x) = 1/tan(x)
    4345        inverted = true;
    4446        a = 1/a;
    4547    }
    46     if (a > tanPiBy12){
     48   
     49    if (a > tanPiBy12)
     50    {
    4751        // tan(x-pi/6) = (tan(x) - tan(pi/6)) / (1 + tan(pi/6)tan(x))
    4852        tanPiBy6Shift = Math.PI/6;
    4953        a = (a - tanPiBy6) / (1 + tanPiBy6*a);
     
    113117            return r;
    114118    }
    115119};
     120
     121Math.acos = function()
     122{
     123    error("Math.acos() does not have a synchronization safe implementation");
     124};
     125
     126Math.asin = function()
     127{
     128    error("Math.asin() does not have a synchronization safe implementation");
     129};
     130
     131Math.tan = function()
     132{
     133    error("Math.tan() does not have a synchronization safe implementation");
     134};