VIEW_CAMERA(3G)
NAME
view_camera − define 3d viewing transformation matrix using camera model
SYNOPSIS
C Syntax:
void view_camera(fildes,camera);
int fildes;
camera_arg ∗camera;
FORTRAN77 Syntax:
subroutine view_camera(fildes,camera)
integer∗4 fildes
real camera(13)
Pascal Syntax:
procedure view_camera(fildes:integer;var camera:camera_arg);
DESCRIPTION
Input Parameters
fildes Integer file descriptor returned by gopen when an I/O path to a graphics device is opened.
camera Structure, record, or array that defines the camera model orientation and contains the following individual elements:
camera position − 3d world coordinates of camera.
C and Pascal: camera.camx, camera.camy, camera.camz
FORTRAN:camera(CAM_CAMX), camera(CAM_CAMY), camera(CAM_CAMZ)
reference position − 3d world coordinates of center of interest.
C and Pascal: camera.refx, camera.refy, camera.refz
FORTRAN:camera(CAM_REFX), camera(CAM_REFY), camera(CAM_REFZ)
field of view − angular field of view in degrees
C and Pascal: camera.field_of_view
FORTRAN:camera(CAM_FIELD_OV)
clipping planes − front and back clipping planes in world coordinates. If both planes are equal, the front plane is set to be very close to the camera and the back plane is set to be far away. If the front is set behind the camera position, it is changed to be just in front of the camera.
C and Pascal: camera.front, camera.back
FORTRAN:camera(CAM_FRONT), camera(CAM_BACK)
camera up vector − 3d world coordinates vector from camera bottom to camera top. This vector is projected onto the plane that is normal to the vector from the camera to the reference position.
C and Pascal: camera.upx, camera.upy, camera.upz
FORTRAN:camera(CAM_UPX), camera(CAM_UPY), camera(CAM_UPZ)
camera projection type − either CAM_PERSPECTIVE or CAM_PARALLEL
C and Pascal: camera.projection
FORTRAN:camera(CAM_PROJECTION)
Discussion
This function is used to define a new viewing transformation matrix with a simple 3-dimensional camera model. This camera view is mapped into the current view_port in a nondistorted fashion. Subsequent calls to view_port recalculate the viewing transformation matrix using the camera view established by this call until another Starbase function establishes a new viewing transformation.
The viewing transformation matrix is the world-to-device coordinate transformation, and should include all user defined non-linear transformations such as perspective. Modelling transformations that affect objects and not the view, such as object translations, rotations, uniform scaling, etc., should appear in modelling matrices pushed on the matrix stack.
If this function is called when the device is not in MODEL_XFORM mode, the matrix stack is flushed since old transformations based on the viewing transformation are invalidated. If this function is called when the device is in the MODEL_XFORM mode, the viewing matrix (at the bottom of the matrix stack) is changed without changing any of the matrices in the rest of the stack.
A viewing transformation matrix based on the camera data in the structure/record/array passed in to view_camera, is calculated. The camera model is really quite simple; the transformation is set up to look from the camera position, to the reference position. The camera geometry is defined by the angular field of view of the camera in degrees (typically 60 degrees). In parallel projections, this angle is only accurate in the plane of the reference position. Changing this value is akin to zooming in or out with a real camera. The camera front and back are the distances in world coordinates to the front and back clipping planes, relative to the reference position, along the direction vector (from camera to reference position). These values reset the values that were in effect from clip_depth or the last view_camera. They also reset the values of the depth_cue_range. The camera up vector determines the orientation of the camera, i.e., which direction the top of the camera points. The camera itself is aimed in the direction established by the vector from the camera position to the reference position. Finally the type of projection used by the camera is determined by the camera projection type.
If camera.projection = CAM_PERSPECTIVE, a perspective projection is used; if camera.projection = CAM_PARALLEL, a parallel projection is used. The view_camera function assumes a left-handed world coordinate system. If this is not the case, then simply call the view_matrix3d function right after calling the view_camera function with a matrix that is identity except that the z-scale term is -1, and the mode set to PRE_CONCAT_VW.
view_camera also sets the viewpoint used for specular light sources. If the viewpoint is currently set to be positional, the viewpoint is set to be the camera position. If the viewpoint is directional, the viewpoint vector is set to be the vector from the reference position to the camera position. If the projection is perspective (camera.projection = CAM_PERSPECTIVE) and the viewpoint is directional, this function sets the positional viewpoint first, then sets the directional viewpoint as specified above. This ensures that back culling works correctly (see hidden_surface).
A simple example further explains: To view a unit cube centered at −5,0,−10 from the positive z direction(left-handed coordinates) and slightly above in the y direction, the following call to view_camera would work:
camera_arg camera;
| camera.back=2.0; | camera.front=-2.0; | camera.upx=0.0; |
| camera.camx=-5.0; | camera.refx=-5.0; | camera.upy=1.0; |
| camera.camy=1.0; | camera.refy=0.0; | camera.upz=0.0; |
| camera.camz=-7.0; | camera.refz=-10.0; |
camera.field_of_view=60.0;
camera.projection = CAM_PERSPECTIVE;
view_camera(fildes,&camera);
draw_cube();
The coordinate systems used by Starbase can be conceptually defined as follows:
• User points are assumed to be defined in modelling coordinates. These points are transformed into world coordinates using a matrix called the modelling transformation matrix (if any matrices have been pushed on the stack). World coordinates are used to perform any rendering calculations needed.
• Next, the world coordinates are transformed to device coordinates by the viewing transformation matrix, which is usually the concatenation of user-defined viewing transformations and the vdc-to-device transformation matrix. When a device is opened, the viewing transformation matrix is simply the vdc-to-device coordinate transformation matrix.
Use matrix stack manipulation functions to place modelling transformation matrices on the matrix stack. Use view_camera, view_matrix, view_volume, or view_window to set viewing transformations.
• If a graphics device has been opened in MODEL_XFORM mode, the modelling transformation cannot be combined with the viewing transformation because special rendering calculations such as shading may be needed after the modelling-to-world-coordinate transformation. Therefore, matrices pushed on the stack are left undisturbed and all transformations from modelling coordinates to device coordinates are processed in two steps: modelling to world coordinates, followed by world to device coordinates.
• If a graphics device is not in MODEL_XFORM mode, the modelling and viewing transformations can be combined. Thus, the current viewing transformation matrix is post-concatenated to modelling matrices placed on the matrix stack, and subsequent output primitives are transformed, using only the top matrix on the matrix stack.
DEFAULTS
After gopen or a call to flush_matrices, the current viewing transformation matrix is the vdc-to-device units transformation matrix.
SEE ALSO
flush_matrices(3G), gopen(3G), hidden_surface(3G), vdc_extent(3G), view_matrix(3G), view_port(3G), view_window(3G), viewpoint(3G), Starbase Graphics Techniques.
Hewlett-Packard Company — May 11, 2021