@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.29 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{copy as t,normalize as i,sub as e,dot as s,scaleAndAdd as r,direction as n}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as o}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as h,createPoints as u,fromMatrix as p,computePlanes as d,intersectsSphere as c,intersectsRay as a,intersectsLineSegment as g,intersectsPoint as l,planePointIndices as _}from"../../../geometry/support/frustum.js";import{Sphere as m}from"../../../geometry/support/sphere.js";class f{get planes(){return this.frustum}get points(){return this._points}get mutablePoints(){return this._points}get direction(){return this._direction}get origin(){return this._origin}get boundingSphere(){return this._boundingSphereDirty&&this._updateBoundingSphere(),this._boundingSphere}constructor(t){this.renderCoordsHelper=t,this.frustum=h(),this._points=u(),this.lines=new Array(12),this._origin=o(),this._direction=o(),this._boundingSphere=new m,this._altitude=null,this._boundingSphereDirty=!0;for(let i=0;i<12;i++)this.lines[i]={origin:null,direction:o(),endpoint:null}}update(i){p(i.viewMatrix,i.projectionMatrix,this.frustum,this._points),t(this._origin,i.eye),t(this._direction,i.viewForward),this._altitude=this.renderCoordsHelper.getAltitude(this._origin),this._updateLines(),this._boundingSphereDirty=!0}updatePoints(i){for(let e=0;e<this._points.length;e++)t(this._points[e],i[e]);d(this.frustum,this._points),this._updateLines()}get altitude(){return this._altitude}intersectsSphere(t){return c(this.frustum,t)}intersectsRay(t){return a(this.frustum,t)}intersectsLineSegment(t,i){return g(this.frustum,t,i)}intersectsPoint(t){return l(this.frustum,t)}_updateLines(){const t=this._points;for(let i=0;i<4;i++){const e=i+4;S(this.lines[i],t[i],t[e]),S(this.lines[i+4],t[i],3===i?t[0]:t[i+1]),S(this.lines[i+8],t[e],3===i?t[4]:t[e+1])}}_updateBoundingSphere(){const{origin:t}=this,n=y;i(n,this.direction);const o=b;e(o,this.points[4],t);const h=.5*s(o,o)/s(n,o),u=this._boundingSphere,p=r(j,t,n,h);u.center=p,u.radius=h}static{this.planePointIndices=_}static{this.nearFarLineIndices=[[0,4],[1,5],[2,6],[3,7]]}}function S(t,i,e){t.origin=i,t.endpoint=e,n(t.direction,i,e)}const b=o(),y=o(),j=o();export{f as Frustum};