home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
sandy
/
view
/
Frustum.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
4KB
|
125 lines
class sandy.view.Frustum
{
function Frustum()
{
this.aPlanes = new Array();
}
static function get INSIDE()
{
return 1;
}
static function get OUTSIDE()
{
return -1;
}
static function get INTERSECT()
{
return 0;
}
function extractPlanes(comboMatrix, normalize)
{
this.aPlanes[0].a = comboMatrix.n14 + comboMatrix.n11;
this.aPlanes[0].b = comboMatrix.n24 + comboMatrix.n21;
this.aPlanes[0].c = comboMatrix.n34 + comboMatrix.n31;
this.aPlanes[0].d = comboMatrix.n44 + comboMatrix.n41;
this.aPlanes[1].a = comboMatrix.n14 - comboMatrix.n11;
this.aPlanes[1].b = comboMatrix.n24 - comboMatrix.n21;
this.aPlanes[1].c = comboMatrix.n34 - comboMatrix.n31;
this.aPlanes[1].d = comboMatrix.n44 - comboMatrix.n41;
this.aPlanes[2].a = comboMatrix.n14 - comboMatrix.n12;
this.aPlanes[2].b = comboMatrix.n24 - comboMatrix.n22;
this.aPlanes[2].c = comboMatrix.n34 - comboMatrix.n32;
this.aPlanes[2].d = comboMatrix.n44 - comboMatrix.n42;
this.aPlanes[3].a = comboMatrix.n14 + comboMatrix.n12;
this.aPlanes[3].b = comboMatrix.n24 + comboMatrix.n22;
this.aPlanes[3].c = comboMatrix.n34 + comboMatrix.n32;
this.aPlanes[3].d = comboMatrix.n44 + comboMatrix.n42;
this.aPlanes[4].a = comboMatrix.n13;
this.aPlanes[4].b = comboMatrix.n23;
this.aPlanes[4].c = comboMatrix.n33;
this.aPlanes[4].d = comboMatrix.n43;
this.aPlanes[5].a = comboMatrix.n14 - comboMatrix.n13;
this.aPlanes[5].b = comboMatrix.n24 - comboMatrix.n23;
this.aPlanes[5].c = comboMatrix.n34 - comboMatrix.n33;
this.aPlanes[5].d = comboMatrix.n44 - comboMatrix.n43;
if(normalize == true)
{
sandy.math.PlaneMath.normalizePlane(this.aPlanes[0]);
sandy.math.PlaneMath.normalizePlane(this.aPlanes[1]);
sandy.math.PlaneMath.normalizePlane(this.aPlanes[2]);
sandy.math.PlaneMath.normalizePlane(this.aPlanes[3]);
sandy.math.PlaneMath.normalizePlane(this.aPlanes[4]);
sandy.math.PlaneMath.normalizePlane(this.aPlanes[5]);
}
}
function pointInFrustum(p)
{
var _loc2_ = 0;
while(_loc2_ < 6)
{
if(sandy.math.PlaneMath.classifyPoint(this.aPlanes[_loc2_],p) == sandy.math.PlaneMath.__get__NEGATIVE())
{
return sandy.view.Frustum.__get__OUTSIDE();
}
_loc2_ = _loc2_ + 1;
}
return sandy.view.Frustum.__get__INSIDE();
}
function sphereInFrustum(s)
{
var _loc3_ = undefined;
var _loc4_ = s.getRadius();
var _loc5_ = s.getCenter();
var _loc2_ = 0;
while(_loc2_ < 6)
{
_loc3_ = sandy.math.PlaneMath.distanceToPoint(this.aPlanes[_loc2_],_loc5_);
if(_loc3_ < - _loc4_)
{
return sandy.view.Frustum.__get__OUTSIDE();
}
if(_loc3_ < _loc4_)
{
return sandy.view.Frustum.__get__INTERSECT();
}
_loc2_ = _loc2_ + 1;
}
return sandy.view.Frustum.__get__INSIDE();
}
function boxInFrustum(box)
{
var _loc7_ = sandy.view.Frustum.__get__INSIDE();
var _loc4_ = undefined;
var _loc3_ = undefined;
var _loc5_ = 0;
while(_loc5_ < 6)
{
_loc4_ = 0;
_loc3_ = 0;
var _loc2_ = 0;
while(_loc2_ < 8 && (_loc3_ == 0 || _loc4_ == 0))
{
if(sandy.math.PlaneMath.distanceToPoint(this.aPlanes[_loc5_],box.getVertex(_loc2_)))
{
_loc4_ = _loc4_ + 1;
}
else
{
_loc3_ = _loc3_ + 1;
}
_loc2_ = _loc2_ + 1;
}
if(!_loc3_)
{
return sandy.view.Frustum.__get__OUTSIDE();
}
if(_loc4_)
{
_loc7_ = sandy.view.Frustum.INTERSECT;
}
_loc5_ = _loc5_ + 1;
}
return _loc7_;
}
}