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

  1. class CTransform
  2. {
  3.    var nearWidth;
  4.    var nearHeight;
  5.    var depth;
  6.    var k;
  7.    var nearDX;
  8.    var nearDY;
  9.    var nearCX = 275;
  10.    var nearCY = 200;
  11.    function CTransform(nearCX_, nearCY_)
  12.    {
  13.       this.nearCX = nearCX_;
  14.       this.nearCY = nearCY_;
  15.    }
  16.    function init(nearWidth_, nearHeight_, depth_, k_)
  17.    {
  18.       this.nearWidth = nearWidth_;
  19.       this.nearHeight = nearHeight_;
  20.       this.depth = depth_;
  21.       this.k = k_;
  22.       this.nearDX = this.nearDY = 0;
  23.    }
  24.    function getScreenXY(x, y, z, point)
  25.    {
  26.       var _loc2_ = this.getKForZ(z);
  27.       x = (x + this.nearDX) * _loc2_ + this.nearCX;
  28.       y = (y + this.nearDY) * _loc2_ + this.nearCY;
  29.       point.k = _loc2_ / (1 + 3 * z / this.depth);
  30.       point.x = x;
  31.       point.y = y;
  32.    }
  33.    function getKForZ(z)
  34.    {
  35.       return 1 - (1 - this.k) * z / this.depth;
  36.    }
  37.    function getWorldXFromScreen(x, k)
  38.    {
  39.       return (x - this.nearCX) / k - this.nearDX;
  40.    }
  41.    function getWorldYFromScreen(y, k)
  42.    {
  43.       return (y - this.nearCY) / k - this.nearDY;
  44.    }
  45. }
  46.