home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / naval.swf / scripts / __Packages / CVector2D.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  2.3 KB  |  106 lines

  1. class CVector2D
  2. {
  3.    var x;
  4.    var y;
  5.    function CVector2D(x_, y_)
  6.    {
  7.       this.x = x_;
  8.       this.y = y_;
  9.    }
  10.    function reinit(x_, y_)
  11.    {
  12.       this.x = x_;
  13.       this.y = y_;
  14.    }
  15.    function getUgol()
  16.    {
  17.       return Math.atan2(this.y,this.x);
  18.    }
  19.    function duplicate()
  20.    {
  21.       return new CVector2D(this.x,this.y);
  22.    }
  23.    function copyTo(v)
  24.    {
  25.       v.x = this.x;
  26.       v.y = this.y;
  27.    }
  28.    function minus(v)
  29.    {
  30.       this.x -= v.x;
  31.       this.y -= v.y;
  32.    }
  33.    function minusNew(v)
  34.    {
  35.       return new CVector2D(this.x - v.x,this.y - v.y);
  36.    }
  37.    function normalize()
  38.    {
  39.       var _loc2_ = Math.sqrt(this.x * this.x + this.y * this.y);
  40.       if(_loc2_ > 0.001)
  41.       {
  42.          this.x /= _loc2_;
  43.          this.y /= _loc2_;
  44.       }
  45.    }
  46.    function reverseNew()
  47.    {
  48.       return new CVector2D(- this.x,- this.y);
  49.    }
  50.    function scalar(v)
  51.    {
  52.       return this.x * v.x + this.y * v.y;
  53.    }
  54.    function modul()
  55.    {
  56.       return Math.sqrt(this.x * this.x + this.y * this.y);
  57.    }
  58.    function reflectFromNormal(n)
  59.    {
  60.       var _loc2_ = Math.atan2(n.y,n.x);
  61.       this.rotate(- _loc2_);
  62.       this.x = - this.x;
  63.       this.rotate(_loc2_);
  64.    }
  65.    function rotate(u)
  66.    {
  67.       var _loc4_ = this.x;
  68.       var _loc3_ = this.y;
  69.       this.x = _loc4_ * Math.cos(u) - _loc3_ * Math.sin(u);
  70.       this.y = _loc4_ * Math.sin(u) + _loc3_ * Math.cos(u);
  71.    }
  72.    function rotateNew(u)
  73.    {
  74.       return new CVector2D(this.x * Math.cos(u) - this.y * Math.sin(u),this.x * Math.sin(u) + this.y * Math.cos(u));
  75.    }
  76.    function mult(k)
  77.    {
  78.       this.x *= k;
  79.       this.y *= k;
  80.    }
  81.    function multNew(k)
  82.    {
  83.       return new CVector2D(this.x * k,this.y * k);
  84.    }
  85.    function plus(v)
  86.    {
  87.       this.x += v.x;
  88.       this.y += v.y;
  89.    }
  90.    function plusNew(v)
  91.    {
  92.       return new CVector2D(this.x + v.x,this.y + v.y);
  93.    }
  94.    function getDistanceTo(p1, p2)
  95.    {
  96.       var _loc3_ = p1.y - p2.y;
  97.       var _loc2_ = p2.x - p1.x;
  98.       var _loc6_ = p1.x * (p2.y - p1.y) - p1.y * (p2.x - p1.x);
  99.       var _loc5_ = Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
  100.       _loc3_ /= _loc5_;
  101.       _loc2_ /= _loc5_;
  102.       _loc6_ /= _loc5_;
  103.       return _loc3_ * this.x + _loc2_ * this.y + _loc6_;
  104.    }
  105. }
  106.