Synthetic Camera Model
Suchit Tiwari
Microsoft Corporation (deputed by MBT, Pune)
Internal notes. Learning purposes only.
Author's Contact: Email: srt@suchit-tiwari.org
©Suchit. Supporting software is available upon request in C Code & executable form.
Just drop me a line.
Introduction
In computer graphics and visualization applications, we need to show three dimensional real-life objects onto the computer screen. Computer screen being 2D, we need to develop some mechanism to ‘reduce’ one extra dimension from the object without causing loss of dimensional information. This particular process of showing a 3D object onto a 2D surface (in general from space S1 onto space S2) is called Projection. There are many different types of projections that are used in various software applications. Figure 1 describes general classification of projections.
 | |
| Figure 1. Hierarchy of Projections. |
The homogeneous co-ordinates and related transformation techniques explained in, say Harrington’s book are good for ‘static’ kind of visualizations. Gaming, virtual reality, walkthrough and special visualization applications require us to us sophisticated projection mechanisms. We shall use a mathematical technique, which uses world coordinates instead of homogeneous coordinates. The technique is very useful and handy in many computer graphics applications. So let’s get started with some of mathematical preliminaries.
Mathematics behind scenes
Coordinate systems are of fundamental importance in any modeling and scientific problem solving. Along with straight coordinate systems, curvilinear coordinates also find many important applications including soft object animations. We shall be concerned with straight coordinate systems for this article. We shall call the main reference coordinate system as
World Coordinate System (WCS). In our work, we shall give due respect to WCS. In other words, all objects, scenes and camera (viewpoint) will be represented in terms of coordinates of WCS. For solving complex problems like designing framework of a space shuttle, inner mechanism of an engine, and so forth, the WCS only is not adequate. In such cases
User Coordinate System (UCS) is used. UCS is a transformed version of WCS and vice versa. The intimate relationship between WCS and UCS is very useful in modeling and visualizations. Figure 2 shows a simulation screen capture.
 | |
| Figure 2. World & User Coordinate Systems. |
The WCS is represented with axes. A sphere is situated at its origin. Another object is cylinder, which traverses a helix (shown from top view in the diagram). Cylinder has been shown in all of its instances as it moves along the helix. Observe another coordinate system at the base of the cylinder. This coordinate system is UCS, represented with axes. What is so exciting about this technique is the fact that the cylinder has been generated in UCS and then project into WCS. Otherwise generating an equation of a cylinder, which lies on the path of helix, would have proven to be a terrible task, though not impossible. Here we are taking advantage of inter-coordinate system transformations. Let’s now study a formal general case.
Given WCS represented with X, Y, Z and UCS represented with X’, Y’, and Z’; we are interested in learning their relationship. UCS is located at with respect to WCS and is oriented such that X’, Y’ and Z’ form specific angles with principal axes. Either these angles or their Direction Cosines must be known. Refer to figure 3.
 | |
| Figure 3. UCS with respect to WCS. |
The UCS can be located anywhere in a 3-dimensional space with reference to WCS. It many also be oriented in any direction with respect to WCS. Let the direction cosines of X’, Y’ and Z’ with respect to X, Y, and Z are ,, and respectively. The using following sets of equations, we can determine point transformations between these coordinate systems.
A given point from UCS appears to be in WCS. Their relationship is:
x = l1 * x’ + l2 * y’ + l3 * z’ + Xo
y = m1 * x’ + m2 * y’ + m3 * z’ + Yo . . . . Equation (1.1)
z = n1 * x’ + n2 * y’ + n3 * z’ + Zo
Using equation 1.1, we can transform coordinates of points from user coordinate system into the world coordinate system. This set of equations is useful when we are constructing objects in the user coordinate system and we want them to be included in WCS finally. CAD systems use this technique when they provide feature commands like “ucs” or “wcs”. Now to transform any point from WCS into the UCS point , following set of equations is used.
x’ = l1 * (x-Xo) + m1 * (y-Yo) + n1 * (z-Zo)
y’ = l2 * (x-Xo) + m2 * (y-Yo) + n2 * (z-Zo) . . . Equation (1.2)
z’ = l3 * (x-Xo) + m3 * (y-Yo) + n3 * (z-Zo)
This set of equations is very useful when we are dealing with modeling and visualization problems in 3D computer graphics. In its most general form, the technique of modeling complex objects using UCS and WCS tools looks something like this: Model complex objects or special cases of simple objects in UCS; collect vertex information for all such modeled objects; understand the “edge-connectivity” relationship among vertices; transform each vertex into WCS and apply the same connectivity to regenerate object in WCS. With this much of mathematical prelude, let’s now begin developing 3D engine.
Synthetic Camera Model
Viewing a 3D object on 2D computer screen is like viewing a photograph of that object. This photograph is taken with a real camera from a given viewpoint and angle would (ideally should) look the same as that of the projection. Extending this analogy we imagine a virtual camera in 3D space at a given location, facing a specific direction and tilted in a particular angle. This virtual camera is called a synthetic camera. The synthetic camera is moved and transformed within world coordinate system, in which different objects in the scene are present. If we observe carefully the working principle of this model, then we can construct a user coordinate system with the camera at origin. We can compare synthetic camera film with XY plane in the user coordinate system. Look at figure 4.
 | |
