FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
    Examples \ Tutorials \ Courses & Workshops
 
   
 
 
Examples for Processing (BETA) version 91+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.



Perspective
by REAS <http://reas.com>

Move the mouse left and right to change the field of view (fov). Click to modify the aspect ratio. The perspective() function sets a perspective projection applying foreshortening, making distant objects appear smaller than closer ones. The parameters define a viewing volume with the shape of truncated pyramid. Objects near to the front of the volume appear their actual size, while farther objects appear smaller. This projection simulates the perspective of the world more accurately than orthographic projection. The version of perspective without parameters sets the default perspective and the version with four parameters allows the programmer to set the area precisely.

Created 28 April 2005

   
// Perspective 
// by REAS <http://reas.com> 

 
void setup() 
{ 
  size(200, 200, P3D); 
  noStroke(); 
} 
 
void draw() 
{ 
  lights(); 
  background(204); 
  float cameraY = height/2.0; 
  float fov = mouseX/float(width) * PI/2; 
  float cameraZ = cameraY / tan(fov / 2.0); 
  float aspect = float(width)/float(height); 
  if(mousePressed) { 
    aspect = aspect / 2.0; 
  } 
  perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0); 
  
  translate(width/2+30, height/2, 0); 
  rotateX(-PI/6); 
  rotateY(PI/3 + mouseY/float(height) * PI); 
  box(45); 
  translate(0, 0, -50); 
  box(30); 
} 
 
 







   
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info