Class: PerspectiveFrustum

PerspectiveFrustum

new PerspectiveFrustum(options)

The viewing frustum is defined by 6 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/camera position.

Name Type Description
options Object 可选

An object with the following properties:

Name Type Default Description
fov Number 可选

The angle of the field of view (FOV), in radians.

aspectRatio Number 可选

The aspect ratio of the frustum's width to it's height.

near Number 1.0 可选

The distance of the near plane.

far Number 500000000.0 可选

The distance of the far plane.

xOffset Number 0.0 可选

The offset in the x direction.

yOffset Number 0.0 可选

The offset in the y direction.

See:
Example
var frustum = new SuperMap3D.PerspectiveFrustum({
    fov : SuperMap3D.Math.PI_OVER_THREE,
    aspectRatio : canvas.clientWidth / canvas.clientHeight
    near : 1.0,
    far : 1000.0
});

Members

static isNDCHalfZRange

Indicates if the z range in NDC space is 0..1 (value: true) or -1..1 (value: false)

static packedLengthNumber

The number of elements used to pack the object into an array.

aspectRatioNumber

The aspect ratio of the frustum's width to it's height.

Default Value:
undefined

farNumber

The distance of the far plane.

Default Value:
500000000.0

fovNumber

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.

Default Value:
undefined

readonly fovyNumber

Gets the angle of the vertical field of view, in radians.

Default Value:
undefined

readonly infiniteProjectionMatrixMatrix4

The perspective projection matrix computed from the view frustum with an infinite far plane.

See:

nearNumber

The distance of the near plane.

Default Value:
1.0

readonly projectionMatrixMatrix4

Gets the perspective projection matrix computed from the view frustum.

See:

xOffsetNumber

Offsets the frustum in the x direction.

Default Value:
0.0

yOffsetNumber

Offsets the frustum in the y direction.

Default Value:
0.0

Methods

static pack(value, array, startingIndex){Array.<Number>}

Stores the provided instance into the provided array.

Name Type Default Description
value PerspectiveFrustum

The value to pack.

array Array.<Number>

The array to pack into.

startingIndex Number 0 可选

The index into the array at which to start packing the elements.

Returns:
Type Description
Array.<Number> The array that was packed into

static unpack(array, startingIndex, result){PerspectiveFrustum}

Retrieves an instance from a packed array.

Name Type Default Description
array Array.<Number>

The packed array.

startingIndex Number 0 可选

The starting index of the element to be unpacked.

result PerspectiveFrustum 可选

The object into which to store the result.

Returns:
Type Description
PerspectiveFrustum The modified result parameter or a new PerspectiveFrustum instance if one was not provided.

clone(result){PerspectiveFrustum}

Returns a duplicate of a PerspectiveFrustum instance.

Name Type Description
result PerspectiveFrustum 可选

The object onto which to store the result.

Returns:
Type Description
PerspectiveFrustum The modified result parameter or a new PerspectiveFrustum instance if one was not provided.

computeCullingVolume(position, direction, up){CullingVolume}

Creates a culling volume for this frustum.

Name Type Description
position Cartesian3

The eye position.

direction Cartesian3

The view direction.

up Cartesian3

The up direction.

Returns:
Type Description
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);

equals(other){Boolean}

Compares the provided PerspectiveFrustum componentwise and returns true if they are equal, false otherwise.

Name Type Description
other PerspectiveFrustum 可选

The right hand side PerspectiveFrustum.

Returns:
Type Description
Boolean true if they are equal, false otherwise.

equalsEpsilon(other, relativeEpsilon, absoluteEpsilon){Boolean}

Compares the provided PerspectiveFrustum componentwise and returns true if they pass an absolute or relative tolerance test, false otherwise.

Name Type Default Description
other PerspectiveFrustum

The right hand side PerspectiveFrustum.

relativeEpsilon Number

The relative epsilon tolerance to use for equality testing.

absoluteEpsilon Number relativeEpsilon 可选

The absolute epsilon tolerance to use for equality testing.

Returns:
Type Description
Boolean true if this and other are within the provided epsilon, false otherwise.

getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, pixelRatio, result){Cartesian2}

Returns the pixel's width and height in meters.

Name Type Description
drawingBufferWidth Number

The width of the drawing buffer.

drawingBufferHeight Number

The height of the drawing buffer.

distance Number

The distance to the near plane in meters.

pixelRatio Number

The scaling factor from pixel space to coordinate space.

result Cartesian2

The object onto which to store the result.

Throws:
  • drawingBufferWidth must be greater than zero.

    Type
    DeveloperError
  • drawingBufferHeight must be greater than zero.

    Type
    DeveloperError
  • pixelRatio must be greater than zero.

    Type
    DeveloperError
Returns:
Type Description
Cartesian2 The modified result parameter or a new instance of Cartesian2 with the pixel's width and height in the x and y properties, respectively.
Examples
// Example 1
// Get the width and height of a pixel.
var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new SuperMap3D.Cartesian2());
// 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 = SuperMap3D.Cartesian3.subtract(primitive.boundingVolume.center, position, new SuperMap3D.Cartesian3());      // vector from camera to a primitive
var toCenterProj = SuperMap3D.Cartesian3.multiplyByScalar(direction, SuperMap3D.Cartesian3.dot(direction, toCenter), new SuperMap3D.Cartesian3()); // project vector onto camera direction vector
var distance = SuperMap3D.Cartesian3.magnitude(toCenterProj);
var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new SuperMap3D.Cartesian2());