Reference ortho()

ortho()

Sets an orthographic projection for the camera.

In an orthographic projection, shapes with the same size always appear the same size, regardless of whether they are near or far from the camera.

myCamera.ortho() changes the camera’s perspective by changing its viewing frustum from a truncated pyramid to a rectangular prism. The frustum is the volume of space that’s visible to the camera. The camera is placed in front of the frustum and views everything within the frustum. myCamera.ortho() has six optional parameters to define the viewing frustum.

The first four parameters, left, right, bottom, and top, set the coordinates of the frustum’s sides, bottom, and top. For example, calling myCamera.ortho(-100, 100, 200, -200) creates a frustum that’s 200 pixels wide and 400 pixels tall. By default, these dimensions are set based on the sketch’s width and height, as in myCamera.ortho(-width / 2, width / 2, -height / 2, height / 2).

The last two parameters, near and far, set the distance of the frustum’s near and far plane from the camera. For example, calling myCamera.ortho(-100, 100, 200, -200, 50, 1000) creates a frustum that’s 200 pixels wide, 400 pixels tall, starts 50 pixels from the camera, and ends 1,000 pixels from the camera. By default, near and far are set to 0 and max(width, height) + 800, respectively.

Examples

Syntax

ortho([left], [right], [bottom], [top], [near], [far])

Parameters

left

x-coordinate of the frustum’s left plane. Defaults to -width / 2.

right

x-coordinate of the frustum’s right plane. Defaults to width / 2.

bottom

y-coordinate of the frustum’s bottom plane. Defaults to height / 2.

top

y-coordinate of the frustum’s top plane. Defaults to -height / 2.

near

z-coordinate of the frustum’s near plane. Defaults to 0.

far

z-coordinate of the frustum’s far plane. Defaults to max(width, height) + 800.

Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/p5.Camera.js and open a pull request!

Related References