<< Chapter < Page | Chapter >> Page > |
A
viewport is a rectangular area of the
display window. To go from the perspective projection plane tothe viewport two steps are taken: (i) transformation into a 2 x
2 window centered in the origin (
normalized device
coordinates ) (ii) mapping the normalized window
onto the viewport. Using the normalized device coordinates, the
clipping operation, that is the elimination of
objects or parts of objects that are not visible through thewindow, becomes trivial.
screenX()
,
screenY()
, and
screenZ()
gives the
X-Y coordinates produced by the viewport transformation and bythe previous operators in the chain of
[link] .
The viewing
frustum is the solid
angle that encompasses the perspective projection, as shown in
[link] . The objects (or their parts)
belonging to the viewing volume are visualized, the remainingparts are subject to clipping. In Processing (and in OpenGL)
the frustum can be defined by positioning the six planes thatdefine it (
frustum()
), or by specification of the
vertical angle, the,
aspect ratio , and the
positions of the front and back planes(
perspective()
). One may ask how the system
removes the hidden faces, i.e., those faces that are masked byother faces in the viewing volume. OpenGL uses the
z-buffer algorithm, which is supported by the graphic accelerators. The
board memory stores a 2D memory area (the z-buffer)corresponding to the pixels of the viewing window, and
containing depth values. Before a polygon gets projected on theviewing window the board checks if the pixels affected by such
polygon have a depth value smaller than the polygon beingdrawn. If this is the case, it means that there is an object that masks the polygon.
Sophisticated geometric transformations are possible by direct
manipulation of the projection and model-view matrices. Thisis possible, in Processing, starting from the unit matrix,
loaded with
resetMatrix()
, and proceeding by
matrix multiplies done with the
applyMatrix()
.
Run and analyze the Processing code
size(200, 200, P3D);
println("Default matrix:"); printMatrix();noFill();
ortho(-width/2, width/2, -height/2, height/2, -100, 100);translate(100, 100, 0);
println("After translation:"); printMatrix();rotateX(atan(1/sqrt(2)));
println("After about-X rotation:"); printMatrix();rotateY(PI/4);
println("After about-Y rotation:"); printMatrix();box(100);
What is visualized and what it the kind of projection
used? How do you interpret the matrices printed out on theconsole? Can one invert the order of rotations?
The wireframe of a cube is visualized in isometric projection. The latter three matrices represent, one afterthe other, the three operations of translation (to center the cube to the window), rotation about the axis, and rotation about the axis. A sequence of two rotations correspond to the product of two rotationmatrices, and the outcome is not order independent (product is not commutative). The product of two rotation matrices correspond to performing the rotation about first, and then the rotation about .
Write a Processing program that performs the oblique projection of a cube.
For example:
size(200, 200, P3D);
float theta = PI/6;float phi = PI/12;
noFill();ortho(-width/2, width/2, -height/2, height/2, -100, 100);
translate(100, 100, 0);applyMatrix(1, 0, - tan(theta), 0,
0, 1, - tan(phi), 0,0, 0, 0, 0,
0, 0, 0, 1);box(100);
Visualize a cube that projects its shadow on the floor, assuming that the light source is atinfinite distance (as it is the case, in practice, for the sun).
We do it similarly to
[link] , but the transformation is
orthographic:
size(200, 200, P3D);
noFill();translate(100, 100, 0);
pushMatrix();rotateY(PI/4); rotateX(PI/3);
box(30);popMatrix();
translate(0, 60, 0); //cast a shadow from infinity (sun)applyMatrix(1, 0, 0, 0,
0, 0, 0, 0,0, 0, 1, 0,
0, 0, 0, 1);fill(150);
pushMatrix();noStroke();
rotateY(PI/4); rotateX(PI/3);box(30);
popMatrix();
Notification Switch
Would you like to follow the 'Media processing in processing' conversation and receive update notifications?