3D Graphics Programming with QuickDraw 3D
TQ3CameraObject
, which is a type of shape object.QuickDraw3D defines three types of cameras:
TQ3CameraData
data structure.
typedef struct TQ3CameraData { TQ3CameraPlacement placement; TQ3CameraRange range; TQ3CameraViewPort viewPort; } TQ3CameraData;These fields specify the location and orientation of the camera, the visible range of interest, and the camera's view port and projection method. The following sections explain these concepts in greater detail.
Because a camera defines a point of view onto a model,
the camera location is also called the eye point.<8bat>u
Figure 9-1 A camera's placement
In QuickDraw3D, you specify a camera's placement by filling in the fields of a camera placement structure, defined by the TQ3CameraPlacement
data type.
typedef struct TQ3CameraPlacement { TQ3Point3D cameraLocation; TQ3Point3D pointOfInterest; TQ3Vector3D upVector; } TQ3CameraPlacement;See "Camera Placement Structure" on page 9-17 for complete information about the camera placement structure.
Figure 9-2 The hither and yon planes
The hither and yon planes are sometimes called
the near and far planes, respectively.<8bat>u
The extent between the hither and yon planes of a camera is the camera range, defined by the TQ3CameraRange
data structure.
typedef struct TQ3CameraRange { float hither; float yon; } TQ3CameraRange;The clipping planes are specified by distances along the viewing direction from the camera location. The distance to the yon plane should always be greater than the distance to the hither plane, and the distance to the hither plane should always be greater than 0.0.
Currently, QuickDraw3D provides only normal view planes, where the view plane is perpendicular to the viewing direction.<8bat>u
Figure 9-3 illustrates a parallel projection of an object. Notice that, because the projectors are parallel, the size of the two-dimensional image corresponds exactly to the size of the three-dimensional object being projected, no matter where the view plane is located. As a result, you do not need to specify the location of the view plane when using parallel projections. See "Orthographic Cameras" on page 9-11 for details on how to specify a parallel projection.
Figure 9-3 A parallel projection of an object
Figure 9-4 illustrates a perspective projection of an object. As you can see, the location of the view plane is very important in a perspective projection. When the view plane is close to the camera, the projectors are close together and the image they create is small. Conversely, when the view plane is farther away from the camera, the projectors are farther apart and the image they create is larger. Similarly, no matter where the view plane is located, the size of the projected image of an object is inversely proportional to the distance of the object from the view plane. Objects farther away from the view plane appear smaller than objects of the same size closer to the view plane. This effect is perspective foreshortening.
Figure 9-4 A perspective projection of an object
When using perspective projection, you therefore need to specify the location of the view plane. QuickDraw3D provides two types of perspective cameras, which specify the location of the view plane in different ways. See "View Plane Cameras" on page 9-13 and "Aspect Ratio Cameras" on page 9-15 for complete details on these two types of perspective cameras.
A camera view port is the rectangular portion of the view plane that is to be mapped into the area specified by the current draw context. A draw context
is usually just a window, so the view port defines the portion of the view
plane that appears in the window. By default, a camera's view port is the
entire square portion of the view plane that is bounded by the view
volume (either a view box, for parallel projections, or a view frustum, for perspective projections). Figure 9-5 shows the default camera view port
for a perspective camera.
Figure 9-5 The default camera view port
You can select a smaller portion of the view plane by filling in a camera view port structure, defined by the TQ3CameraViewPort
data type.
typedef struct TQ3CameraViewPort { TQ3Point2D origin; float width; float height; } TQ3CameraViewPort;For example, to display only the right side of the view plane, you would set the
origin
field to the point (0, 1), the width
field to the value 1.0, and the height
field to the value 2.0.The image displayed in a draw context is not necessarily the image drawn on the view port. The view port image is scaled to fit into the draw context pane and then clipped with the draw context mask. See the chapter "Draw Context Objects" for information about draw context panes and masks, and for further details on the relationship between a view port and a draw context.<8bat>u
The two most common types of orthographic projection are isometric projection and elevation projection. An isometric projection is an orthographic projection in which the viewing direction makes equal angles with each of the three principal axes of an object. An elevation projection is an orthographic projection in which the view plane is perpendicular to one of the principal axes of the object being projected. Figure 9-6 shows isometric and elevation projections of an object.
Figure 9-6 Isometric and elevation projections
The view volume associated with an orthographic camera is determined by a box aligned with the viewing direction, as shown in Figure 9-7. To specify the box, you provide the left side, top side, right side, and bottom side. The values you use to specify these sides are relative to the camera coordinate system defined by the camera location and the viewing direction. The box defines the four horizontal and vertical clipping planes.
Figure 9-7 An orthographic camera
See "Orthographic Camera Data Structure" on page 9-20 for details on the data you need to provide to define an orthographic camera. See "Managing Orthographic Cameras," beginning on page 9-29 for a description of the routines you can use to create and manipulate orthographic cameras.
The view frustum associated with a view plane camera is determined by a view plane (located at a specified distance from the camera) and the rectangular cross section of an object, as shown in Figure 9-8. The point at which the camera vector intersects the view plane defines the origin of the view plane coordinate system. You specify a rectangular cross section of an object by specifying its center (in the view plane coordinate system) and the half-width and half-height of the cross section. In Figure 9-8, the center of the cross section is the point (cx, cy), and the half-width and half-height are the distances dx and dy, respectively.
Figure 9-8 A view plane camera
See "View Plane Camera Data Structure" on page 9-20 for complete details on the data you need to provide to define a view plane camera. See "Managing View Plane Cameras," beginning on page 9-35 for a description of the routines you can use to create and manipulate view plane cameras.
Figure 9-9 An aspect ratio camera
The orientation of the field of view is determined by the specified aspect ratio. If the aspect ratio is greater than 1.0, the field of view is vertical. If the aspect ratio is less than 1.0, the field of view is horizontal. In general, to avoid distortion, the aspect ratio should be the same as the aspect ratio of the camera's view port.
You can easily see that as the field of view increases, the view plane must move closer to camera location for the view port to fit within the field of view, in which case the image size decreases (because of perspective foreshortening). Conversely, as the field of view decreases, the view plane must move away from the camera location, and the image size increases.
Note that you can always find a view plane camera that is projectively identical to any aspect ratio camera. (The converse is not true: it's not always possible to find an aspect ratio camera that is projectively identical to an arbitrary view plane camera.) Consider the aspect ratio camera shown in Figure 9-10. It's easy to specify a view plane camera that creates the same image as that aspect ratio camera. To do this, set the center of the cross section (cx, cy) to be the origin (0, 0), and set the half-width dx to be the quantity d tan(a/2), where d is the distance from the camera to the view plane and a is the horizontal field of view. (The half-angle applies to the smaller of the two view port dimensions.)
Figure 9-10 The relation between aspect ratio cameras and view plane cameras
See "Aspect Ratio Camera Data Structure" on page 9-21 for more details on the data you need to provide to define an aspect ratio camera. See "Managing Aspect Ratio Cameras," beginning on page 9-43 for a description of the routines you can use to create and manipulate aspect ratio cameras.
Let us know what you think of these prototype pages.
Generated with Harlequin WebMaker