Eng 591 - VR Programming - Class Outline 20

General Topics: Viewing Parameters, Viewpoints, & Windows

The material in this handout relates to the different viewing options available in WorldToolKit, and how to adjust relevant viewing parameters. Much of this material is covered in chapters 16, 17, and 2, although not all of those chapters is covered by this handout.

Display & Window Options

On day one of this course we started with a basic VR program, and learned that every WTK program must have a line of the form:
WTuniverse_new( WTDISPLAY_DEFAULT, WTWINDOW_DEFAULT );

However there are other display and window options available besides just the defaults:

  • WTDISPLAY_NOWINDOW creates a display without any windows. In this case windows must be created later in the simulation using other function calls, such as X-Windows Motif calls, MS Windows MFC calls, or WorldToolKit UI ( User Interface ) calls.
  • WTDISPLAY_CRYSTALEYES creates a single full-screen stereo window suitable for use with CrystalEyes glasses.
  • WTWINDOW_STEREO creates a stereo window on systems with hardware support for stereo display, or a split window ( left eye on top, right eye on bottom ) otherwise.
  • WTWINDOW_STEREOVSPLIT creates a stereo split window, regardless of whether the hardware is capable of generating stereo imagery or not.
  • WTWINDOW_INTERLACEODDEVEN ( or EVENODD ) creates a stereo window where the odd ( or even ) scan lines correspond to the left eye image, and the even ( or odd ) lines correspond to the right eye image.
  • WTWINDOW_NOBORDER creates a window with no border. This constant can be bitwise or'ed with any of the other WTWINDOW constants.

Stereo Viewing

In order to produce true stereoscopic viewing, it is necessary to generate separate views for the left and right eyes, with slightly different viewpoints for each eye. The additional work roughly doubles the time required to render a single frame, or halves the framerate, although this may not always be the case. From a hardware standpoint, there are several different methods for generating stereo views:
  • Dual output graphics cards: There are some graphics cards that have multiple monitor connections, making it possible to output two separate images simultaneously. One example is the Diamond FireGL 3000. With this card it is possible to set the resolution to twice a normal setting ( e.g. 2048 x 768 or 1024 x 1536 ), which will cause half the image to be sent to each video output. WorldToolKit recognizes this situation, and if the display type is set to WTWINDOW_STEREO, it will generate the left eye image on one half of the display, and the right eye image on the other.
  • Field Sequential Mode: A normal display mode for most monitors and graphics cards will refresh the entire screen at a rate of 60 Hz. For field sequential stereo, the image is refreshed at 120 Hz, but every other frame is for the left eye, and the alternate frames are for the right eye.The user wears a special pair of LCD ( Liquid Crystal Display ) glasses that block the vision of alternate eyes at the same 120 Hz frequency. These glasses work by applying an electrical current to LCD panels such that the right eye does not see the left eye images and vice versa. This mode requires that both the monitor and the video card be capable of 120 Hz refresh frequencies.
  • Over/Under Mode: This mode is similar to the field sequential mode, except that the video card issues a 60 Hz signal with the left eye image in the top half of the screen and the right eye image in the bottom half of the screen. This video signal is passed through a converter box that adds an extra sync signal, such that the monitor receives a 120 Hz signal with half the vertical resolution of the signal issued by the graphics card. The converter box also issues a signal to LCD shutter glasses, as described above, so that each eye only sees the correct view.
  • Line Sequential Mode, a.k.a. Interlaced Mode: In this mode, every other scan line goes to one eye, and the remaining lines go to the other eye.
  • Split Screen: In this approach, the left eye image appears on the left half of the screen, and the right eye image appears on the right. Because the human eye has a much larger field of view side-to-side than top-to-bottom, the images are also rotated 90 degrees. A special viewing hood presents the correct image to the correct eye in the correct orientation. WTK no longer supports this stereo display mode.

Viewpoints ( Viewing Parameters )

As we have used them up to this point, viewpoints define the position and orientation from which the viewer observes the rendered scene. There are, however, many different viewing parameters that can be adjusted, both for stereoscopic and monoscopic viewing. This section will cover only a few of the more immediately relevant parameters. Students should also check chapter 16 for more information.
  • WTviewpoint_setaspect, WTviewpoint_getaspect: These calls are used to set and determine the aspect ration of the viewpoint, i.e. the relative ratio of height to width. The default ratio is 1.0, which is usually correct. If, however, square objects appear rectangular, or spherical objects appear elliptical, then this ratio can be adjusted to compensate.
  • WTviewpoint_setparallax, WTviewpoint_getparallax: These calls are used to determine the distance between the left and right viewpoint for stereoscopic viewing, in WorldToolKit units. It is important that the parallax be set properly in order to portray effective stereo viewing. For example, if a house is modelled with doorways that are eight units high, and the parallax is set at 10 units, then the house will appear as a small doll house, because only one of the eyes can be placed in the door at a time. On the other hand, if a fly is modeled 100 units high and the parallax is set at the same 10 units, then it will appear to be a very large fly indeed.
  • WTviewpoint_setconvergence, WTviewpoint_getconvergence: These calls are used to adjust the left and right images closer together or farther apart, in terms of actual pixels. These adjustments correct for interpupilary distance in HMDs that do not allow for this physical adjustment.
  • WTviewpoint_setconvdistance, WTviewpoint_getconvdistance: For asymmetric viewpoints, these calls control whether objects appear to recede behind the screen or stick out in front of it.

Windows ( Viewing Parameters )

