Static p5_sys::global::perspective[][src]

pub static perspective: PerspectiveInternalType
Expand description

Sets a perspective projection for the camera in a 3D sketch. This projection represents depth through foreshortening: objects that are close to the camera appear their actual size while those that are further away from the camera appear smaller. The parameters to this function define the viewing frustum (the truncated pyramid within which objects are seen by the camera) through vertical field of view, aspect ratio (usually width/height), and near and far clipping planes.

When called with no arguments, the defaults provided are equivalent to perspective(PI/3.0, width/height, eyeZ/10.0, eyeZ10.0), where eyeZ is equal to ((height/2.0) / tan(PI60.0/360.0));

Examples

//drag the mouse to look around!
function setup() {
  createCanvas(100, 100, WEBGL);
  perspective(PI / 3.0, width / height, 0.1, 500);
}
function draw() {
  background(200);
  orbitControl();
  normalMaterial();

  rotateX(-0.3);
  rotateY(-0.2);
  translate(0, 0, -50);

  push();
  translate(-15, 0, sin(frameCount / 30) * 95);
  box(30);
  pop();
  push();
  translate(15, 0, sin(frameCount / 30 + PI) * 95);
  box(30);
  pop();
}

Parameters

fovy? camera frustum vertical field of view, from bottom to top of view, in angleMode units

aspect? camera frustum aspect ratio

near? frustum near plane length

far? frustum far plane length