home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / midnightstrike1.swf / scripts / __Packages / com / neodelight / std / XMath.as < prev    next >
Encoding:
Text File  |  2007-04-02  |  1.3 KB  |  60 lines

  1. class com.neodelight.std.XMath
  2. {
  3.    function XMath()
  4.    {
  5.    }
  6.    static function p2pDistance(px, py, qx, qy)
  7.    {
  8.       return Math.sqrt(Math.pow(qx - px,2) + Math.pow(qy - py,2));
  9.    }
  10.    static function toNumber(n)
  11.    {
  12.       n = Number(n);
  13.       if(isNaN(n))
  14.       {
  15.          n = 0;
  16.       }
  17.       return n;
  18.    }
  19.    static function vAngle(dx, dy)
  20.    {
  21.       var _loc1_ = Math.asin(dx / Math.sqrt(dx * dx + dy * dy));
  22.       if(dy > 0)
  23.       {
  24.          _loc1_ = 3.141592653589793 - _loc1_;
  25.       }
  26.       return (_loc1_ + 6.283185307179586) % 6.283185307179586;
  27.    }
  28.    static function angleDiff(a0, a1)
  29.    {
  30.       var _loc2_ = 6.283185307179586;
  31.       var _loc1_ = a1 - a0;
  32.       while(_loc1_ < 0)
  33.       {
  34.          _loc1_ += _loc2_;
  35.       }
  36.       _loc1_ %= _loc2_;
  37.       if(_loc1_ > 3.141592653589793)
  38.       {
  39.          _loc1_ = (_loc2_ - _loc1_) * -1;
  40.       }
  41.       return _loc1_;
  42.    }
  43.    static function vNormalize(v)
  44.    {
  45.       var _loc2_ = Math.sqrt(v.x * v.x + v.y * v.y);
  46.       v.x /= _loc2_;
  47.       v.y /= _loc2_;
  48.       return v;
  49.    }
  50.    static function vLength(vx, vy)
  51.    {
  52.       return Math.sqrt(vx * vx + vy * vy);
  53.    }
  54.    static function rnd(min, max)
  55.    {
  56.       var _loc1_ = Math.round(Math.random() * (max - min)) + min;
  57.       return _loc1_;
  58.    }
  59. }
  60.