constructor(fov?: number, aspect?: number)
View sourceCreates a perspective projection value.
The constructor stores fov and aspect as supplied. It does not
validate, clamp, or normalize either value.
Class
ExtendsProjection
Represents the perspective variant of the Projection contract used
by Camera.
This class identifies its variant with ProjectionType.Perspective.
import { Camera, PerspectiveProjection } from '@wimaengine/render-core'
const camera = new Camera(new PerspectiveProjection(Math.PI / 3, 16 / 9))
const matrix = camera.projectionMatrix()constructor(fov?: number, aspect?: number)Creates a perspective projection value.
The constructor stores fov and aspect as supplied. It does not
validate, clamp, or normalize either value.
Numeric projection discriminator for this value.
Default: ProjectionType.Perspective
Full vertical field-of-view angle used by the perspective frustum.
The value is interpreted in radians by
Projection.asProjectionMatrix.
Width-to-height aspect ratio used to size the near-plane frustum.
isPerspective(): booleanReports that this projection uses perspective mapping.
asProjectionMatrix(near: number, far: number): Matrix4Builds a perspective matrix from this projection and clipping distances.
The near-plane bounds are computed as top = near * Math.tan(0.5 * fov),
height = 2 * top, width = aspect * height, and
left = -0.5 * width. The method then calls
PerspectiveProjection.from with
(left, left + width, top, top - height, near, far) and returns its new
matrix. This projection object is not mutated.
from(left: number, right: number, top: number, bottom: number, near: number, far: number, out?: Matrix4): Matrix4Builds a perspective frustum matrix from explicit bounds and clipping distances.
The scale and offset terms are computed as follows:
x = 2 * near / (right - left),
y = 2 * near / (top - bottom),
a = (right + left) / (right - left),
b = (top + bottom) / (top - bottom),
c = -(far + near) / (far - near), and
d = -2 * far * near / (far - near).
The method overwrites all entries of out with those terms and the
perspective constants, then returns out. It performs no bounds or
clipping-distance validation.
serialize(value: PerspectiveProjection): PerspectiveProjectionSerialSerializes a perspective projection’s discriminator and settings.
The returned object always has type: 'perspective' and copies fov and
aspect from value without validating them.
deserialize(value: PerspectiveProjectionSerial, out?: PerspectiveProjection): PerspectiveProjectionDeserializes perspective settings into a projection value.
The method copies value.fov and value.aspect directly. It does not
validate the input or copy its type field. Without out, it creates a
new PerspectiveProjection; with out, it updates and returns that
same object.
validateSerial(value: unknown): value is PerspectiveProjectionSerialChecks whether a value has the serialized perspective shape.
The value must be a non-null object containing type, fov, and
aspect, with type === 'perspective' and both settings having the
number JavaScript type. Extra properties are allowed; numeric values are
not required to be finite or within a projection-specific range.