home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Esportes / CrossingCup.swf / scripts / __Packages / sandy / view / Frustum.as < prev    next >
Text File  |  2007-12-11  |  4KB  |  125 lines

  1. class sandy.view.Frustum
  2. {
  3.    function Frustum()
  4.    {
  5.       this.aPlanes = new Array();
  6.    }
  7.    static function get INSIDE()
  8.    {
  9.       return 1;
  10.    }
  11.    static function get OUTSIDE()
  12.    {
  13.       return -1;
  14.    }
  15.    static function get INTERSECT()
  16.    {
  17.       return 0;
  18.    }
  19.    function extractPlanes(comboMatrix, normalize)
  20.    {
  21.       this.aPlanes[0].a = comboMatrix.n14 + comboMatrix.n11;
  22.       this.aPlanes[0].b = comboMatrix.n24 + comboMatrix.n21;
  23.       this.aPlanes[0].c = comboMatrix.n34 + comboMatrix.n31;
  24.       this.aPlanes[0].d = comboMatrix.n44 + comboMatrix.n41;
  25.       this.aPlanes[1].a = comboMatrix.n14 - comboMatrix.n11;
  26.       this.aPlanes[1].b = comboMatrix.n24 - comboMatrix.n21;
  27.       this.aPlanes[1].c = comboMatrix.n34 - comboMatrix.n31;
  28.       this.aPlanes[1].d = comboMatrix.n44 - comboMatrix.n41;
  29.       this.aPlanes[2].a = comboMatrix.n14 - comboMatrix.n12;
  30.       this.aPlanes[2].b = comboMatrix.n24 - comboMatrix.n22;
  31.       this.aPlanes[2].c = comboMatrix.n34 - comboMatrix.n32;
  32.       this.aPlanes[2].d = comboMatrix.n44 - comboMatrix.n42;
  33.       this.aPlanes[3].a = comboMatrix.n14 + comboMatrix.n12;
  34.       this.aPlanes[3].b = comboMatrix.n24 + comboMatrix.n22;
  35.       this.aPlanes[3].c = comboMatrix.n34 + comboMatrix.n32;
  36.       this.aPlanes[3].d = comboMatrix.n44 + comboMatrix.n42;
  37.       this.aPlanes[4].a = comboMatrix.n13;
  38.       this.aPlanes[4].b = comboMatrix.n23;
  39.       this.aPlanes[4].c = comboMatrix.n33;
  40.       this.aPlanes[4].d = comboMatrix.n43;
  41.       this.aPlanes[5].a = comboMatrix.n14 - comboMatrix.n13;
  42.       this.aPlanes[5].b = comboMatrix.n24 - comboMatrix.n23;
  43.       this.aPlanes[5].c = comboMatrix.n34 - comboMatrix.n33;
  44.       this.aPlanes[5].d = comboMatrix.n44 - comboMatrix.n43;
  45.       if(normalize == true)
  46.       {
  47.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[0]);
  48.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[1]);
  49.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[2]);
  50.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[3]);
  51.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[4]);
  52.          sandy.math.PlaneMath.normalizePlane(this.aPlanes[5]);
  53.       }
  54.    }
  55.    function pointInFrustum(p)
  56.    {
  57.       var _loc2_ = 0;
  58.       while(_loc2_ < 6)
  59.       {
  60.          if(sandy.math.PlaneMath.classifyPoint(this.aPlanes[_loc2_],p) == sandy.math.PlaneMath.__get__NEGATIVE())
  61.          {
  62.             return sandy.view.Frustum.__get__OUTSIDE();
  63.          }
  64.          _loc2_ = _loc2_ + 1;
  65.       }
  66.       return sandy.view.Frustum.__get__INSIDE();
  67.    }
  68.    function sphereInFrustum(s)
  69.    {
  70.       var _loc3_ = undefined;
  71.       var _loc4_ = s.getRadius();
  72.       var _loc5_ = s.getCenter();
  73.       var _loc2_ = 0;
  74.       while(_loc2_ < 6)
  75.       {
  76.          _loc3_ = sandy.math.PlaneMath.distanceToPoint(this.aPlanes[_loc2_],_loc5_);
  77.          if(_loc3_ < - _loc4_)
  78.          {
  79.             return sandy.view.Frustum.__get__OUTSIDE();
  80.          }
  81.          if(_loc3_ < _loc4_)
  82.          {
  83.             return sandy.view.Frustum.__get__INTERSECT();
  84.          }
  85.          _loc2_ = _loc2_ + 1;
  86.       }
  87.       return sandy.view.Frustum.__get__INSIDE();
  88.    }
  89.    function boxInFrustum(box)
  90.    {
  91.       var _loc7_ = sandy.view.Frustum.__get__INSIDE();
  92.       var _loc4_ = undefined;
  93.       var _loc3_ = undefined;
  94.       var _loc5_ = 0;
  95.       while(_loc5_ < 6)
  96.       {
  97.          _loc4_ = 0;
  98.          _loc3_ = 0;
  99.          var _loc2_ = 0;
  100.          while(_loc2_ < 8 && (_loc3_ == 0 || _loc4_ == 0))
  101.          {
  102.             if(sandy.math.PlaneMath.distanceToPoint(this.aPlanes[_loc5_],box.getVertex(_loc2_)))
  103.             {
  104.                _loc4_ = _loc4_ + 1;
  105.             }
  106.             else
  107.             {
  108.                _loc3_ = _loc3_ + 1;
  109.             }
  110.             _loc2_ = _loc2_ + 1;
  111.          }
  112.          if(!_loc3_)
  113.          {
  114.             return sandy.view.Frustum.__get__OUTSIDE();
  115.          }
  116.          if(_loc4_)
  117.          {
  118.             _loc7_ = sandy.view.Frustum.INTERSECT;
  119.          }
  120.          _loc5_ = _loc5_ + 1;
  121.       }
  122.       return _loc7_;
  123.    }
  124. }
  125.