| Figure 4. Synthetic Camera in WCS. |
The UCS constructed has its origin at a 3-dimesional point “from”. The axis joining “at” and “from” points defines Z’ axis. The Z’ axis is the direction of viewing. The “up” vector determines how much the camera is tilted. Once we set these attributes of synthetic camera, a photograph is taken by the camera and it is rendered on the computer screen as it is. With this analogy, we can easily see that we need to transform objects from world coordinate system into the camera coordinate system, which is now the user coordinate system. Once transformed, we need to “eliminate” the z-coordinate. Suppose we have transformed a point from world coordinate system into camera coordinate system . Now we need to think about how to plot this on to ‘screen’, which is actually camera’s film parallel to X’Y’ plane. One obvious choice is to neglect z’ altogether and use only . However, instead of losing this additional information about objects if we can make use of it in a more meaningful way, then we might achieve more realism. With this in mind, observe if we plot (with a non-zero z’) then what we get is larger coordinates for smaller values of z’ and smaller values of coordinates for larger values of z’. In other words, the objects that are farther from the “from” point (having larger z’ coordinates) will appear smaller and objects nearer to the “from” point will appear larger. It is a case of a simple one-point perspective projection. The synthetic camera can be transformed by transforming its “from”, “at” and “up” attributes. Using appropriate transforms, we can achieve effects like zoom-in, zoom-out, fly-around, walk-through, revolve, and cinemascope style camera movement.
Generating objects in UCS
This section describes how to create objects using user coordinate systems. We shall use a problem statement of generating a 3-dimensional graph or tree with vertices spaced in 3D and edges connecting various pairs of vertices. One interesting example of such a problem statement in real-life is molecule modeling. Refer to figure 5. It shows a typical bcc molecular grid we want to model. The spheres are atoms within molecules and connecting cylinders are atomic bonds.
 | |
| Figure 5. Generating 3D Objects in UCS. |
The atoms are represented and rendered as spheres with radii proportional to their atomic weight or atomic number. The atomic bonds are modeled as cylinders connecting pairs of atoms. The key is to be able to generate such cylinders to connect two atoms. As shown in the figure 5, we construct a user coordinate system with one atom at the origin and other atom defining Z’ axis. Now to construct a user coordinate system, we create Z’ to be a unit vector in the direction from origin-atom to bonded atom. X’ is constructed by taking a cross product of Z’ and Z. Cross product makes sure that X’ is perpendicular to the plane containing Z’. Once X’ and Z’ are computed, Y’ is obtained with a cross product of Z’ and X’ preserving right-handed coordinate system. Note that Z’ is obtained by subtracting coordinates of origin atom from that of the other bonded atom and then dividing them by distance between them. Thus if p1, and p2 were 3-dimesional points describing positions of atoms, and p1 is the origin atom (means bonds starts from p1 to p2) then, Z’= p2-p1, is obtained as structure subtraction of x, y, and z components of each. Also note that since X’, Y’, and Z’ have been computed as unit vectors, they have i, j, k components and that these components define ,, respectively.
References:
- Harrington, Computer Graphics, Tata McGraw Hills.
- Van Dam A., Foley J.D., Fundamentals of Interactive Computer Graphics, Addison Wesley.
- Isaac Victor Kerlow, The Art of 3-D Computer Animation & Imaging, Galgotia Publication.
- Hearn D., Baker P.M., Computer Graphics C Version, Pearson Education.
- Watt A., Watt M., Advanced Animation & Rendering Techniques, Addison Wesley.
|