Reference camera()

camera()

Sets the position and orientation of the current camera in a 3D sketch.

camera() allows objects to be viewed from different angles. It has nine parameters that are all optional.

The first three parameters, x, y, and z, are the coordinates of the camera’s position. For example, calling camera(0, 0, 0) places the camera at the origin (0, 0, 0). By default, the camera is placed at (0, 0, 800).

The next three parameters, centerX, centerY, and centerZ are the coordinates of the point where the camera faces. For example, calling camera(0, 0, 0, 10, 20, 30) places the camera at the origin (0, 0, 0) and points it at (10, 20, 30). By default, the camera points at the origin (0, 0, 0).

The last three parameters, upX, upY, and upZ are the components of the "up" vector. The "up" vector orients the camera’s y-axis. For example, calling camera(0, 0, 0, 10, 20, 30, 0, -1, 0) places the camera at the origin (0, 0, 0), points it at (10, 20, 30), and sets the "up" vector to (0, -1, 0) which is like holding it upside-down. By default, the "up" vector is (0, 1, 0).

Note: camera() can only be used in WebGL mode.

Examples

Syntax

camera([x], [y], [z], [centerX], [centerY], [centerZ], [upX], [upY], [upZ])

Parameters

x
Number:

x-coordinate of the camera. Defaults to 0.

y
Number:

y-coordinate of the camera. Defaults to 0.

z
Number:

z-coordinate of the camera. Defaults to 800.

centerX
Number:

x-coordinate of the point the camera faces. Defaults to 0.

centerY
Number:

y-coordinate of the point the camera faces. Defaults to 0.

centerZ
Number:

z-coordinate of the point the camera faces. Defaults to 0.

upX
Number:

x-component of the camera’s "up" vector. Defaults to 0.

upY
Number:

y-component of the camera’s "up" vector. Defaults to 1.

upZ
Number:

z-component of the camera’s "up" vector. Defaults to 0.

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