Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 9605x 122018x 1x 122017x 122017x 122017x 104719x 17298x 2x 17296x 17296x 17296x 17296x 17296x 17296x 17296x 17296x 1x 40814x 40812x 79639x 79638x 1x 1x 1x 1x 1x 13442x 2x 13440x 2x 13438x 2x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 13436x 13436x 1610x 13436x 13436x 13436x 13436x 13436x 1x 1565x 1565x 4x 1561x 2x 1559x 2x 1557x 1557x 2x 1555x 2x 1553x 1553x 1553x 1553x 1553x 1553x 1553x 1553x 1553x 1x 16187x 1x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 16187x 1x 16x 1x 9600x | import Cartesian3 from "./Cartesian3.js";
import Cartesian4 from "./Cartesian4.js";
import CullingVolume from "./CullingVolume.js";
import Frozen from "./Frozen.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import CesiumMath from "./Math.js";
import Matrix4 from "./Matrix4.js";
/**
* 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
* const 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 = options ?? Frozen.EMPTY_OBJECT;
/**
* Defines the left clipping plane.
* @type {number|undefined}
* @default undefined
*/
this.left = options.left;
this._left = undefined;
/**
* Defines the right clipping plane.
* @type {number|undefined}
* @default undefined
*/
this.right = options.right;
this._right = undefined;
/**
* Defines the top clipping plane.
* @type {number|undefined}
* @default undefined
*/
this.top = options.top;
this._top = undefined;
/**
* Defines the bottom clipping plane.
* @type {number|undefined}
* @default undefined
*/
this.bottom = options.bottom;
this._bottom = undefined;
/**
* The distance of the near plane.
* @type {number}
* @default 1.0
*/
this.near = options.near ?? 1.0;
this._near = this.near;
/**
* The distance of the far plane.
* @type {number}
* @default 500000000.0
*/
this.far = options.far ?? 500000000.0;
this._far = this.far;
this._cullingVolume = new CullingVolume();
this._perspectiveMatrix = new Matrix4();
this._infinitePerspective = new Matrix4();
}
function update(frustum) {
//>>includeStart('debug', pragmas.debug);
if (
!defined(frustum.right) ||
!defined(frustum.left) ||
!defined(frustum.top) ||
!defined(frustum.bottom) ||
!defined(frustum.near) ||
!defined(frustum.far)
) {
throw new DeveloperError(
"right, left, top, bottom, near, or far parameters are not set.",
);
}
//>>includeEnd('debug');
const { top, bottom, right, left, near, far } = frustum;
const changed =
top !== frustum._top ||
bottom !== frustum._bottom ||
left !== frustum._left ||
right !== frustum._right ||
near !== frustum._near ||
far !== frustum._far;
if (!changed) {
return;
}
//>>includeStart('debug', pragmas.debug);
if (frustum.near <= 0 || frustum.near > frustum.far) {
throw new DeveloperError(
"near must be greater than zero and less than far.",
);
}
//>>includeEnd('debug');
frustum._left = left;
frustum._right = right;
frustum._top = top;
frustum._bottom = bottom;
frustum._near = near;
frustum._far = far;
frustum._perspectiveMatrix = Matrix4.computePerspectiveOffCenter(
left,
right,
bottom,
top,
near,
far,
frustum._perspectiveMatrix,
);
frustum._infinitePerspective = Matrix4.computeInfinitePerspectiveOffCenter(
left,
right,
bottom,
top,
near,
frustum._infinitePerspective,
);
}
Object.defineProperties(PerspectiveOffCenterFrustum.prototype, {
/**
* Gets the perspective projection matrix computed from the view frustum.
* The projection matrix will be recomputed if any frustum parameters have changed.
*
* @memberof PerspectiveOffCenterFrustum.prototype
* @type {Matrix4}
* @readonly
*
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
*/
projectionMatrix: {
get: function () {
update(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(this);
return this._infinitePerspective;
},
},
});
const getPlanesRight = new Cartesian3();
const getPlanesNearCenter = new Cartesian3();
const getPlanesFarCenter = new Cartesian3();
const getPlanesNormal = new 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.
* const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
* const intersect = cullingVolume.computeVisibility(boundingVolume);
*/
PerspectiveOffCenterFrustum.prototype.computeCullingVolume = function (
position,
direction,
up,
) {
//>>includeStart('debug', pragmas.debug);
if (!defined(position)) {
throw new DeveloperError("position is required.");
}
if (!defined(direction)) {
throw new DeveloperError("direction is required.");
}
if (!defined(up)) {
throw new DeveloperError("up is required.");
}
//>>includeEnd('debug');
const planes = this._cullingVolume.planes;
const t = this.top;
const b = this.bottom;
const r = this.right;
const l = this.left;
const n = this.near;
const f = this.far;
const right = Cartesian3.cross(direction, up, getPlanesRight);
const nearCenter = getPlanesNearCenter;
Cartesian3.multiplyByScalar(direction, n, nearCenter);
Cartesian3.add(position, nearCenter, nearCenter);
const farCenter = getPlanesFarCenter;
Cartesian3.multiplyByScalar(direction, f, farCenter);
Cartesian3.add(position, farCenter, farCenter);
const normal = getPlanesNormal;
//Left plane computation
Cartesian3.multiplyByScalar(right, l, normal);
Cartesian3.add(nearCenter, normal, normal);
Cartesian3.subtract(normal, position, normal);
Cartesian3.normalize(normal, normal);
Cartesian3.cross(normal, up, normal);
Cartesian3.normalize(normal, normal);
let plane = planes[0];
if (!defined(plane)) {
plane = planes[0] = new Cartesian4();
}
plane.x = normal.x;
plane.y = normal.y;
plane.z = normal.z;
plane.w = -Cartesian3.dot(normal, position);
//Right plane computation
Cartesian3.multiplyByScalar(right, r, normal);
Cartesian3.add(nearCenter, normal, normal);
Cartesian3.subtract(normal, position, normal);
Cartesian3.cross(up, normal, normal);
Cartesian3.normalize(normal, normal);
plane = planes[1];
if (!defined(plane)) {
plane = planes[1] = new Cartesian4();
}
plane.x = normal.x;
plane.y = normal.y;
plane.z = normal.z;
plane.w = -Cartesian3.dot(normal, position);
//Bottom plane computation
Cartesian3.multiplyByScalar(up, b, normal);
Cartesian3.add(nearCenter, normal, normal);
Cartesian3.subtract(normal, position, normal);
Cartesian3.cross(right, normal, normal);
Cartesian3.normalize(normal, normal);
plane = planes[2];
if (!defined(plane)) {
plane = planes[2] = new Cartesian4();
}
plane.x = normal.x;
plane.y = normal.y;
plane.z = normal.z;
plane.w = -Cartesian3.dot(normal, position);
//Top plane computation
Cartesian3.multiplyByScalar(up, t, normal);
Cartesian3.add(nearCenter, normal, normal);
Cartesian3.subtract(normal, position, normal);
Cartesian3.cross(normal, right, normal);
Cartesian3.normalize(normal, normal);
plane = planes[3];
if (!defined(plane)) {
plane = planes[3] = new Cartesian4();
}
plane.x = normal.x;
plane.y = normal.y;
plane.z = normal.z;
plane.w = -Cartesian3.dot(normal, position);
//Near plane computation
plane = planes[4];
if (!defined(plane)) {
plane = planes[4] = new Cartesian4();
}
plane.x = direction.x;
plane.y = direction.y;
plane.z = direction.z;
plane.w = -Cartesian3.dot(direction, nearCenter);
//Far plane computation
Cartesian3.negate(direction, normal);
plane = planes[5];
if (!defined(plane)) {
plane = planes[5] = new Cartesian4();
}
plane.x = normal.x;
plane.y = normal.y;
plane.z = normal.z;
plane.w = -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.
* const 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.
* const position = camera.position;
* const direction = camera.direction;
* const toCenter = Cesium.Cartesian3.subtract(primitive.boundingVolume.center, position, new Cesium.Cartesian3()); // vector from camera to a primitive
* const toCenterProj = Cesium.Cartesian3.multiplyByScalar(direction, Cesium.Cartesian3.dot(direction, toCenter), new Cesium.Cartesian3()); // project vector onto camera direction vector
* const distance = Cesium.Cartesian3.magnitude(toCenterProj);
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cesium.Cartesian2());
*/
PerspectiveOffCenterFrustum.prototype.getPixelDimensions = function (
drawingBufferWidth,
drawingBufferHeight,
distance,
pixelRatio,
result,
) {
update(this);
//>>includeStart('debug', pragmas.debug);
if (!defined(drawingBufferWidth) || !defined(drawingBufferHeight)) {
throw new DeveloperError(
"Both drawingBufferWidth and drawingBufferHeight are required.",
);
}
if (drawingBufferWidth <= 0) {
throw new DeveloperError("drawingBufferWidth must be greater than zero.");
}
if (drawingBufferHeight <= 0) {
throw new DeveloperError("drawingBufferHeight must be greater than zero.");
}
Iif (!defined(distance)) {
throw new DeveloperError("distance is required.");
}
if (!defined(pixelRatio)) {
throw new DeveloperError("pixelRatio is required");
}
if (pixelRatio <= 0) {
throw new DeveloperError("pixelRatio must be greater than zero.");
}
Iif (!defined(result)) {
throw new DeveloperError("A result object is required.");
}
//>>includeEnd('debug');
const inverseNear = 1.0 / this.near;
let tanTheta = this.top * inverseNear;
const pixelHeight =
(2.0 * pixelRatio * distance * tanTheta) / drawingBufferHeight;
tanTheta = this.right * inverseNear;
const 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(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(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(other) &&
other instanceof PerspectiveOffCenterFrustum &&
CesiumMath.equalsEpsilon(
this.right,
other.right,
relativeEpsilon,
absoluteEpsilon,
) &&
CesiumMath.equalsEpsilon(
this.left,
other.left,
relativeEpsilon,
absoluteEpsilon,
) &&
CesiumMath.equalsEpsilon(
this.top,
other.top,
relativeEpsilon,
absoluteEpsilon,
) &&
CesiumMath.equalsEpsilon(
this.bottom,
other.bottom,
relativeEpsilon,
absoluteEpsilon,
) &&
CesiumMath.equalsEpsilon(
this.near,
other.near,
relativeEpsilon,
absoluteEpsilon,
) &&
CesiumMath.equalsEpsilon(
this.far,
other.far,
relativeEpsilon,
absoluteEpsilon,
))
);
};
export default PerspectiveOffCenterFrustum;
|