In addition to the viewing parameters that are configurable for viewpoints, there are also a number of parameters that are configurable on a window by window basis:
  • WTwindow_new is used to create a new window. Besides position and size information, it also takes the same window parameters discussed above.
  • WTwindow_setviewpoint associates a viewpoint ( possibly created with WTviewpoint_new ) with a window. The default viewpoint for a newly created window is NULL, ( unless the window was automatically created by WTuniverse_new, in which case a default viewpoint is also automatically created. )
  • The viewing angle is half the total horizontal viewing angle, given in radians, with a default value of 0.698131 radians ( 40 degrees ). This parameter is set with WTwindow_setviewangle, and works in conjunction with the viewpoint's aspect ratio ( see above ) to determine the angled sides of the viewing frustrum.
  • The hither clipping value and the yon clipping value determine the closest and farthest distances that can be seen in this window. Anything closer or farther than these distances will not be displayed. These values determine the front and back edges of the viewing frustrum respectively.
  • Note: It is tempting to set the hither clipping value to a very small value, and the yon clipping value to a very large value, but this is usually not the best configuration, due to z-buffer problems. Z-buffering is a method for determining which objects are in front of ( and blocking ) which other objects which is a very fast method currently supported by most high speed video cards. In the z-buffering system, there are a number of buffers associated with each pixel on the screen, which are sorted from closest ( low z ) to farthest ( high z ). For each object that might conceivably appear at a given pixel location, the color of its pixel is placed into one of the z-buffers, according to its distance ( between the hither and yon clipping planes. ) However the number of z-buffers available is hardware dependant, and limited to 256 ( 8-bit ), 32768 ( 16-bit ), or 2 million ( 32-bit ). The buffers are exponentially distributed, so if the hither distance is very small, then a large fraction of the available buffers may be used up for near distances. If two objects are closer together in the z-distance than can be distinguished using the available buffers, then flashing may occur, in which the computer can't determine which object is in front of which, and alternates rapidly. The bottom line is that the hither and yon clipping distances should be set as close to each other as possible to yield the best depth resolution, while still not having excessive clipping occur in the simulation. These values are set with WTwindow_sethithervalue and WTwindow_setyonvalue.
  • The eye parameter determines whether the view rendered is for the left eye ( default ) or the right eye. This parameter is not intended for stereo views within a single window - it is intended for stereo situations where separate windows are created for each eye. In this case, both windows are assigned the same viewpoint, but the eye parameter is different for each window.
  • The projection type can be either SYMMETRIC for most situations, or ASYMMETRIC for special situations such as the CAVE.
  • The window background color is normally blue, but can be changed with WTwindow_setbgrgb.

Other Viewpoint Functions

  • WTviewpoint_getposition, WTviewpoint_setposition, WTviewpoint_getorientation, WTviewpoint_setorientation, WTviewpoint_translate, WTviewpoint_rotate, WTviewpoint_move, WTviewpoint_moveto, WTviewpoint_getdirection, WTviewpoint_setdirection can all be used to determine or modify the viewpoint's current position and orientation. Some of these calls make incremental changes, and others set absolute values; Some affect both position and orientation, and others only affect some of the information.
  • The functions listed above modify the viewpoint relative to either the world reference frame or the viewpoints reference frame. There are also functions available ( p. 16-14 ff ) to adjust the viewpoint relative to an arbitrary reference frame. For example, if there was an escalator on a cruise ship that is sailing the ocean, it might be useful to move the viewpoint relative to the cruise ship's reference frame.
  • WTviewpoint_getaxis determines the direction vector ( in world space ) corresponding to one of the three coordinate axes of the viewpoint orientation frame. For example, getting the axis direction of the viewpoint's Z axis would yield a unit vector pointing straight ahead of the user in 3-D world space.
  • WTviewpoint_alignaxis aligns one of the viewpoint's coordinate axes with a direction vector in 3-D space.
  • WTviewpoint_world2local and WTviewpoint_local2world convert 3-D coordinates from the world reference frame to the viewpoint reference frame and vice versa.

Other Window Functions

  • WTwindow_next is used to loop through all the windows in a simulation.
  • WTwindow_setrootnode is used to attach a particular scene graph to a window. One easy way to "portal" is to create multiple scene graphs, and switch which one is attached to the viewing window as appropriate.
  • WTwindow_enable is used to temporarily disable and later re-enable rendering for a particular window. ( WTwindow_isenabled determines whether a given window is enabled or not. )
  • WTwindow_setposition, WTwindow_getposition determine the location of a window on the screen, as well as its size.
  • WTwindow_zoomviewpoint adjusts the viewpoint in a window such that all objects in the scene are visible.
  • WTwindow_zoonviewtonode adjusts the viewpoint such that a particular node ( and all its descendents ) are visible.
  • WTwindow_pickpoly picks a polygon at a particular location within a window ( similar to WTscreen_pickpoly. )
  • WTwindow_getray determines a ray from the viewpoint location through a particular x,y point in a window.
  • WTwindow_projectpoint determines the 2-D point in a window corresponding to a 3-D point in the world. ( Returns FALSE if the 3-D point is not within the viewing angle of the window. )
  • WTwindow_setbgrgb, WTwindow_getbgrgb
  • WTwindow_numpolys
  • WTwindow_loadimage is used to load a texture map as a full-size image in a window. The image may be placed in the background, or in the foreground, or anywhere in between.
  • WTwindow_saveimage captures a screen shot of the window into a data file.
  • WTwindow_newviewport, WTwindow_setviewport, WTwindow_getviewport