CS-460/560, Week 13-A Spring, 1998 R. Eckert 3D VIEWING AND PROJECTION TRANSFORMATIONS Once a 3-D model of a scene has been built and stored, all points in the model must be transformed to the viewing coordinate system. They must then be projected onto a projection plane. The first transformation is called the 3-D viewing transformation, and it converts the world coordinates of each point (xw,yw,zw,) to the viewing coordinates (xv,yv,zv) of the point as seen by a "camera" that is going to "photograph" the scene. (xw,yw,zw) ------------------------> (xv,yv,zv) Viewing transformation The second transformation is called the projection transformation, and it converts the viewing coordinates (xv,yv,zv) of each point to 2-D (xp,yp) coordinates of the projection of the point onto a projection plane. We can think of the projection plane as containing the screen upon which the image is to be displayed. (xv,yv,zv) --------------------------> (xp,yp) Projection transformation There are many possible viewing setups. We are going to choose a simple, 4-parameter viewing setup. While somewhat restricted, this viewing setup will be adequate for most common situations. The following describes the 4-parameter viewing setup (see the diagram): -Choose the viewpoint (camera location) at a distance rho from the world coordinate system origin at azimuthal angle theta and polar angle phi (i.e., spherical coordinates). This viewpoint will be the origin of the viewing coordinate system. Three of the four parameters are rho, theta, and phi. -Choose the viewing coordinate system's zv-axis to point toward the origin of the world coordinate system. (Therefore objects we want to be visible must be close to the origin of the world coordinate system.) -Choose the projection plane perpendicular to the zv-axis at a distance d from the origin of the viewing system. The fourth parameter is d. Obviously rho must be greater than z. -We will eventually perform a perspective projection whose center of projection coincides with the origin of the viewing coordinate system. -Choose the viewing coordinate system's yv-axis to be parallel to the projection of the world coordinate system's zw-axis onto the projection plane. Thus the world coordinate zw-axis defines the "up" direction. -Choose the viewing coordinate system's xv-axis such that the xv-yv-zv- axes form a left-handed coordinate system. In that way objects further from the viewing system's origin will have larger values of zv. -The projection plane coordinate system's origin will be at the intersection point of rho and the projection plane. The xp-yp-axes are the projections of the xv-yv axes on the projection plane. In other words, xp-yp are the same as xv-yv translated a distance d along the zv axis. THE 3-D VIEWING TRANSFORMATION-- In order to derive equations that implement the 3-D viewing transformation, we need to perform a coordinate system transformation that converts xw-yw-zw to xv-yv-zv. The following steps need to be performed: 1. Translate the origin by a distance rho in the direction (theta, phi). (See the following diagram.) In other words, if the origin of the viewing coordinate sytem is at world coordinates (x,y,z), we need to translate the world coordinate system origin by (x,y,z). The homogeneous transformation matrix that implements a translation by (x,y,z) is: | 1 0 0 x | Tgeom = | 0 1 0 y | | 0 0 1 z | | 0 0 0 1 | But using the relationship between coordinate system transformations and geometric transformations, Tcoord(x,y,z) = Tgeom(-x,-y,-z), we get for the first transformation matrix, T1: | 1 0 0 -x | T1 = | 0 1 0 -y | | 0 0 1 -z | | 0 0 0 1 | We can get x, y, and z in terms of rho, theta, and phi by using the relationship between Cartesian and spherical coordinates: x = rho*sin(phi)*cos(theta) y = rho*sin(phi)*sin(theta) z = rho*cos(phi) 2. Rotate by -(90-theta) degrees about the z-axis to bring the new y-axis (y') into the plane of zw and rho. (see the following diagram.) Again we use the relationship between coordinate system rotations and geometric rotations: Tcoord(alpha) = Tgeom(-alpha). Thus our second transformation will be T2 = Rz(90-theta): | cos(90-theta) -sin(90-theta) 0 0 | T2 = | sin(90-theta) cos(90-theta) 0 0 | | 0 0 1 0 | | 0 0 0 1 | 3. Rotate by (180-phi) about the x-axis to point the transformed z-axis (z") toward the origin of the world coordinate system. (See the following diagram.) We once again use the relation ship between geometric and coordinate system rotations: T3 = Rx(phi-180): | 1 0 0 0 | T3 = | 0 cos(phi-180) -sin(phi-180) 0 | | 0 sin(phi-180) cos(phi-180) 0 | | 0 0 0 1 | 4. Finally, we notice that the coordinate system that results from these three transformations has the x-axis pointing in the opposite direction from the desired direction. (This is a consequence of the fact that the world coordinate system is a right-handed system, while the viewing system is supposed to be a left-handed system.) So we need to apply a reflection transformation across the y"-z" plane, which will convert x to -x. The matrix that will implement this transformation is T4: | -1 0 0 0 | T4 = | 0 1 0 0 | | 0 0 1 0 | | 0 0 0 1 | The 3-D viewing transformation matrix (Tv) will be the composite of these four transformation matrices: Tv = T4*T3*T2*T1 If we substitute the matrices given above, perform the multiplications, and make use of some trigonometric identities to simplify the result, we get: | -sin(theta) cos(theta) 0 0 | Tv = | -cos(phi)*cos(theta) -cos(phi)*sin(theta) sin(phi) 0 | | -sin(phi)*cos(theta) -sin(phi)*sin(theta) -cos(phi) rho | | 0 0 0 1 | THE PROJECTION TRANSFORMATION-- If we look down the xv axis at the viewing setup, we get the following diagram: We see that triangle OAP' and OBP are similar. Therefore we can set up the following proportion: yp d ---- = ---- yv zv Solving for yp, we get: yp = (yv*d)/zv The equation for xp can be obtained by applying the same logic to the diagram that results when we look down the yv axis. The result is: xp = (xv*d)/zv