Cameras

TCamera is an abstract base class that contains the viewing parameters for a 3D scene to define how 3D objects are projected onto a 2D projection plane. The TCamera class architecture is shown in Figure 214.

TMatrix3DState provides a 3D transformation matrix for the camera. TLinkableCamera provides protocol for linking the camera to a TMatrix3DState and TClipState. See Chapter 19 for more information on TMatrix3DState and TLinkableCamera.


Projection from 3-D to 2-D

3D graphics can have either a perspective or parallel projection onto the 2D viewing plane. Figure 215 shows a perspective projection and a parallel projection. The projectors are the straight lines in the figure that connect points in the scene (A and B) to their corresponding points in the projection plane.


Perspective projection: A center of projection is required, which is the point at which the projectors converge. The size of the projected image depends on the relative distances between the camera, the projection plane, and the 3D scene.

Parallel projection: Only the direction of projection is required.

Concrete camera classes

The concrete camera classes are TPerspectiveCamera and TParallelCamera. TPerspectiveCamera uses a perspective projection and is directly analogous to cameras in the real world. TParallelCamera uses an parallel projection. TParallelCamera provides a camera in which the projectors are parallel and the projected image size is always the same regardless of the distances involved.

The concrete camera constructors take parameters that let you position and orient the camera, and define the viewing distances and clipping planes of the scene. Figure 216 shows the perspective camera, and Figure 217 shows the parallel camera. The elements in these figures are described with the parallel and perspective camera constructors below.



Perspective camera constructors

There are two TPerspectiveCamera constructors of interest.

      TPerspectiveCamera( const TGPoint3D& cameraPosition,
                          const TGPoint3D& referencePoint,
                          const TGPoint3D& upVector,
                          GCoordinate viewDistance,
                          GCoordinate nearPlaneDistance,
                          GCoordinate farPlaneDistance,
                          const TGPoint projectionPoint = TGPoint::kOrigin,
                          const TGRect& cropWindow = TGRect::kInfiniteRect );
      TPerspectiveCamera( const TGPoint3D& cameraPosition,
                          const TGPoint3D& referencePoint,
                          GDegrees twistAngle,
                          GCoordinate viewDistance,
                          GCoordinate nearPlaneDistance,
                          GCoordinate farPlaneDistance,
                          const TGPoint projectionPoint = TGPoint::kOrigin,
                          const TGRect& cropWindow = TGRect::kInfiniteRect );

Parallel camera constructors

There are two
TParallelCamera constructors of interest.

      TParallelCamera( const TGPoint3D& cameraPosition,
                          const TGPoint3D& referencePoint,
                          const TGPoint3D& upVector,
                          GCoordinate viewDistance,
                          GCoordinate nearViewPlaneDistance,
                          GCoordinate farViewPlaneDistance,
                          const TGPoint projectionPoint = TGPoint::kOrigin,
                          const TGRect& cropWindow = TGRect::kInfiniteRect );
      TParallelCamera( const TGPoint3D& cameraPosition,
                          const TGPoint3D& referencePoint,
                          GDegrees twistAngle,
                          GCoordinate viewDistance,
                          GCoordinate nearViewPlaneDistance,
                          GCoordinate farViewPlaneDistance,
                          const TGPoint projectionPoint = TGPoint::kOrigin,
                          const TGRect& cropWindow = TGRect::kInfiniteRect );

Positioning the camera

cameraPosition: A
TGPoint3D that positions the camera in space. The camera position determines how the eye views the scene. The camera position is represented in the figures by the camera.

referencePoint: A TGPoint3D that represents a point in the scene at which the camera points. The reference point is the center of interest.

Orientation and roll

The orientation of the camera refers to whether the camera points up, down, to the left, or to the side. The roll of the camera refers to whether the camera is rotated clockwise or counterclockwise. One constructor lets you determine the orientation and roll by specifying an upVector, the other constructor uses a twistAngle. The projection plane is always parallel to the upVector.

upVector: A TGPoint3D that sets the orientation and roll of the camera. The upVector parameter is defined relative to the y-axis in the world-coordinate system.

twistAngle: A TGPoint3D that sets the orientation and roll of the camera.

Figure 218 shows that if the camera is sitting on the y-axis looking straight up or down, a twist angle of zero is not uniquely defined. In this case, the system chooses an orientation where the up vector is ( 1, 0, 0 ) so the upper edge of the projection plane faces the negative x-axis.


Viewing distances and clipping planes

viewDistance: The distance between the camera and the projection plane.

nearPlaneDistance (perspective cameras only): A GCoordinate value that sets the distance between the camera and the front clipping plane.

nearViewPlaneDistance (parallel cameras only): A GCoordinate value that sets the distance between the camera and the front clipping plane.

farPlaneDistance (perspective cameras only): A GCoordinate value that sets the distance between the camera and the far clipping plane.

farViewPlaneDistance (parallel cameras only): A GCoordinate value that sets the distance between the camera and the far clipping plane.

projectionPoint: A TGPoint that defines the 2D origin. The default is TGPoint::kOrigin, which corresponds to the center of the projection plane.

cropWindow: A TGRect that represents the area of interest. It is analogous to the view finder on a camera. Graphics within the view finder are part of the scene; areas outside the view finder are not part of the scene. The default is TGRect::kInfiniteRect, which corresponds to no cropping.

Default camera settings

A scene bundle has a default perspective camera with the following settings. These are the settings you get when you create a perspective camera by calling the TPerspectiveCamera default constructor.

cameraPosition TGPoint3D( 0.,0., 72*18. )
referencePoint TGPoint3D( 0., 0., 0. )
upVector TGPoint3D( 0., 1., 0. )
viewDistance 72. * 18.
nearPlaneDistance 0.1
farPlaneDistance 2000.0
projectionPoint TGPoint( 0., 0. )
cropWindow TGRect( TGPoint( kInfinity, kInfinity, TGPoint( kInfinity, kInfinity ) )

These default settings center the TGBox3D constructed in the code fragment below as a 2inch cube on the screen when viewed 18 inches away.

    TGBox3D( TGPoint3D( 72., 72., 72. ), TGPoint3D( 72., 72., 72. ) );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker