123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166 |
- /* This file is automatically rebuilt by the Cesium build process. */
- define(['exports', './defined-26bd4a03', './Check-da037458', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './GeometryAttributes-eecc9f43', './Plane-a1a3fd52', './VertexFormat-fbb91dc7'], function (exports, defined, Check, defaultValue, _Math, Cartesian2, defineProperties, Transforms, ComponentDatatype, GeometryAttribute, GeometryAttributes, Plane, VertexFormat) { 'use strict';
- /**
- * The culling volume defined by planes.
- *
- * @alias CullingVolume
- * @constructor
- *
- * @param {Cartesian4[]} [planes] An array of clipping planes.
- */
- function CullingVolume(planes) {
- /**
- * Each plane is represented by a Cartesian4 object, where the x, y, and z components
- * define the unit vector normal to the plane, and the w component is the distance of the
- * plane from the origin.
- * @type {Cartesian4[]}
- * @default []
- */
- this.planes = defaultValue.defaultValue(planes, []);
- }
- var faces = [new Cartesian2.Cartesian3(), new Cartesian2.Cartesian3(), new Cartesian2.Cartesian3()];
- Cartesian2.Cartesian3.clone(Cartesian2.Cartesian3.UNIT_X, faces[0]);
- Cartesian2.Cartesian3.clone(Cartesian2.Cartesian3.UNIT_Y, faces[1]);
- Cartesian2.Cartesian3.clone(Cartesian2.Cartesian3.UNIT_Z, faces[2]);
- var scratchPlaneCenter = new Cartesian2.Cartesian3();
- var scratchPlaneNormal = new Cartesian2.Cartesian3();
- var scratchPlane = new Plane.Plane(new Cartesian2.Cartesian3(1.0, 0.0, 0.0), 0.0);
- /**
- * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
- * The planes are aligned to the x, y, and z axes in world coordinates.
- *
- * @param {BoundingSphere} boundingSphere The bounding sphere used to create the culling volume.
- * @param {CullingVolume} [result] The object onto which to store the result.
- * @returns {CullingVolume} The culling volume created from the bounding sphere.
- */
- CullingVolume.fromBoundingSphere = function(boundingSphere, result) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(boundingSphere)) {
- throw new Check.DeveloperError('boundingSphere is required.');
- }
- //>>includeEnd('debug');
- if (!defined.defined(result)) {
- result = new CullingVolume();
- }
- var length = faces.length;
- var planes = result.planes;
- planes.length = 2 * length;
- var center = boundingSphere.center;
- var radius = boundingSphere.radius;
- var planeIndex = 0;
- for (var i = 0; i < length; ++i) {
- var faceNormal = faces[i];
- var plane0 = planes[planeIndex];
- var plane1 = planes[planeIndex + 1];
- if (!defined.defined(plane0)) {
- plane0 = planes[planeIndex] = new Transforms.Cartesian4();
- }
- if (!defined.defined(plane1)) {
- plane1 = planes[planeIndex + 1] = new Transforms.Cartesian4();
- }
- Cartesian2.Cartesian3.multiplyByScalar(faceNormal, -radius, scratchPlaneCenter);
- Cartesian2.Cartesian3.add(center, scratchPlaneCenter, scratchPlaneCenter);
- plane0.x = faceNormal.x;
- plane0.y = faceNormal.y;
- plane0.z = faceNormal.z;
- plane0.w = -Cartesian2.Cartesian3.dot(faceNormal, scratchPlaneCenter);
- Cartesian2.Cartesian3.multiplyByScalar(faceNormal, radius, scratchPlaneCenter);
- Cartesian2.Cartesian3.add(center, scratchPlaneCenter, scratchPlaneCenter);
- plane1.x = -faceNormal.x;
- plane1.y = -faceNormal.y;
- plane1.z = -faceNormal.z;
- plane1.w = -Cartesian2.Cartesian3.dot(Cartesian2.Cartesian3.negate(faceNormal, scratchPlaneNormal), scratchPlaneCenter);
- planeIndex += 2;
- }
- return result;
- };
- /**
- * Determines whether a bounding volume intersects the culling volume.
- *
- * @param {Object} boundingVolume The bounding volume whose intersection with the culling volume is to be tested.
- * @returns {Intersect} Intersect.OUTSIDE, Intersect.INTERSECTING, or Intersect.INSIDE.
- */
- CullingVolume.prototype.computeVisibility = function(boundingVolume) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(boundingVolume)) {
- throw new Check.DeveloperError('boundingVolume is required.');
- }
- //>>includeEnd('debug');
- var planes = this.planes;
- var intersecting = false;
- for (var k = 0, len = planes.length; k < len; ++k) {
- var result = boundingVolume.intersectPlane(Plane.Plane.fromCartesian4(planes[k], scratchPlane));
- if (result === Transforms.Intersect.OUTSIDE) {
- return Transforms.Intersect.OUTSIDE;
- } else if (result === Transforms.Intersect.INTERSECTING) {
- intersecting = true;
- }
- }
- return intersecting ? Transforms.Intersect.INTERSECTING : Transforms.Intersect.INSIDE;
- };
- /**
- * Determines whether a bounding volume intersects the culling volume.
- *
- * @param {Object} boundingVolume The bounding volume whose intersection with the culling volume is to be tested.
- * @param {Number} parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
- * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
- * the parent (and therefore this) volume is completely inside plane[planeIndex]
- * and that plane check can be skipped.
- * @returns {Number} A plane mask as described above (which can be applied to this boundingVolume's children).
- *
- * @private
- */
- CullingVolume.prototype.computeVisibilityWithPlaneMask = function(boundingVolume, parentPlaneMask) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(boundingVolume)) {
- throw new Check.DeveloperError('boundingVolume is required.');
- }
- if (!defined.defined(parentPlaneMask)) {
- throw new Check.DeveloperError('parentPlaneMask is required.');
- }
- //>>includeEnd('debug');
- if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
- // parent is completely outside or completely inside, so this child is as well.
- return parentPlaneMask;
- }
- // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.
- // (Because if there are fewer than 31 planes, the upper bits wont be changed.)
- var mask = CullingVolume.MASK_INSIDE;
- var planes = this.planes;
- for (var k = 0, len = planes.length; k < len; ++k) {
- // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
- var flag = (k < 31) ? (1 << k) : 0;
- if (k < 31 && (parentPlaneMask & flag) === 0) {
- // boundingVolume is known to be INSIDE this plane.
- continue;
- }
- var result = boundingVolume.intersectPlane(Plane.Plane.fromCartesian4(planes[k], scratchPlane));
- if (result === Transforms.Intersect.OUTSIDE) {
- return CullingVolume.MASK_OUTSIDE;
- } else if (result === Transforms.Intersect.INTERSECTING) {
- mask |= flag;
- }
- }
- return mask;
- };
- /**
- * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
- * represents the case where the object bounding volume is entirely outside the culling volume.
- *
- * @type {Number}
- * @private
- */
- CullingVolume.MASK_OUTSIDE = 0xffffffff;
- /**
- * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
- * represents the case where the object bounding volume is entirely inside the culling volume.
- *
- * @type {Number}
- * @private
- */
- CullingVolume.MASK_INSIDE = 0x00000000;
- /**
- * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
- * represents the case where the object bounding volume (may) intersect all planes of the culling volume.
- *
- * @type {Number}
- * @private
- */
- CullingVolume.MASK_INDETERMINATE = 0x7fffffff;
- /**
- * The viewing frustum is defined by 6 planes.
- * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components
- * define the unit vector normal to the plane, and the w component is the distance of the
- * plane from the origin/camera position.
- *
- * @alias OrthographicOffCenterFrustum
- * @constructor
- *
- * @param {Object} [options] An object with the following properties:
- * @param {Number} [options.left] The left clipping plane distance.
- * @param {Number} [options.right] The right clipping plane distance.
- * @param {Number} [options.top] The top clipping plane distance.
- * @param {Number} [options.bottom] The bottom clipping plane distance.
- * @param {Number} [options.near=1.0] The near clipping plane distance.
- * @param {Number} [options.far=500000000.0] The far clipping plane distance.
- *
- * @example
- * var maxRadii = ellipsoid.maximumRadius;
- *
- * var frustum = new Cesium.OrthographicOffCenterFrustum();
- * frustum.right = maxRadii * Cesium.Math.PI;
- * frustum.left = -c.frustum.right;
- * frustum.top = c.frustum.right * (canvas.clientHeight / canvas.clientWidth);
- * frustum.bottom = -c.frustum.top;
- * frustum.near = 0.01 * maxRadii;
- * frustum.far = 50.0 * maxRadii;
- */
- function OrthographicOffCenterFrustum(options) {
- options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
- /**
- * The left clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.left = options.left;
- this._left = undefined;
- /**
- * The right clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.right = options.right;
- this._right = undefined;
- /**
- * The top clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.top = options.top;
- this._top = undefined;
- /**
- * The bottom clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.bottom = options.bottom;
- this._bottom = undefined;
- /**
- * The distance of the near plane.
- * @type {Number}
- * @default 1.0
- */
- this.near = defaultValue.defaultValue(options.near, 1.0);
- this._near = this.near;
- /**
- * The distance of the far plane.
- * @type {Number}
- * @default 500000000.0;
- */
- this.far = defaultValue.defaultValue(options.far, 500000000.0);
- this._far = this.far;
- this._cullingVolume = new CullingVolume();
- this._orthographicMatrix = new Transforms.Matrix4();
- }
- function update(frustum) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(frustum.right) || !defined.defined(frustum.left) ||
- !defined.defined(frustum.top) || !defined.defined(frustum.bottom) ||
- !defined.defined(frustum.near) || !defined.defined(frustum.far)) {
- throw new Check.DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
- }
- //>>includeEnd('debug');
- if (frustum.top !== frustum._top || frustum.bottom !== frustum._bottom ||
- frustum.left !== frustum._left || frustum.right !== frustum._right ||
- frustum.near !== frustum._near || frustum.far !== frustum._far) {
- //>>includeStart('debug', pragmas.debug);
- if (frustum.left > frustum.right) {
- throw new Check.DeveloperError('right must be greater than left.');
- }
- if (frustum.bottom > frustum.top) {
- throw new Check.DeveloperError('top must be greater than bottom.');
- }
- if (frustum.near <= 0 || frustum.near > frustum.far) {
- throw new Check.DeveloperError('near must be greater than zero and less than far.');
- }
- //>>includeEnd('debug');
- frustum._left = frustum.left;
- frustum._right = frustum.right;
- frustum._top = frustum.top;
- frustum._bottom = frustum.bottom;
- frustum._near = frustum.near;
- frustum._far = frustum.far;
- frustum._orthographicMatrix = Transforms.Matrix4.computeOrthographicOffCenter(frustum.left, frustum.right, frustum.bottom, frustum.top, frustum.near, frustum.far, frustum._orthographicMatrix);
- }
- }
- defineProperties.defineProperties(OrthographicOffCenterFrustum.prototype, {
- /**
- * Gets the orthographic projection matrix computed from the view frustum.
- * @memberof OrthographicOffCenterFrustum.prototype
- * @type {Matrix4}
- * @readonly
- */
- projectionMatrix : {
- get : function() {
- update(this);
- return this._orthographicMatrix;
- }
- }
- });
- var getPlanesRight = new Cartesian2.Cartesian3();
- var getPlanesNearCenter = new Cartesian2.Cartesian3();
- var getPlanesPoint = new Cartesian2.Cartesian3();
- var negateScratch = new Cartesian2.Cartesian3();
- /**
- * Creates a culling volume for this frustum.
- *
- * @param {Cartesian3} position The eye position.
- * @param {Cartesian3} direction The view direction.
- * @param {Cartesian3} up The up direction.
- * @returns {CullingVolume} A culling volume at the given position and orientation.
- *
- * @example
- * // Check if a bounding volume intersects the frustum.
- * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
- * var intersect = cullingVolume.computeVisibility(boundingVolume);
- */
- OrthographicOffCenterFrustum.prototype.computeCullingVolume = function(position, direction, up) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(position)) {
- throw new Check.DeveloperError('position is required.');
- }
- if (!defined.defined(direction)) {
- throw new Check.DeveloperError('direction is required.');
- }
- if (!defined.defined(up)) {
- throw new Check.DeveloperError('up is required.');
- }
- //>>includeEnd('debug');
- var planes = this._cullingVolume.planes;
- var t = this.top;
- var b = this.bottom;
- var r = this.right;
- var l = this.left;
- var n = this.near;
- var f = this.far;
- var right = Cartesian2.Cartesian3.cross(direction, up, getPlanesRight);
- Cartesian2.Cartesian3.normalize(right, right);
- var nearCenter = getPlanesNearCenter;
- Cartesian2.Cartesian3.multiplyByScalar(direction, n, nearCenter);
- Cartesian2.Cartesian3.add(position, nearCenter, nearCenter);
- var point = getPlanesPoint;
- // Left plane
- Cartesian2.Cartesian3.multiplyByScalar(right, l, point);
- Cartesian2.Cartesian3.add(nearCenter, point, point);
- var plane = planes[0];
- if (!defined.defined(plane)) {
- plane = planes[0] = new Transforms.Cartesian4();
- }
- plane.x = right.x;
- plane.y = right.y;
- plane.z = right.z;
- plane.w = -Cartesian2.Cartesian3.dot(right, point);
- // Right plane
- Cartesian2.Cartesian3.multiplyByScalar(right, r, point);
- Cartesian2.Cartesian3.add(nearCenter, point, point);
- plane = planes[1];
- if (!defined.defined(plane)) {
- plane = planes[1] = new Transforms.Cartesian4();
- }
- plane.x = -right.x;
- plane.y = -right.y;
- plane.z = -right.z;
- plane.w = -Cartesian2.Cartesian3.dot(Cartesian2.Cartesian3.negate(right, negateScratch), point);
- // Bottom plane
- Cartesian2.Cartesian3.multiplyByScalar(up, b, point);
- Cartesian2.Cartesian3.add(nearCenter, point, point);
- plane = planes[2];
- if (!defined.defined(plane)) {
- plane = planes[2] = new Transforms.Cartesian4();
- }
- plane.x = up.x;
- plane.y = up.y;
- plane.z = up.z;
- plane.w = -Cartesian2.Cartesian3.dot(up, point);
- // Top plane
- Cartesian2.Cartesian3.multiplyByScalar(up, t, point);
- Cartesian2.Cartesian3.add(nearCenter, point, point);
- plane = planes[3];
- if (!defined.defined(plane)) {
- plane = planes[3] = new Transforms.Cartesian4();
- }
- plane.x = -up.x;
- plane.y = -up.y;
- plane.z = -up.z;
- plane.w = -Cartesian2.Cartesian3.dot(Cartesian2.Cartesian3.negate(up, negateScratch), point);
- // Near plane
- plane = planes[4];
- if (!defined.defined(plane)) {
- plane = planes[4] = new Transforms.Cartesian4();
- }
- plane.x = direction.x;
- plane.y = direction.y;
- plane.z = direction.z;
- plane.w = -Cartesian2.Cartesian3.dot(direction, nearCenter);
- // Far plane
- Cartesian2.Cartesian3.multiplyByScalar(direction, f, point);
- Cartesian2.Cartesian3.add(position, point, point);
- plane = planes[5];
- if (!defined.defined(plane)) {
- plane = planes[5] = new Transforms.Cartesian4();
- }
- plane.x = -direction.x;
- plane.y = -direction.y;
- plane.z = -direction.z;
- plane.w = -Cartesian2.Cartesian3.dot(Cartesian2.Cartesian3.negate(direction, negateScratch), point);
- return this._cullingVolume;
- };
- /**
- * Returns the pixel's width and height in meters.
- *
- * @param {Number} drawingBufferWidth The width of the drawing buffer.
- * @param {Number} drawingBufferHeight The height of the drawing buffer.
- * @param {Number} distance The distance to the near plane in meters.
- * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space.
- * @param {Cartesian2} result The object onto which to store the result.
- * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.
- *
- * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
- * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
- * @exception {DeveloperError} pixelRatio must be greater than zero.
- *
- * @example
- * // Example 1
- * // Get the width and height of a pixel.
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2());
- */
- OrthographicOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) {
- update(this);
- if (pixelRatio instanceof Cartesian2.Cartesian2) {
- result = pixelRatio;
- pixelRatio = 1.0;
- Transforms.deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.');
- }
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(drawingBufferWidth) || !defined.defined(drawingBufferHeight)) {
- throw new Check.DeveloperError('Both drawingBufferWidth and drawingBufferHeight are required.');
- }
- if (drawingBufferWidth <= 0) {
- throw new Check.DeveloperError('drawingBufferWidth must be greater than zero.');
- }
- if (drawingBufferHeight <= 0) {
- throw new Check.DeveloperError('drawingBufferHeight must be greater than zero.');
- }
- if (!defined.defined(distance)) {
- throw new Check.DeveloperError('distance is required.');
- }
- if (!defined.defined(pixelRatio)) {
- throw new Check.DeveloperError('pixelRatio is required.');
- }
- if (pixelRatio <= 0) {
- throw new Check.DeveloperError('pixelRatio must be greater than zero.');
- }
- if (!defined.defined(result)) {
- throw new Check.DeveloperError('A result object is required.');
- }
- //>>includeEnd('debug');
- var frustumWidth = this.right - this.left;
- var frustumHeight = this.top - this.bottom;
- var pixelWidth = pixelRatio * frustumWidth / drawingBufferWidth;
- var pixelHeight = pixelRatio * frustumHeight / drawingBufferHeight;
- result.x = pixelWidth;
- result.y = pixelHeight;
- return result;
- };
- /**
- * Returns a duplicate of a OrthographicOffCenterFrustum instance.
- *
- * @param {OrthographicOffCenterFrustum} [result] The object onto which to store the result.
- * @returns {OrthographicOffCenterFrustum} The modified result parameter or a new OrthographicOffCenterFrustum instance if one was not provided.
- */
- OrthographicOffCenterFrustum.prototype.clone = function(result) {
- if (!defined.defined(result)) {
- result = new OrthographicOffCenterFrustum();
- }
- result.left = this.left;
- result.right = this.right;
- result.top = this.top;
- result.bottom = this.bottom;
- result.near = this.near;
- result.far = this.far;
- // force update of clone to compute matrices
- result._left = undefined;
- result._right = undefined;
- result._top = undefined;
- result._bottom = undefined;
- result._near = undefined;
- result._far = undefined;
- return result;
- };
- /**
- * Compares the provided OrthographicOffCenterFrustum componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {OrthographicOffCenterFrustum} [other] The right hand side OrthographicOffCenterFrustum.
- * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- OrthographicOffCenterFrustum.prototype.equals = function(other) {
- return (defined.defined(other) && other instanceof OrthographicOffCenterFrustum &&
- this.right === other.right &&
- this.left === other.left &&
- this.top === other.top &&
- this.bottom === other.bottom &&
- this.near === other.near &&
- this.far === other.far);
- };
- /**
- * Compares the provided OrthographicOffCenterFrustum componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {OrthographicOffCenterFrustum} other The right hand side OrthographicOffCenterFrustum.
- * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
- * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
- */
- OrthographicOffCenterFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
- return (other === this) ||
- (defined.defined(other) &&
- other instanceof OrthographicOffCenterFrustum &&
- _Math.CesiumMath.equalsEpsilon(this.right, other.right, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.left, other.left, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.top, other.top, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.bottom, other.bottom, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon));
- };
- /**
- * The viewing frustum is defined by 6 planes.
- * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components
- * define the unit vector normal to the plane, and the w component is the distance of the
- * plane from the origin/camera position.
- *
- * @alias OrthographicFrustum
- * @constructor
- *
- * @param {Object} [options] An object with the following properties:
- * @param {Number} [options.width] The width of the frustum in meters.
- * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.
- * @param {Number} [options.near=1.0] The distance of the near plane.
- * @param {Number} [options.far=500000000.0] The distance of the far plane.
- *
- * @example
- * var maxRadii = ellipsoid.maximumRadius;
- *
- * var frustum = new Cesium.OrthographicFrustum();
- * frustum.near = 0.01 * maxRadii;
- * frustum.far = 50.0 * maxRadii;
- */
- function OrthographicFrustum(options) {
- options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
- this._offCenterFrustum = new OrthographicOffCenterFrustum();
- /**
- * The horizontal width of the frustum in meters.
- * @type {Number}
- * @default undefined
- */
- this.width = options.width;
- this._width = undefined;
- /**
- * The aspect ratio of the frustum's width to it's height.
- * @type {Number}
- * @default undefined
- */
- this.aspectRatio = options.aspectRatio;
- this._aspectRatio = undefined;
- /**
- * The distance of the near plane.
- * @type {Number}
- * @default 1.0
- */
- this.near = defaultValue.defaultValue(options.near, 1.0);
- this._near = this.near;
- /**
- * The distance of the far plane.
- * @type {Number}
- * @default 500000000.0;
- */
- this.far = defaultValue.defaultValue(options.far, 500000000.0);
- this._far = this.far;
- }
- /**
- * The number of elements used to pack the object into an array.
- * @type {Number}
- */
- OrthographicFrustum.packedLength = 4;
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {OrthographicFrustum} value The value to pack.
- * @param {Number[]} array The array to pack into.
- * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {Number[]} The array that was packed into
- */
- OrthographicFrustum.pack = function(value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object('value', value);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- array[startingIndex++] = value.width;
- array[startingIndex++] = value.aspectRatio;
- array[startingIndex++] = value.near;
- array[startingIndex] = value.far;
- return array;
- };
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {Number[]} array The packed array.
- * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {OrthographicFrustum} [result] The object into which to store the result.
- * @returns {OrthographicFrustum} The modified result parameter or a new OrthographicFrustum instance if one was not provided.
- */
- OrthographicFrustum.unpack = function(array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- if (!defined.defined(result)) {
- result = new OrthographicFrustum();
- }
- result.width = array[startingIndex++];
- result.aspectRatio = array[startingIndex++];
- result.near = array[startingIndex++];
- result.far = array[startingIndex];
- return result;
- };
- function update$1(frustum) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(frustum.width) || !defined.defined(frustum.aspectRatio) || !defined.defined(frustum.near) || !defined.defined(frustum.far)) {
- throw new Check.DeveloperError('width, aspectRatio, near, or far parameters are not set.');
- }
- //>>includeEnd('debug');
- var f = frustum._offCenterFrustum;
- if (frustum.width !== frustum._width || frustum.aspectRatio !== frustum._aspectRatio ||
- frustum.near !== frustum._near || frustum.far !== frustum._far) {
- //>>includeStart('debug', pragmas.debug);
- if (frustum.aspectRatio < 0) {
- throw new Check.DeveloperError('aspectRatio must be positive.');
- }
- if (frustum.near < 0 || frustum.near > frustum.far) {
- throw new Check.DeveloperError('near must be greater than zero and less than far.');
- }
- //>>includeEnd('debug');
- frustum._aspectRatio = frustum.aspectRatio;
- frustum._width = frustum.width;
- frustum._near = frustum.near;
- frustum._far = frustum.far;
- var ratio = 1.0 / frustum.aspectRatio;
- f.right = frustum.width * 0.5;
- f.left = -f.right;
- f.top = ratio * f.right;
- f.bottom = -f.top;
- f.near = frustum.near;
- f.far = frustum.far;
- }
- }
- defineProperties.defineProperties(OrthographicFrustum.prototype, {
- /**
- * Gets the orthographic projection matrix computed from the view frustum.
- * @memberof OrthographicFrustum.prototype
- * @type {Matrix4}
- * @readonly
- */
- projectionMatrix : {
- get : function() {
- update$1(this);
- return this._offCenterFrustum.projectionMatrix;
- }
- }
- });
- /**
- * Creates a culling volume for this frustum.
- *
- * @param {Cartesian3} position The eye position.
- * @param {Cartesian3} direction The view direction.
- * @param {Cartesian3} up The up direction.
- * @returns {CullingVolume} A culling volume at the given position and orientation.
- *
- * @example
- * // Check if a bounding volume intersects the frustum.
- * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
- * var intersect = cullingVolume.computeVisibility(boundingVolume);
- */
- OrthographicFrustum.prototype.computeCullingVolume = function(position, direction, up) {
- update$1(this);
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
- };
- /**
- * Returns the pixel's width and height in meters.
- *
- * @param {Number} drawingBufferWidth The width of the drawing buffer.
- * @param {Number} drawingBufferHeight The height of the drawing buffer.
- * @param {Number} distance The distance to the near plane in meters.
- * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space.
- * @param {Cartesian2} result The object onto which to store the result.
- * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.
- *
- * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
- * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
- * @exception {DeveloperError} pixelRatio must be greater than zero.
- *
- * @example
- * // Example 1
- * // Get the width and height of a pixel.
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2());
- */
- OrthographicFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) {
- update$1(this);
- if (pixelRatio instanceof Cartesian2.Cartesian2) {
- result = pixelRatio;
- pixelRatio = 1.0;
- Transforms.deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.');
- }
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result);
- };
- /**
- * Returns a duplicate of a OrthographicFrustum instance.
- *
- * @param {OrthographicFrustum} [result] The object onto which to store the result.
- * @returns {OrthographicFrustum} The modified result parameter or a new OrthographicFrustum instance if one was not provided.
- */
- OrthographicFrustum.prototype.clone = function(result) {
- if (!defined.defined(result)) {
- result = new OrthographicFrustum();
- }
- result.aspectRatio = this.aspectRatio;
- result.width = this.width;
- result.near = this.near;
- result.far = this.far;
- // force update of clone to compute matrices
- result._aspectRatio = undefined;
- result._width = undefined;
- result._near = undefined;
- result._far = undefined;
- this._offCenterFrustum.clone(result._offCenterFrustum);
- return result;
- };
- /**
- * Compares the provided OrthographicFrustum componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {OrthographicFrustum} [other] The right hand side OrthographicFrustum.
- * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- OrthographicFrustum.prototype.equals = function(other) {
- if (!defined.defined(other) || !(other instanceof OrthographicFrustum)) {
- return false;
- }
- update$1(this);
- update$1(other);
- return (this.width === other.width &&
- this.aspectRatio === other.aspectRatio &&
- this._offCenterFrustum.equals(other._offCenterFrustum));
- };
- /**
- * Compares the provided OrthographicFrustum componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {OrthographicFrustum} other The right hand side OrthographicFrustum.
- * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
- * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
- */
- OrthographicFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
- if (!defined.defined(other) || !(other instanceof OrthographicFrustum)) {
- return false;
- }
- update$1(this);
- update$1(other);
- return (_Math.CesiumMath.equalsEpsilon(this.width, other.width, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.aspectRatio, other.aspectRatio, relativeEpsilon, absoluteEpsilon) &&
- this._offCenterFrustum.equalsEpsilon(other._offCenterFrustum, relativeEpsilon, absoluteEpsilon));
- };
- /**
- * The viewing frustum is defined by 6 planes.
- * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components
- * define the unit vector normal to the plane, and the w component is the distance of the
- * plane from the origin/camera position.
- *
- * @alias PerspectiveOffCenterFrustum
- * @constructor
- *
- * @param {Object} [options] An object with the following properties:
- * @param {Number} [options.left] The left clipping plane distance.
- * @param {Number} [options.right] The right clipping plane distance.
- * @param {Number} [options.top] The top clipping plane distance.
- * @param {Number} [options.bottom] The bottom clipping plane distance.
- * @param {Number} [options.near=1.0] The near clipping plane distance.
- * @param {Number} [options.far=500000000.0] The far clipping plane distance.
- *
- * @example
- * var frustum = new Cesium.PerspectiveOffCenterFrustum({
- * left : -1.0,
- * right : 1.0,
- * top : 1.0,
- * bottom : -1.0,
- * near : 1.0,
- * far : 100.0
- * });
- *
- * @see PerspectiveFrustum
- */
- function PerspectiveOffCenterFrustum(options) {
- options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
- /**
- * Defines the left clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.left = options.left;
- this._left = undefined;
- /**
- * Defines the right clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.right = options.right;
- this._right = undefined;
- /**
- * Defines the top clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.top = options.top;
- this._top = undefined;
- /**
- * Defines the bottom clipping plane.
- * @type {Number}
- * @default undefined
- */
- this.bottom = options.bottom;
- this._bottom = undefined;
- /**
- * The distance of the near plane.
- * @type {Number}
- * @default 1.0
- */
- this.near = defaultValue.defaultValue(options.near, 1.0);
- this._near = this.near;
- /**
- * The distance of the far plane.
- * @type {Number}
- * @default 500000000.0
- */
- this.far = defaultValue.defaultValue(options.far, 500000000.0);
- this._far = this.far;
- this._cullingVolume = new CullingVolume();
- this._perspectiveMatrix = new Transforms.Matrix4();
- this._infinitePerspective = new Transforms.Matrix4();
- }
- function update$2(frustum) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(frustum.right) || !defined.defined(frustum.left) ||
- !defined.defined(frustum.top) || !defined.defined(frustum.bottom) ||
- !defined.defined(frustum.near) || !defined.defined(frustum.far)) {
- throw new Check.DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
- }
- //>>includeEnd('debug');
- var t = frustum.top;
- var b = frustum.bottom;
- var r = frustum.right;
- var l = frustum.left;
- var n = frustum.near;
- var f = frustum.far;
- if (t !== frustum._top || b !== frustum._bottom ||
- l !== frustum._left || r !== frustum._right ||
- n !== frustum._near || f !== frustum._far) {
- //>>includeStart('debug', pragmas.debug);
- if (frustum.near <= 0 || frustum.near > frustum.far) {
- throw new Check.DeveloperError('near must be greater than zero and less than far.');
- }
- //>>includeEnd('debug');
- frustum._left = l;
- frustum._right = r;
- frustum._top = t;
- frustum._bottom = b;
- frustum._near = n;
- frustum._far = f;
- frustum._perspectiveMatrix = Transforms.Matrix4.computePerspectiveOffCenter(l, r, b, t, n, f, frustum._perspectiveMatrix);
- frustum._infinitePerspective = Transforms.Matrix4.computeInfinitePerspectiveOffCenter(l, r, b, t, n, frustum._infinitePerspective);
- }
- }
- defineProperties.defineProperties(PerspectiveOffCenterFrustum.prototype, {
- /**
- * Gets the perspective projection matrix computed from the view frustum.
- * @memberof PerspectiveOffCenterFrustum.prototype
- * @type {Matrix4}
- * @readonly
- *
- * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
- */
- projectionMatrix : {
- get : function() {
- update$2(this);
- return this._perspectiveMatrix;
- }
- },
- /**
- * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
- * @memberof PerspectiveOffCenterFrustum.prototype
- * @type {Matrix4}
- * @readonly
- *
- * @see PerspectiveOffCenterFrustum#projectionMatrix
- */
- infiniteProjectionMatrix : {
- get : function() {
- update$2(this);
- return this._infinitePerspective;
- }
- }
- });
- var getPlanesRight$1 = new Cartesian2.Cartesian3();
- var getPlanesNearCenter$1 = new Cartesian2.Cartesian3();
- var getPlanesFarCenter = new Cartesian2.Cartesian3();
- var getPlanesNormal = new Cartesian2.Cartesian3();
- /**
- * Creates a culling volume for this frustum.
- *
- * @param {Cartesian3} position The eye position.
- * @param {Cartesian3} direction The view direction.
- * @param {Cartesian3} up The up direction.
- * @returns {CullingVolume} A culling volume at the given position and orientation.
- *
- * @example
- * // Check if a bounding volume intersects the frustum.
- * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
- * var intersect = cullingVolume.computeVisibility(boundingVolume);
- */
- PerspectiveOffCenterFrustum.prototype.computeCullingVolume = function(position, direction, up) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(position)) {
- throw new Check.DeveloperError('position is required.');
- }
- if (!defined.defined(direction)) {
- throw new Check.DeveloperError('direction is required.');
- }
- if (!defined.defined(up)) {
- throw new Check.DeveloperError('up is required.');
- }
- //>>includeEnd('debug');
- var planes = this._cullingVolume.planes;
- var t = this.top;
- var b = this.bottom;
- var r = this.right;
- var l = this.left;
- var n = this.near;
- var f = this.far;
- var right = Cartesian2.Cartesian3.cross(direction, up, getPlanesRight$1);
- var nearCenter = getPlanesNearCenter$1;
- Cartesian2.Cartesian3.multiplyByScalar(direction, n, nearCenter);
- Cartesian2.Cartesian3.add(position, nearCenter, nearCenter);
- var farCenter = getPlanesFarCenter;
- Cartesian2.Cartesian3.multiplyByScalar(direction, f, farCenter);
- Cartesian2.Cartesian3.add(position, farCenter, farCenter);
- var normal = getPlanesNormal;
- //Left plane computation
- Cartesian2.Cartesian3.multiplyByScalar(right, l, normal);
- Cartesian2.Cartesian3.add(nearCenter, normal, normal);
- Cartesian2.Cartesian3.subtract(normal, position, normal);
- Cartesian2.Cartesian3.normalize(normal, normal);
- Cartesian2.Cartesian3.cross(normal, up, normal);
- Cartesian2.Cartesian3.normalize(normal, normal);
- var plane = planes[0];
- if (!defined.defined(plane)) {
- plane = planes[0] = new Transforms.Cartesian4();
- }
- plane.x = normal.x;
- plane.y = normal.y;
- plane.z = normal.z;
- plane.w = -Cartesian2.Cartesian3.dot(normal, position);
- //Right plane computation
- Cartesian2.Cartesian3.multiplyByScalar(right, r, normal);
- Cartesian2.Cartesian3.add(nearCenter, normal, normal);
- Cartesian2.Cartesian3.subtract(normal, position, normal);
- Cartesian2.Cartesian3.cross(up, normal, normal);
- Cartesian2.Cartesian3.normalize(normal, normal);
- plane = planes[1];
- if (!defined.defined(plane)) {
- plane = planes[1] = new Transforms.Cartesian4();
- }
- plane.x = normal.x;
- plane.y = normal.y;
- plane.z = normal.z;
- plane.w = -Cartesian2.Cartesian3.dot(normal, position);
- //Bottom plane computation
- Cartesian2.Cartesian3.multiplyByScalar(up, b, normal);
- Cartesian2.Cartesian3.add(nearCenter, normal, normal);
- Cartesian2.Cartesian3.subtract(normal, position, normal);
- Cartesian2.Cartesian3.cross(right, normal, normal);
- Cartesian2.Cartesian3.normalize(normal, normal);
- plane = planes[2];
- if (!defined.defined(plane)) {
- plane = planes[2] = new Transforms.Cartesian4();
- }
- plane.x = normal.x;
- plane.y = normal.y;
- plane.z = normal.z;
- plane.w = -Cartesian2.Cartesian3.dot(normal, position);
- //Top plane computation
- Cartesian2.Cartesian3.multiplyByScalar(up, t, normal);
- Cartesian2.Cartesian3.add(nearCenter, normal, normal);
- Cartesian2.Cartesian3.subtract(normal, position, normal);
- Cartesian2.Cartesian3.cross(normal, right, normal);
- Cartesian2.Cartesian3.normalize(normal, normal);
- plane = planes[3];
- if (!defined.defined(plane)) {
- plane = planes[3] = new Transforms.Cartesian4();
- }
- plane.x = normal.x;
- plane.y = normal.y;
- plane.z = normal.z;
- plane.w = -Cartesian2.Cartesian3.dot(normal, position);
- //Near plane computation
- plane = planes[4];
- if (!defined.defined(plane)) {
- plane = planes[4] = new Transforms.Cartesian4();
- }
- plane.x = direction.x;
- plane.y = direction.y;
- plane.z = direction.z;
- plane.w = -Cartesian2.Cartesian3.dot(direction, nearCenter);
- //Far plane computation
- Cartesian2.Cartesian3.negate(direction, normal);
- plane = planes[5];
- if (!defined.defined(plane)) {
- plane = planes[5] = new Transforms.Cartesian4();
- }
- plane.x = normal.x;
- plane.y = normal.y;
- plane.z = normal.z;
- plane.w = -Cartesian2.Cartesian3.dot(normal, farCenter);
- return this._cullingVolume;
- };
- /**
- * Returns the pixel's width and height in meters.
- *
- * @param {Number} drawingBufferWidth The width of the drawing buffer.
- * @param {Number} drawingBufferHeight The height of the drawing buffer.
- * @param {Number} distance The distance to the near plane in meters.
- * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space.
- * @param {Cartesian2} result The object onto which to store the result.
- * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.
- *
- * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
- * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
- * @exception {DeveloperError} pixelRatio must be greater than zero.
- *
- * @example
- * // Example 1
- * // Get the width and height of a pixel.
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new Cesium.Cartesian2());
- *
- * @example
- * // Example 2
- * // Get the width and height of a pixel if the near plane was set to 'distance'.
- * // For example, get the size of a pixel of an image on a billboard.
- * var position = camera.position;
- * var direction = camera.direction;
- * var toCenter = Cesium.Cartesian3.subtract(primitive.boundingVolume.center, position, new Cesium.Cartesian3()); // vector from camera to a primitive
- * var toCenterProj = Cesium.Cartesian3.multiplyByScalar(direction, Cesium.Cartesian3.dot(direction, toCenter), new Cesium.Cartesian3()); // project vector onto camera direction vector
- * var distance = Cesium.Cartesian3.magnitude(toCenterProj);
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cesium.Cartesian2());
- */
- PerspectiveOffCenterFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) {
- update$2(this);
- if (pixelRatio instanceof Cartesian2.Cartesian2) {
- result = pixelRatio;
- pixelRatio = 1.0;
- Transforms.deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.');
- }
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(drawingBufferWidth) || !defined.defined(drawingBufferHeight)) {
- throw new Check.DeveloperError('Both drawingBufferWidth and drawingBufferHeight are required.');
- }
- if (drawingBufferWidth <= 0) {
- throw new Check.DeveloperError('drawingBufferWidth must be greater than zero.');
- }
- if (drawingBufferHeight <= 0) {
- throw new Check.DeveloperError('drawingBufferHeight must be greater than zero.');
- }
- if (!defined.defined(distance)) {
- throw new Check.DeveloperError('distance is required.');
- }
- if (!defined.defined(pixelRatio)) {
- throw new Check.DeveloperError('pixelRatio is required');
- }
- if (pixelRatio <= 0) {
- throw new Check.DeveloperError('pixelRatio must be greater than zero.');
- }
- if (!defined.defined(result)) {
- throw new Check.DeveloperError('A result object is required.');
- }
- //>>includeEnd('debug');
- var inverseNear = 1.0 / this.near;
- var tanTheta = this.top * inverseNear;
- var pixelHeight = 2.0 * pixelRatio * distance * tanTheta / drawingBufferHeight;
- tanTheta = this.right * inverseNear;
- var pixelWidth = 2.0 * pixelRatio * distance * tanTheta / drawingBufferWidth;
- result.x = pixelWidth;
- result.y = pixelHeight;
- return result;
- };
- /**
- * Returns a duplicate of a PerspectiveOffCenterFrustum instance.
- *
- * @param {PerspectiveOffCenterFrustum} [result] The object onto which to store the result.
- * @returns {PerspectiveOffCenterFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
- */
- PerspectiveOffCenterFrustum.prototype.clone = function(result) {
- if (!defined.defined(result)) {
- result = new PerspectiveOffCenterFrustum();
- }
- result.right = this.right;
- result.left = this.left;
- result.top = this.top;
- result.bottom = this.bottom;
- result.near = this.near;
- result.far = this.far;
- // force update of clone to compute matrices
- result._left = undefined;
- result._right = undefined;
- result._top = undefined;
- result._bottom = undefined;
- result._near = undefined;
- result._far = undefined;
- return result;
- };
- /**
- * Compares the provided PerspectiveOffCenterFrustum componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.
- * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- PerspectiveOffCenterFrustum.prototype.equals = function(other) {
- return (defined.defined(other) && other instanceof PerspectiveOffCenterFrustum &&
- this.right === other.right &&
- this.left === other.left &&
- this.top === other.top &&
- this.bottom === other.bottom &&
- this.near === other.near &&
- this.far === other.far);
- };
- /**
- * Compares the provided PerspectiveOffCenterFrustum componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {PerspectiveOffCenterFrustum} other The right hand side PerspectiveOffCenterFrustum.
- * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
- * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
- */
- PerspectiveOffCenterFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
- return (other === this) ||
- (defined.defined(other) &&
- other instanceof PerspectiveOffCenterFrustum &&
- _Math.CesiumMath.equalsEpsilon(this.right, other.right, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.left, other.left, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.top, other.top, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.bottom, other.bottom, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.near, other.near, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.far, other.far, relativeEpsilon, absoluteEpsilon));
- };
- /**
- * The viewing frustum is defined by 6 planes.
- * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components
- * define the unit vector normal to the plane, and the w component is the distance of the
- * plane from the origin/camera position.
- *
- * @alias PerspectiveFrustum
- * @constructor
- *
- * @param {Object} [options] An object with the following properties:
- * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.
- * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.
- * @param {Number} [options.near=1.0] The distance of the near plane.
- * @param {Number} [options.far=500000000.0] The distance of the far plane.
- * @param {Number} [options.xOffset=0.0] The offset in the x direction.
- * @param {Number} [options.yOffset=0.0] The offset in the y direction.
- *
- * @example
- * var frustum = new Cesium.PerspectiveFrustum({
- * fov : Cesium.Math.PI_OVER_THREE,
- * aspectRatio : canvas.clientWidth / canvas.clientHeight
- * near : 1.0,
- * far : 1000.0
- * });
- *
- * @see PerspectiveOffCenterFrustum
- */
- function PerspectiveFrustum(options) {
- options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
- this._offCenterFrustum = new PerspectiveOffCenterFrustum();
- /**
- * The angle of the field of view (FOV), in radians. This angle will be used
- * as the horizontal FOV if the width is greater than the height, otherwise
- * it will be the vertical FOV.
- * @type {Number}
- * @default undefined
- */
- this.fov = options.fov;
- this._fov = undefined;
- this._fovy = undefined;
- this._sseDenominator = undefined;
- /**
- * The aspect ratio of the frustum's width to it's height.
- * @type {Number}
- * @default undefined
- */
- this.aspectRatio = options.aspectRatio;
- this._aspectRatio = undefined;
- /**
- * The distance of the near plane.
- * @type {Number}
- * @default 1.0
- */
- this.near = defaultValue.defaultValue(options.near, 1.0);
- this._near = this.near;
- /**
- * The distance of the far plane.
- * @type {Number}
- * @default 500000000.0
- */
- this.far = defaultValue.defaultValue(options.far, 500000000.0);
- this._far = this.far;
- /**
- * Offsets the frustum in the x direction.
- * @type {Number}
- * @default 0.0
- */
- this.xOffset = defaultValue.defaultValue(options.xOffset, 0.0);
- this._xOffset = this.xOffset;
- /**
- * Offsets the frustum in the y direction.
- * @type {Number}
- * @default 0.0
- */
- this.yOffset = defaultValue.defaultValue(options.yOffset, 0.0);
- this._yOffset = this.yOffset;
- }
- /**
- * The number of elements used to pack the object into an array.
- * @type {Number}
- */
- PerspectiveFrustum.packedLength = 6;
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {PerspectiveFrustum} value The value to pack.
- * @param {Number[]} array The array to pack into.
- * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {Number[]} The array that was packed into
- */
- PerspectiveFrustum.pack = function(value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object('value', value);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- array[startingIndex++] = value.fov;
- array[startingIndex++] = value.aspectRatio;
- array[startingIndex++] = value.near;
- array[startingIndex++] = value.far;
- array[startingIndex++] = value.xOffset;
- array[startingIndex] = value.yOffset;
- return array;
- };
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {Number[]} array The packed array.
- * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {PerspectiveFrustum} [result] The object into which to store the result.
- * @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
- */
- PerspectiveFrustum.unpack = function(array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- if (!defined.defined(result)) {
- result = new PerspectiveFrustum();
- }
- result.fov = array[startingIndex++];
- result.aspectRatio = array[startingIndex++];
- result.near = array[startingIndex++];
- result.far = array[startingIndex++];
- result.xOffset = array[startingIndex++];
- result.yOffset = array[startingIndex];
- return result;
- };
- function update$3(frustum) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined.defined(frustum.fov) || !defined.defined(frustum.aspectRatio) || !defined.defined(frustum.near) || !defined.defined(frustum.far)) {
- throw new Check.DeveloperError('fov, aspectRatio, near, or far parameters are not set.');
- }
- //>>includeEnd('debug');
- var f = frustum._offCenterFrustum;
- if (frustum.fov !== frustum._fov || frustum.aspectRatio !== frustum._aspectRatio ||
- frustum.near !== frustum._near || frustum.far !== frustum._far ||
- frustum.xOffset !== frustum._xOffset || frustum.yOffset !== frustum._yOffset) {
- //>>includeStart('debug', pragmas.debug);
- if (frustum.fov < 0 || frustum.fov >= Math.PI) {
- throw new Check.DeveloperError('fov must be in the range [0, PI).');
- }
- if (frustum.aspectRatio < 0) {
- throw new Check.DeveloperError('aspectRatio must be positive.');
- }
- if (frustum.near < 0 || frustum.near > frustum.far) {
- throw new Check.DeveloperError('near must be greater than zero and less than far.');
- }
- //>>includeEnd('debug');
- frustum._aspectRatio = frustum.aspectRatio;
- frustum._fov = frustum.fov;
- frustum._fovy = (frustum.aspectRatio <= 1) ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;
- frustum._near = frustum.near;
- frustum._far = frustum.far;
- frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);
- frustum._xOffset = frustum.xOffset;
- frustum._yOffset = frustum.yOffset;
- f.top = frustum.near * Math.tan(0.5 * frustum._fovy);
- f.bottom = -f.top;
- f.right = frustum.aspectRatio * f.top;
- f.left = -f.right;
- f.near = frustum.near;
- f.far = frustum.far;
- f.right += frustum.xOffset;
- f.left += frustum.xOffset;
- f.top += frustum.yOffset;
- f.bottom += frustum.yOffset;
- }
- }
- defineProperties.defineProperties(PerspectiveFrustum.prototype, {
- /**
- * Gets the perspective projection matrix computed from the view frustum.
- * @memberof PerspectiveFrustum.prototype
- * @type {Matrix4}
- * @readonly
- *
- * @see PerspectiveFrustum#infiniteProjectionMatrix
- */
- projectionMatrix : {
- get : function() {
- update$3(this);
- return this._offCenterFrustum.projectionMatrix;
- }
- },
- /**
- * The perspective projection matrix computed from the view frustum with an infinite far plane.
- * @memberof PerspectiveFrustum.prototype
- * @type {Matrix4}
- * @readonly
- *
- * @see PerspectiveFrustum#projectionMatrix
- */
- infiniteProjectionMatrix : {
- get : function() {
- update$3(this);
- return this._offCenterFrustum.infiniteProjectionMatrix;
- }
- },
- /**
- * Gets the angle of the vertical field of view, in radians.
- * @memberof PerspectiveFrustum.prototype
- * @type {Number}
- * @readonly
- * @default undefined
- */
- fovy : {
- get : function() {
- update$3(this);
- return this._fovy;
- }
- },
- /**
- * @readonly
- * @private
- */
- sseDenominator : {
- get : function () {
- update$3(this);
- return this._sseDenominator;
- }
- }
- });
- /**
- * Creates a culling volume for this frustum.
- *
- * @param {Cartesian3} position The eye position.
- * @param {Cartesian3} direction The view direction.
- * @param {Cartesian3} up The up direction.
- * @returns {CullingVolume} A culling volume at the given position and orientation.
- *
- * @example
- * // Check if a bounding volume intersects the frustum.
- * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
- * var intersect = cullingVolume.computeVisibility(boundingVolume);
- */
- PerspectiveFrustum.prototype.computeCullingVolume = function(position, direction, up) {
- update$3(this);
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
- };
- /**
- * Returns the pixel's width and height in meters.
- *
- * @param {Number} drawingBufferWidth The width of the drawing buffer.
- * @param {Number} drawingBufferHeight The height of the drawing buffer.
- * @param {Number} distance The distance to the near plane in meters.
- * @param {Number} pixelRatio The scaling factor from pixel space to coordinate space.
- * @param {Cartesian2} result The object onto which to store the result.
- * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.
- *
- * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
- * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
- * @exception {DeveloperError} pixelRatio must be greater than zero.
- *
- * @example
- * // Example 1
- * // Get the width and height of a pixel.
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new Cesium.Cartesian2());
- *
- * @example
- * // Example 2
- * // Get the width and height of a pixel if the near plane was set to 'distance'.
- * // For example, get the size of a pixel of an image on a billboard.
- * var position = camera.position;
- * var direction = camera.direction;
- * var toCenter = Cesium.Cartesian3.subtract(primitive.boundingVolume.center, position, new Cesium.Cartesian3()); // vector from camera to a primitive
- * var toCenterProj = Cesium.Cartesian3.multiplyByScalar(direction, Cesium.Cartesian3.dot(direction, toCenter), new Cesium.Cartesian3()); // project vector onto camera direction vector
- * var distance = Cesium.Cartesian3.magnitude(toCenterProj);
- * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cesium.Cartesian2());
- */
- PerspectiveFrustum.prototype.getPixelDimensions = function(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result) {
- update$3(this);
- if (pixelRatio instanceof Cartesian2.Cartesian2) {
- result = pixelRatio;
- pixelRatio = 1.0;
- Transforms.deprecationWarning('getPixelDimensions-parameter-change', 'getPixelDimensions now takes a pixelRatio argument before the result argument in Cesium 1.63. The previous function definition will no longer work in 1.65.');
- }
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result);
- };
- /**
- * Returns a duplicate of a PerspectiveFrustum instance.
- *
- * @param {PerspectiveFrustum} [result] The object onto which to store the result.
- * @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
- */
- PerspectiveFrustum.prototype.clone = function(result) {
- if (!defined.defined(result)) {
- result = new PerspectiveFrustum();
- }
- result.aspectRatio = this.aspectRatio;
- result.fov = this.fov;
- result.near = this.near;
- result.far = this.far;
- // force update of clone to compute matrices
- result._aspectRatio = undefined;
- result._fov = undefined;
- result._near = undefined;
- result._far = undefined;
- this._offCenterFrustum.clone(result._offCenterFrustum);
- return result;
- };
- /**
- * Compares the provided PerspectiveFrustum componentwise and returns
- * <code>true</code> if they are equal, <code>false</code> otherwise.
- *
- * @param {PerspectiveFrustum} [other] The right hand side PerspectiveFrustum.
- * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
- */
- PerspectiveFrustum.prototype.equals = function(other) {
- if (!defined.defined(other) || !(other instanceof PerspectiveFrustum)) {
- return false;
- }
- update$3(this);
- update$3(other);
- return (this.fov === other.fov &&
- this.aspectRatio === other.aspectRatio &&
- this._offCenterFrustum.equals(other._offCenterFrustum));
- };
- /**
- * Compares the provided PerspectiveFrustum componentwise and returns
- * <code>true</code> if they pass an absolute or relative tolerance test,
- * <code>false</code> otherwise.
- *
- * @param {PerspectiveFrustum} other The right hand side PerspectiveFrustum.
- * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
- * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
- * @returns {Boolean} <code>true</code> if this and other are within the provided epsilon, <code>false</code> otherwise.
- */
- PerspectiveFrustum.prototype.equalsEpsilon = function(other, relativeEpsilon, absoluteEpsilon) {
- if (!defined.defined(other) || !(other instanceof PerspectiveFrustum)) {
- return false;
- }
- update$3(this);
- update$3(other);
- return (_Math.CesiumMath.equalsEpsilon(this.fov, other.fov, relativeEpsilon, absoluteEpsilon) &&
- _Math.CesiumMath.equalsEpsilon(this.aspectRatio, other.aspectRatio, relativeEpsilon, absoluteEpsilon) &&
- this._offCenterFrustum.equalsEpsilon(other._offCenterFrustum, relativeEpsilon, absoluteEpsilon));
- };
- var PERSPECTIVE = 0;
- var ORTHOGRAPHIC = 1;
- /**
- * Describes a frustum at the given the origin and orientation.
- *
- * @alias FrustumGeometry
- * @constructor
- *
- * @param {Object} options Object with the following properties:
- * @param {PerspectiveFrustum|OrthographicFrustum} options.frustum The frustum.
- * @param {Cartesian3} options.origin The origin of the frustum.
- * @param {Quaternion} options.orientation The orientation of the frustum.
- * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
- */
- function FrustumGeometry(options) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object('options', options);
- Check.Check.typeOf.object('options.frustum', options.frustum);
- Check.Check.typeOf.object('options.origin', options.origin);
- Check.Check.typeOf.object('options.orientation', options.orientation);
- //>>includeEnd('debug');
- var frustum = options.frustum;
- var orientation = options.orientation;
- var origin = options.origin;
- var vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
- // This is private because it is used by DebugCameraPrimitive to draw a multi-frustum by
- // creating multiple FrustumGeometrys. This way the near plane of one frustum doesn't overlap
- // the far plane of another.
- var drawNearPlane = defaultValue.defaultValue(options._drawNearPlane, true);
- var frustumType;
- var frustumPackedLength;
- if (frustum instanceof PerspectiveFrustum) {
- frustumType = PERSPECTIVE;
- frustumPackedLength = PerspectiveFrustum.packedLength;
- } else if (frustum instanceof OrthographicFrustum) {
- frustumType = ORTHOGRAPHIC;
- frustumPackedLength = OrthographicFrustum.packedLength;
- }
- this._frustumType = frustumType;
- this._frustum = frustum.clone();
- this._origin = Cartesian2.Cartesian3.clone(origin);
- this._orientation = Transforms.Quaternion.clone(orientation);
- this._drawNearPlane = drawNearPlane;
- this._vertexFormat = vertexFormat;
- this._workerName = 'createFrustumGeometry';
- /**
- * The number of elements used to pack the object into an array.
- * @type {Number}
- */
- this.packedLength = 2 + frustumPackedLength + Cartesian2.Cartesian3.packedLength + Transforms.Quaternion.packedLength + VertexFormat.VertexFormat.packedLength;
- }
- /**
- * Stores the provided instance into the provided array.
- *
- * @param {FrustumGeometry} value The value to pack.
- * @param {Number[]} array The array to pack into.
- * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
- *
- * @returns {Number[]} The array that was packed into
- */
- FrustumGeometry.pack = function(value, array, startingIndex) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.typeOf.object('value', value);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- var frustumType = value._frustumType;
- var frustum = value._frustum;
- array[startingIndex++] = frustumType;
- if (frustumType === PERSPECTIVE) {
- PerspectiveFrustum.pack(frustum, array, startingIndex);
- startingIndex += PerspectiveFrustum.packedLength;
- } else {
- OrthographicFrustum.pack(frustum, array, startingIndex);
- startingIndex += OrthographicFrustum.packedLength;
- }
- Cartesian2.Cartesian3.pack(value._origin, array, startingIndex);
- startingIndex += Cartesian2.Cartesian3.packedLength;
- Transforms.Quaternion.pack(value._orientation, array, startingIndex);
- startingIndex += Transforms.Quaternion.packedLength;
- VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
- startingIndex += VertexFormat.VertexFormat.packedLength;
- array[startingIndex] = value._drawNearPlane ? 1.0 : 0.0;
- return array;
- };
- var scratchPackPerspective = new PerspectiveFrustum();
- var scratchPackOrthographic = new OrthographicFrustum();
- var scratchPackQuaternion = new Transforms.Quaternion();
- var scratchPackorigin = new Cartesian2.Cartesian3();
- var scratchVertexFormat = new VertexFormat.VertexFormat();
- /**
- * Retrieves an instance from a packed array.
- *
- * @param {Number[]} array The packed array.
- * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
- * @param {FrustumGeometry} [result] The object into which to store the result.
- */
- FrustumGeometry.unpack = function(array, startingIndex, result) {
- //>>includeStart('debug', pragmas.debug);
- Check.Check.defined('array', array);
- //>>includeEnd('debug');
- startingIndex = defaultValue.defaultValue(startingIndex, 0);
- var frustumType = array[startingIndex++];
- var frustum;
- if (frustumType === PERSPECTIVE) {
- frustum = PerspectiveFrustum.unpack(array, startingIndex, scratchPackPerspective);
- startingIndex += PerspectiveFrustum.packedLength;
- } else {
- frustum = OrthographicFrustum.unpack(array, startingIndex, scratchPackOrthographic);
- startingIndex += OrthographicFrustum.packedLength;
- }
- var origin = Cartesian2.Cartesian3.unpack(array, startingIndex, scratchPackorigin);
- startingIndex += Cartesian2.Cartesian3.packedLength;
- var orientation = Transforms.Quaternion.unpack(array, startingIndex, scratchPackQuaternion);
- startingIndex += Transforms.Quaternion.packedLength;
- var vertexFormat = VertexFormat.VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
- startingIndex += VertexFormat.VertexFormat.packedLength;
- var drawNearPlane = array[startingIndex] === 1.0;
- if (!defined.defined(result)) {
- return new FrustumGeometry({
- frustum : frustum,
- origin : origin,
- orientation : orientation,
- vertexFormat : vertexFormat,
- _drawNearPlane : drawNearPlane
- });
- }
- var frustumResult = frustumType === result._frustumType ? result._frustum : undefined;
- result._frustum = frustum.clone(frustumResult);
- result._frustumType = frustumType;
- result._origin = Cartesian2.Cartesian3.clone(origin, result._origin);
- result._orientation = Transforms.Quaternion.clone(orientation, result._orientation);
- result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
- result._drawNearPlane = drawNearPlane;
- return result;
- };
- function getAttributes(offset, normals, tangents, bitangents, st, normal, tangent, bitangent) {
- var stOffset = offset / 3 * 2;
- for (var i = 0; i < 4; ++i) {
- if (defined.defined(normals)) {
- normals[offset] = normal.x;
- normals[offset + 1] = normal.y;
- normals[offset + 2] = normal.z;
- }
- if (defined.defined(tangents)) {
- tangents[offset] = tangent.x;
- tangents[offset + 1] = tangent.y;
- tangents[offset + 2] = tangent.z;
- }
- if (defined.defined(bitangents)) {
- bitangents[offset] = bitangent.x;
- bitangents[offset + 1] = bitangent.y;
- bitangents[offset + 2] = bitangent.z;
- }
- offset += 3;
- }
- st[stOffset] = 0.0;
- st[stOffset + 1] = 0.0;
- st[stOffset + 2] = 1.0;
- st[stOffset + 3] = 0.0;
- st[stOffset + 4] = 1.0;
- st[stOffset + 5] = 1.0;
- st[stOffset + 6] = 0.0;
- st[stOffset + 7] = 1.0;
- }
- var scratchRotationMatrix = new Transforms.Matrix3();
- var scratchViewMatrix = new Transforms.Matrix4();
- var scratchInverseMatrix = new Transforms.Matrix4();
- var scratchXDirection = new Cartesian2.Cartesian3();
- var scratchYDirection = new Cartesian2.Cartesian3();
- var scratchZDirection = new Cartesian2.Cartesian3();
- var scratchNegativeX = new Cartesian2.Cartesian3();
- var scratchNegativeY = new Cartesian2.Cartesian3();
- var scratchNegativeZ = new Cartesian2.Cartesian3();
- var frustumSplits = new Array(3);
- var frustumCornersNDC = new Array(4);
- frustumCornersNDC[0] = new Transforms.Cartesian4(-1.0, -1.0, 1.0, 1.0);
- frustumCornersNDC[1] = new Transforms.Cartesian4(1.0, -1.0, 1.0, 1.0);
- frustumCornersNDC[2] = new Transforms.Cartesian4(1.0, 1.0, 1.0, 1.0);
- frustumCornersNDC[3] = new Transforms.Cartesian4(-1.0, 1.0, 1.0, 1.0);
- var scratchFrustumCorners = new Array(4);
- for (var i = 0; i < 4; ++i) {
- scratchFrustumCorners[i] = new Transforms.Cartesian4();
- }
- FrustumGeometry._computeNearFarPlanes = function(origin, orientation, frustumType, frustum, positions, xDirection, yDirection, zDirection) {
- var rotationMatrix = Transforms.Matrix3.fromQuaternion(orientation, scratchRotationMatrix);
- var x = defaultValue.defaultValue(xDirection, scratchXDirection);
- var y = defaultValue.defaultValue(yDirection, scratchYDirection);
- var z = defaultValue.defaultValue(zDirection, scratchZDirection);
- x = Transforms.Matrix3.getColumn(rotationMatrix, 0, x);
- y = Transforms.Matrix3.getColumn(rotationMatrix, 1, y);
- z = Transforms.Matrix3.getColumn(rotationMatrix, 2, z);
- Cartesian2.Cartesian3.normalize(x, x);
- Cartesian2.Cartesian3.normalize(y, y);
- Cartesian2.Cartesian3.normalize(z, z);
- Cartesian2.Cartesian3.negate(x, x);
- var view = Transforms.Matrix4.computeView(origin, z, y, x, scratchViewMatrix);
- var inverseView;
- var inverseViewProjection;
- if (frustumType === PERSPECTIVE) {
- var projection = frustum.projectionMatrix;
- var viewProjection = Transforms.Matrix4.multiply(projection, view, scratchInverseMatrix);
- inverseViewProjection = Transforms.Matrix4.inverse(viewProjection, scratchInverseMatrix);
- } else {
- inverseView = Transforms.Matrix4.inverseTransformation(view, scratchInverseMatrix);
- }
- if (defined.defined(inverseViewProjection)) {
- frustumSplits[0] = frustum.near;
- frustumSplits[1] = frustum.far;
- } else {
- frustumSplits[0] = 0.0;
- frustumSplits[1] = frustum.near;
- frustumSplits[2] = frustum.far;
- }
- for (var i = 0; i < 2; ++i) {
- for (var j = 0; j < 4; ++j) {
- var corner = Transforms.Cartesian4.clone(frustumCornersNDC[j], scratchFrustumCorners[j]);
- if (!defined.defined(inverseViewProjection)) {
- if (defined.defined(frustum._offCenterFrustum)) {
- frustum = frustum._offCenterFrustum;
- }
- var near = frustumSplits[i];
- var far = frustumSplits[i + 1];
- corner.x = (corner.x * (frustum.right - frustum.left) + frustum.left + frustum.right) * 0.5;
- corner.y = (corner.y * (frustum.top - frustum.bottom) + frustum.bottom + frustum.top) * 0.5;
- corner.z = (corner.z * (near - far) - near - far) * 0.5;
- corner.w = 1.0;
- Transforms.Matrix4.multiplyByVector(inverseView, corner, corner);
- } else {
- corner = Transforms.Matrix4.multiplyByVector(inverseViewProjection, corner, corner);
- // Reverse perspective divide
- var w = 1.0 / corner.w;
- Cartesian2.Cartesian3.multiplyByScalar(corner, w, corner);
- Cartesian2.Cartesian3.subtract(corner, origin, corner);
- Cartesian2.Cartesian3.normalize(corner, corner);
- var fac = Cartesian2.Cartesian3.dot(z, corner);
- Cartesian2.Cartesian3.multiplyByScalar(corner, frustumSplits[i] / fac, corner);
- Cartesian2.Cartesian3.add(corner, origin, corner);
- }
- positions[12 * i + j * 3] = corner.x;
- positions[12 * i + j * 3 + 1] = corner.y;
- positions[12 * i + j * 3 + 2] = corner.z;
- }
- }
- };
- /**
- * Computes the geometric representation of a frustum, including its vertices, indices, and a bounding sphere.
- *
- * @param {FrustumGeometry} frustumGeometry A description of the frustum.
- * @returns {Geometry|undefined} The computed vertices and indices.
- */
- FrustumGeometry.createGeometry = function(frustumGeometry) {
- var frustumType = frustumGeometry._frustumType;
- var frustum = frustumGeometry._frustum;
- var origin = frustumGeometry._origin;
- var orientation = frustumGeometry._orientation;
- var drawNearPlane = frustumGeometry._drawNearPlane;
- var vertexFormat = frustumGeometry._vertexFormat;
- var numberOfPlanes = drawNearPlane ? 6 : 5;
- var positions = new Float64Array(3 * 4 * 6);
- FrustumGeometry._computeNearFarPlanes(origin, orientation, frustumType, frustum, positions);
- // -x plane
- var offset = 3 * 4 * 2;
- positions[offset] = positions[3 * 4];
- positions[offset + 1] = positions[3 * 4 + 1];
- positions[offset + 2] = positions[3 * 4 + 2];
- positions[offset + 3] = positions[0];
- positions[offset + 4] = positions[1];
- positions[offset + 5] = positions[2];
- positions[offset + 6] = positions[3 * 3];
- positions[offset + 7] = positions[3 * 3 + 1];
- positions[offset + 8] = positions[3 * 3 + 2];
- positions[offset + 9] = positions[3 * 7];
- positions[offset + 10] = positions[3 * 7 + 1];
- positions[offset + 11] = positions[3 * 7 + 2];
- // -y plane
- offset += 3 * 4;
- positions[offset] = positions[3 * 5];
- positions[offset + 1] = positions[3 * 5 + 1];
- positions[offset + 2] = positions[3 * 5 + 2];
- positions[offset + 3] = positions[3];
- positions[offset + 4] = positions[3 + 1];
- positions[offset + 5] = positions[3 + 2];
- positions[offset + 6] = positions[0];
- positions[offset + 7] = positions[1];
- positions[offset + 8] = positions[2];
- positions[offset + 9] = positions[3 * 4];
- positions[offset + 10] = positions[3 * 4 + 1];
- positions[offset + 11] = positions[3 * 4 + 2];
- // +x plane
- offset += 3 * 4;
- positions[offset] = positions[3];
- positions[offset + 1] = positions[3 + 1];
- positions[offset + 2] = positions[3 + 2];
- positions[offset + 3] = positions[3 * 5];
- positions[offset + 4] = positions[3 * 5 + 1];
- positions[offset + 5] = positions[3 * 5 + 2];
- positions[offset + 6] = positions[3 * 6];
- positions[offset + 7] = positions[3 * 6 + 1];
- positions[offset + 8] = positions[3 * 6 + 2];
- positions[offset + 9] = positions[3 * 2];
- positions[offset + 10] = positions[3 * 2 + 1];
- positions[offset + 11] = positions[3 * 2 + 2];
- // +y plane
- offset += 3 * 4;
- positions[offset] = positions[3 * 2];
- positions[offset + 1] = positions[3 * 2 + 1];
- positions[offset + 2] = positions[3 * 2 + 2];
- positions[offset + 3] = positions[3 * 6];
- positions[offset + 4] = positions[3 * 6 + 1];
- positions[offset + 5] = positions[3 * 6 + 2];
- positions[offset + 6] = positions[3 * 7];
- positions[offset + 7] = positions[3 * 7 + 1];
- positions[offset + 8] = positions[3 * 7 + 2];
- positions[offset + 9] = positions[3 * 3];
- positions[offset + 10] = positions[3 * 3 + 1];
- positions[offset + 11] = positions[3 * 3 + 2];
- if (!drawNearPlane) {
- positions = positions.subarray(3 * 4);
- }
- var attributes = new GeometryAttributes.GeometryAttributes({
- position : new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
- componentsPerAttribute : 3,
- values : positions
- })
- });
- if (defined.defined(vertexFormat.normal) || defined.defined(vertexFormat.tangent) || defined.defined(vertexFormat.bitangent) || defined.defined(vertexFormat.st)) {
- var normals = defined.defined(vertexFormat.normal) ? new Float32Array(3 * 4 * numberOfPlanes) : undefined;
- var tangents = defined.defined(vertexFormat.tangent) ? new Float32Array(3 * 4 * numberOfPlanes) : undefined;
- var bitangents = defined.defined(vertexFormat.bitangent) ? new Float32Array(3 * 4 * numberOfPlanes) : undefined;
- var st = defined.defined(vertexFormat.st) ? new Float32Array(2 * 4 * numberOfPlanes) : undefined;
- var x = scratchXDirection;
- var y = scratchYDirection;
- var z = scratchZDirection;
- var negativeX = Cartesian2.Cartesian3.negate(x, scratchNegativeX);
- var negativeY = Cartesian2.Cartesian3.negate(y, scratchNegativeY);
- var negativeZ = Cartesian2.Cartesian3.negate(z, scratchNegativeZ);
- offset = 0;
- if (drawNearPlane) {
- getAttributes(offset, normals, tangents, bitangents, st, negativeZ, x, y); // near
- offset += 3 * 4;
- }
- getAttributes(offset, normals, tangents, bitangents, st, z, negativeX, y); // far
- offset += 3 * 4;
- getAttributes(offset, normals, tangents, bitangents, st, negativeX, negativeZ, y); // -x
- offset += 3 * 4;
- getAttributes(offset, normals, tangents, bitangents, st, negativeY, negativeZ, negativeX); // -y
- offset += 3 * 4;
- getAttributes(offset, normals, tangents, bitangents, st, x, z, y); // +x
- offset += 3 * 4;
- getAttributes(offset, normals, tangents, bitangents, st, y, z, negativeX); // +y
- if (defined.defined(normals)) {
- attributes.normal = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
- componentsPerAttribute : 3,
- values : normals
- });
- }
- if (defined.defined(tangents)) {
- attributes.tangent = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
- componentsPerAttribute : 3,
- values : tangents
- });
- }
- if (defined.defined(bitangents)) {
- attributes.bitangent = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
- componentsPerAttribute : 3,
- values : bitangents
- });
- }
- if (defined.defined(st)) {
- attributes.st = new GeometryAttribute.GeometryAttribute({
- componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
- componentsPerAttribute : 2,
- values : st
- });
- }
- }
- var indices = new Uint16Array(6 * numberOfPlanes);
- for (var i = 0; i < numberOfPlanes; ++i) {
- var indexOffset = i * 6;
- var index = i * 4;
- indices[indexOffset] = index;
- indices[indexOffset + 1] = index + 1;
- indices[indexOffset + 2] = index + 2;
- indices[indexOffset + 3] = index;
- indices[indexOffset + 4] = index + 2;
- indices[indexOffset + 5] = index + 3;
- }
- return new GeometryAttribute.Geometry({
- attributes : attributes,
- indices : indices,
- primitiveType : GeometryAttribute.PrimitiveType.TRIANGLES,
- boundingSphere : Transforms.BoundingSphere.fromVertices(positions)
- });
- };
- exports.FrustumGeometry = FrustumGeometry;
- exports.OrthographicFrustum = OrthographicFrustum;
- exports.PerspectiveFrustum = PerspectiveFrustum;
- });
|