getPixelDimensions

fun getPixelDimensions(drawingBufferWidth: Double, drawingBufferHeight: Double, distance: Double, pixelRatio: Double, result: Cartesian2): Cartesian2(source)

Returns the pixel's width and height in meters.

// Example 1
// Get the width and height of a pixel.
const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, scene.pixelRatio, new 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.
const position = camera.position;
const direction = camera.direction;
const toCenter = Cartesian3.subtract(primitive.boundingVolume.center, position, new Cartesian3()); // vector from camera to a primitive
const toCenterProj = Cartesian3.multiplyByScalar(direction, Cartesian3.dot(direction, toCenter), new Cartesian3()); // project vector onto camera direction vector
const distance = Cartesian3.magnitude(toCenterProj);
const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, scene.pixelRatio, new Cartesian2());

Return

The modified result parameter or a new instance of Cartesian2 with the pixel's width and height in the x and y properties, respectively.

Parameters

drawingBufferWidth

The width of the drawing buffer.

drawingBufferHeight

The height of the drawing buffer.

distance

The distance to the near plane in meters.

pixelRatio

The scaling factor from pixel space to coordinate space.

result

The object onto which to store the result.

See also