import { IClone } from "./IClone" ; import { BoundingBox } from "./BoundingBox" ; import { BoundingSphere } from "./BoundingSphere" ; import { CollisionUtil } from "./CollisionUtil" ; import { ContainmentType } from "./enums/ContainmentType" ; import { Matrix } from "./Matrix" ; import { Plane } from "./Plane" ; /**
 * A bounding frustum.
 */ export class BoundingFrustum implements IClone { /** The near plane of this frustum. */ public near : Plane ; /** The far plane of this frustum. */ public far : Plane ; /** The left plane of this frustum. */ public left : Plane ; /** The right plane of this frustum. */ public right : Plane ; /** The top plane of this frustum. */ public top : Plane ; /** The bottom plane of this frustum. */ public bottom : Plane ; param matrix constructor ( matrix = null ) { this . near = new Plane ( ) ; this . far = new Plane ( ) ; this . left = new Plane ( ) ; this . right = new Plane ( ) ; this . top = new Plane ( ) ; this . bottom = new Plane ( ) ; matrix && this . calculateFromMatrix ( matrix ) ; } returns clone ( ) { const bf = new BoundingFrustum ( ) ; this . cloneTo ( bf ) ; return bf ; } param out returns cloneTo ( out ) { this . near . cloneTo ( out . near ) ; this . far . cloneTo ( out . far ) ; this . left . cloneTo ( out . left ) ; this . right . cloneTo ( out . right ) ; this . top . cloneTo ( out . top ) ; this . bottom . cloneTo ( out . bottom ) ; return out ; } param index returns getPlane ( index ) { switch ( index ) { case 0 : return this . near ; case 1 : return this . far ; case 2 : return this . left ; case 3 : return this . right ; case 4 : return this . top ; case 5 : return this . bottom ; default : return null ; } } param matrix public calculateFromMatrix ( matrix ) { const me = matrix . elements ; const m11 = me [ 0 ] ; const m12 = me [ 1 ] ; const m13 = me [ 2 ] ; const m14 = me [ 3 ] ; const m21 = me [ 4 ] ; const m22 = me [ 5 ] ; const m23 = me [ 6 ] ; const m24 = me [ 7 ] ; const m31 = me [ 8 ] ; const m32 = me [ 9 ] ; const m33 = me [ 10 ] ; const m34 = me [ 11 ] ; const m41 = me [ 12 ] ; const m42 = me [ 13 ] ; const m43 = me [ 14 ] ; const m44 = me [ 15 ] ; const nearNormal = this . near . normal ; nearNormal . x = - m14 - m13 ; nearNormal . y = - m24 - m23 ; nearNormal . z = - m34 - m33 ; this . near . distance = - m44 - m43 ; this . near . normalize ( ) ; const farNormal = this . far . normal ; farNormal . x = m13 - m14 ; farNormal . y = m23 - m24 ; farNormal . z = m33 - m34 ; this . far . distance = m43 - m44 ; this . far . normalize ( ) ; const leftNormal = this . left . normal ; leftNormal . x = - m14 - m11 ; leftNormal . y = - m24 - m21 ; leftNormal . z = - m34 - m31 ; this . left . distance = - m44 - m41 ; this . left . normalize ( ) ; const rightNormal = this . right . normal ; rightNormal . x = m11 - m14 ; rightNormal . y = m21 - m24 ; rightNormal . z = m31 - m34 ; this . right . distance = m41 - m44 ; this . right . normalize ( ) ; const topNormal = this . top . normal ; topNormal . x = m12 - m14 ; topNormal . y = m22 - m24 ; topNormal . z = m32 - m34 ; this . top . distance = m42 - m44 ; this . top . normalize ( ) ; const bottomNormal = this . bottom . normal ; bottomNormal . x = - m14 - m12 ; bottomNormal . y = - m24 - m22 ; bottomNormal . z = - m34 - m32 ; this . bottom . distance = - m44 - m42 ; this . bottom . normalize ( ) ; } param box returns public intersectsBox ( box ) { return CollisionUtil . intersectsFrustumAndBox ( this , box ) ; } param sphere returns public intersectsSphere ( sphere ) { return CollisionUtil . frustumContainsSphere ( this , sphere ) !== ContainmentType . Disjoint ; } }