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-coordinate of the camera. Defaults to 0.
y-coordinate of the camera. Defaults to 0.
z-coordinate of the camera. Defaults to 800.
x-coordinate of the point the camera faces. Defaults to 0.
y-coordinate of the point the camera faces. Defaults to 0.
z-coordinate of the point the camera faces. Defaults to 0.
x-component of the camera’s "up" vector. Defaults to 0.
y-component of the camera’s "up" vector. Defaults to 1.
z-component of the camera’s "up" vector. Defaults to 0.