Eng 591 - VR Programming - Class Outline 9

General Topics: Paths & Motionlinks

Demo:

The demo program looploop.c demonstrates some of the path and motionlink concepts discussed below. Important keys in this demo:
C: Create a new path.
L: Interpolate the path using linear interpolation.
B: Interpolate the path using Bezier interpolation.
S: Interpolate the path using B-spline interpolation.
1 to 9: Follow the path at varying speeds.
0: Stop the path.
V: Toggle path visibility.
D: Delete the path. ( Creating a new path also deletes the old one. )

Paths

A "path" in WorldToolKit is a sequence of position-orientation pairs that can be used to move either the viewpoint or an object is a smooth, regular, predetermined fashion. Paths can be used to move the viewer along a "guided-tour", or to make an object move through the simulation in a special way. There are several important steps to creating and using paths:
  1. Creating a new path. Paths can be created by recording the viewpoint position and orientation, or or they may be loaded in from a file, or they can be created element-by-element from WTpq data. Relevant WTK calls include:

    • WTpath_new creates a new empty path structure.
    • WTpath_record, WTpath_record1, and WTpath_stop are used for recording the viewpoint data to a path.
    • WTpath_load loads a path in from a file ( created using a text editor or by using WTpath_save to save a pre-existing path. )
    • WTpathelement_new creates a new path element from a WTpq.
    • WTpathelement_insert and WTpathelement_append add pathelements into ( or at the end of ) an existing path.

  2. Manipulating an existing path. Once a path has been created, there are several things that can be done to modify it. Paths can be copied and deleted, markers can be placed to make the path visible, various path parameters can be adjusted, and the path can be set to a finer resolution by interpolating new points in between the existing path elements.. Relevant WTK calls include:

    • WTpath_copy copies a path.
    • WTpath_delete deletes a path.
    • WTpath_setmarker defines a geometry to be used to mark the location of the path.
    • WTpath_setvisibility is used to determine whether or not the markers are visible.
    • WTpath_setmode determines whether a path plays only once or continuously, and whether it plays in a single direction or oscillates from one end of the path to the other.
    • WTpath_setdirection determines whether a path plays forward or backwards.
    • WTpath_setplayspeed controls how fast the path is played.
    • WTpath_interpolate is used to add new points into an existing path, thereby refining the resolution. The interpolation can be linear, B-spline, or Bezier. B-spline produces the smoothest path, but does not guarantee that the new path will pass through the original points. Bezier produces a smooth path that includes the original points.

  3. Playing a path. "Playing a path" causes it to step from one position-orientation pair to another. In order for this to have any effect on a simulation, it is necessary to attach either an object or the viewpoint to the path, using a motionlink as discussed below. When this is done, then "playing the path" will cause the object ( or viewpoint ) to move through space according to the data in the path. I.e. the object or viewpoint "follows" the path. Relevant WTK calls include:
    • WTpath_play plays the path, according to the parameters set by WTpath_setmode.
    • WTpath_play1 causes the path to take a single step, to the next pathelement.
    • WTpath_stop stops a playing path.
    • WTpath_isplaying and WTpath_isrecording indicate whether a path is currently playing or recording, respectively.
    • WTpath_seek can be used to move a path to a particular element.

MotionLinks

Motionlinks attach a source of motion information with a target that can be moved. The source can either be a sensor ( such as a mouse or head tracker ) or a path ( as discussed above. ) The target can be either the viewpoint or a movable object ( in the form of a movable node, a transform node, or a nodepath, the latter of which will be discussed later. ) The primary WTK functions used with motionlinks include:
  • WTmotionlink_new creates a new link between a given source and target.
  • WTmotionlink_delete deletes an existing motionlink.
  • WTmotionlink_disable and WTmotionlink_enable can be used to temporarily inhibit the source from affecting the target, and then resume normal link behavior.
  • WTmotionlink_addconstraint can be used to limit the allowable motion of the target. For example, the viewpoint could be motionlinked to the mouse, but constrained so that the Y component always remains within a given range.
  • It is also possible to set particular reference frames for motionlinks, both for the motion itself and for the constraints ( which may be different reference frames. )
  • Two examples from the looploop.c demo program follow. The first connects the mouse activity to the viewpoint, and the second connects the viewpoint to a path:
           WTmotionlink_new( Mouse, Viewpoint, WTSOURCE_SENSOR,
                WTTARGET_VIEWPOINT );

           WTmotionlink_new( path, Viewpoint, WTSOURCE_PATH,
                WTTARGET_VIEWPOINT );

Exercise:

Add path functionality to your project.