import { mat4 , vec3 } from 'gl-matrix' ; import { AABB } from './AABB' ; import { Plane } from './Plane' ; export enum Mask { OUTSIDE = 0xffffffff , INSIDE = 0x00000000 , INDETERMINATE = 0x7fffffff } export class Frustum { public planes : Plane [ ] = [ ] ; constructor ( planes ? ) { if ( planes ) { this . planes = planes ; } else { for ( let i = 0 ; i < 6 ; i ++ ) { this . planes . push ( new Plane ( ) ) ; } } } see http param vpMatrix public extractFromVPMatrix ( vpMatrix ) { const [ m0 , m1 , m2 , m3 , m4 , m5 , m6 , m7 , m8 , m9 , m10 , m11 , m12 , m13 , m14 , m15 , ] = vpMatrix ; vec3 . set ( this . planes [ 0 ] . normal , m3 - m0 , m7 - m4 , m11 - m8 ) ; this . planes [ 0 ] . distance = - ( m15 - m12 ) ; vec3 . set ( this . planes [ 1 ] . normal , m3 + m0 , m7 + m4 , m11 + m8 ) ; this . planes [ 1 ] . distance = - ( m15 + m12 ) ; vec3 . set ( this . planes [ 2 ] . normal , m3 + m1 , m7 + m5 , m11 + m9 ) ; this . planes [ 2 ] . distance = - ( m15 + m13 ) ; vec3 . set ( this . planes [ 3 ] . normal , m3 - m1 , m7 - m5 , m11 - m9 ) ; this . planes [ 3 ] . distance = - ( m15 - m13 ) ; vec3 . set ( this . planes [ 4 ] . normal , m3 - m2 , m7 - m6 , m11 - m10 ) ; this . planes [ 4 ] . distance = - ( m15 - m14 ) ; vec3 . set ( this . planes [ 5 ] . normal , m3 + m2 , m7 + m6 , m11 + m10 ) ; this . planes [ 5 ] . distance = - ( m15 + m14 ) ; this . planes . forEach ( ( plane ) => { plane . normalize ( ) ; plane . updatePNVertexFlag ( ) ; } ) ; } }