Previous Section: Object Animation

View Animation

In this section you will learn how to animate the view. It is assumed that you have already gone through the steps outlined in the object animation tutorial. From the main menu, select CREATE SCRIPT and then choose View from the posted menu. The object animation window disappears and the view animation window appears in its place. Change the name of the Output file to view.script.

Making the Eye Follow Animation Curves

One simple way to animate the view is to designate a path for the eye to follow, and then orient the view using automatic steering or other methods. Set the source type to Source curve, and type spl_path2 in the corresponding entry box. You will make the eye follow the path that the cone did through the torus. Press the View size button to enter the current view size into the appropriate box. Make sure that the Object center, Object yaw, pitch, roll, Eye point, and Eye yaw, pitch, roll entry boxes are empty or zero-filled. (A good way to delete the contents of an entry box is to click on the box with the left mouse, and then type CTRL-k.) Under Orientation Control, select No rotation. Finally, press OK to create the view script.

Before showing the script be sure to put the MGED display into perspective mode, with a command such as:

mged> set perspective 30
This sets a perspective view with a thirty degree field of view. Perspective views work much better than orthogonal views for animations such as this one in which the eye moves through the model instead of just looking at it. To return to an orthogonal view, use the command:
mged> set perspective -1
On an SGI workstation, the F3 key can be used to toggle the perspective. Now that the perspective is set, go ahead an show the script. The eye should move throught the torus and along the same path that the cone followed before. Since there is no rotation, the view has a yaw, pitch, and roll of 0. Because the model is fairly sparse, you might see a lot of empty space in this animation. To get a better feel for where you're going, you can increase the perspective field of view to 90 degrees or so. (For a funhouse view, try 170 degrees!).

Change the Eye yaw, pitch, and roll field to -90 0 0, recreate the script and show the results. This gives the camera a yaw of -90 degrees, making it face the negative y-axis. Next, change the Eye yaw, pitch, and roll field back to 0 0 0 and select Automatic steering. Re-create the script and show the results. This time the view faces the direction of motion as it moves along the path.

Combining Scripts

At this point, you can combine the script which animates the cone with the script which animates the view to create a script in which they move together. (This is why you were supposed to save foo.script, the script which flies the cone along the curve spl_path2.) From the main menu, select COMBINE SCRIPTS to pop up the script-combining window. On the right side of the window is a listbox which should show all of the script files in the current directory. Find foo.script in the list, and click on it with the left mouse button. This makes foo.script appear in the listbox on the left, which is the list of files that will be sorted together. You can also type in the names of the files you want to combine. Type view.script in the entry box below the Combine Scripts label, and press the Return key to enter the file into the list. Next, go to the Create script entry box and enter the name both.script. This is the name of the file that will be created by combining foo.script and view.script.

Press the OK button to begin combining the scripts. With the short, simple scripts being used here, this process won't take long, but when combining long, complicated scripts, the process can take a few seconds or even minutes in extreme cases. You can halt the process if necessary with the Halt button that appears while the scripts are being combined.

Press the Show Script button to bring up the show script window, and show both.script. Because the eye and the center of the cone follow the same path and point the same direction, you will see the front of the cone in front of you. It is as if the camera were fixed to the center of the cone. Because the cone was animated with automatic steering and banking, you will see it bank left and right into the turns.

Attaching the Eye to Objects

You can use the Eye point box to fix the eye to a point other than the center of the cone. In the view animation window, enter an eye point of -60 0 10. To understand what this means, imagine that you have a camera at the point (-60,0,10), which is facing the positive x direction. The camera is attached by an invisible bar to an invisible tripod at the origin. When the view script is created, it is the invisible tripod which will be moved and steered along the path defined by spl_path2. The camera will remain rigidly attached behind and above the tripod. When this script is combined with the cone animation script, the eye always remains 60mm behind and 10mm above the center of the cone. Press the OK button to recreate view.script, then return to the combine script window and re-combine foo.script and view.script to make both.script. Show the new script, and you should see the cone from behind and above as it flies along its path.

When giving the view a fixed offset, as you just did, it's not easy to know exactly where you want the camera to be in relation to the invisible tripod. The Object center and Object yaw, pitch, roll entry boxes help to automate that process. Suppose for example that you want to look down on the cone at an angle from the front. The first step is to enter the center point and orientation of the cone. These should approximately the same values you used when animating the cone. Before doing this, press the Restore button on the SHOW SCRIPT window, to put the cone back into it's true position in the model. Turn off perspective viewing to make centering the display on the cone easier. Set the object center by centering the display on the cone and pressing the Object center button. Type 45 90 0 in the Object yaw, pitch, roll entry box as you did in the previous section. The next step is to manipulate the display until the desired view of the cone is acheived. Turn perspective viewing back on, and manipulate the view until the cone appears as you would like to see it. You could try, for example, executing the command:

mged> viewset ypr 0 -40 120
to look at the top left of the cone. When you have the view of the cone that you want, press the Eye point and Eye yaw, pitch, roll buttons to enter the current values. Now, create the view script and combine it with foo.script to create a new both.script. When you show this script, the cone should move along its usual path, and the view should be fixed to the cone in the way that you specified.

If you need to attach the view to a moving object in more complicated ways, you should consult the anim_cascade man page. This routine could be used, for example, to make the eye pan in a circle around the cone as it flies.

Using an Eye Path and a Look-at Path

Another useful common way of manipulating the view is to specify where the eye should be and what it should look at in every frame. In this example, you will move the eye along an edge of the square platform while it looks toward the cone. Go to the curve editor and make the last node of the path curve current. Make a note of the time for this node, which is displayed in the entry next to the Time label. You will now create an eye curve which must end at the same time. Open a new curve by clicking on the Current curve label, selecting New curve from the posted menu, and typing eye for the name of the curve. Center the display on a point just above the top left corner of the square platform (as seen from a top view). Press ADD to make this the first point in the eye curve. Center the display on a point just above the bottom left corner of the platform, and add this to the eye curve. Click on the entry box next to the Time label with the left mouse, and change the time parameter of this node to match the last time parameter of the path curve. Be sure to press the Return key to apply the new time value to the curve. Press the Spline Interpolate button to create an interpolated curve called spl_eye.

The next step is to create an animation table which contains the eye curve and the path curve. Open a new or existing table editor using the TABLE EDITOR button on the main menu. Press the Read button and select from curve spl_eye from the posted menu. On the input request window which pops up, make sure that Replace mode is enabled and that all columns will be read, then press OK. The table editor should fill up with a four-column table of parameters from the eye curve. Press the Read button again, and this time select from curve spl_path2. On the input request window, enable Add Columns mode, and next to the which columns label enter 1-3. This will take columns 1,2 and 3 of the path and add them to the right of the existing columns of the table editor. Column 0 of spl_path is the time column, which is not needed since the table editor already has a time column is already present. If all has gone well, there should be seven columns in every row of the table - these are time, three eye columns, and three path columns.

Go back to the view animation window, and choose table editor from the Source option menu. Type the integer identifier of the table editor you just used in the corresponding entry box. Delete any values in the Object center, Object yaw, pitch, roll, Eye point, and Eye yaw, pitch, roll entries. Select Eye path and look-at path from the orientation control section, and press OK to create the new view script. Combine the view script with foo.script, and show the resulting script. The eye should move steadily along the edge of the platform as it watches the flying cone.

Editing View Curves

A third useful method for view animation is interpolating between saved views. A series of views can be saved in a view curve, much as a series of points can be stored in an ordinary curves. Select VIEW EDITOR from the main menu to pop up the view editor window.

The view editor is similar in many ways to the curve editor. The name of the current view curve, displayed next to the Current v-curve label, is initially "view". By pressing the ADD button, you insert the display's view parameters after the current node of the view curve. INSERT inserts the display's view parameters before the current node, MOVE overwrites the current node with the display's view parameters, and DELETE deletes the current node.

Once you have stored a set a views in a view curve, you can interpolate between them to create a complete view animation table. Interpolating between orientations is more complicated then interpolating between positions.

To get experience with view interpolation, you first need to create a suitable view curve. Center the display on the small white sphere (light.r), and select a right view. Zoom in or out if necessary so the moss world objects fill most of the screen. Press the ADD button to make this the first view in the view curve. Next select a top view, and press ADD again. At the MGED prompt, type:

mged> vrot 0 -90 0
Press Add again. Finally, select the right view again, and press ADD a fourth time. To step visually through the views you stored, enable the Apply current node to view checkbutton. With this button enabled, the display always reflects the view saved in the current node. Step back and forth between the saved views using the left and right arrow buttons.

The views in the view curve are stored as lists of view parameters. The particular combination of parameters stored in a given view curve are listed next to the Parameters label; by default, the parameters are size (viewsize), eye (the three coordinates of the eye point), and quat (four quaternion orientation coordinates). To see the view curve contents, click on the name of the the current view curve, which is displayed next to the Current v-curve label. The view curve display window which pops up is similar to a table editor, exept that the text can't be edited, and there are fewer functions in the menu bar on the bottom line. Each row of the table corresponds to one of the saved views, and each column corresponds to one of the current view parameters. In this case, the first column is time, the next is the viewsize, the next three are the eye point, and the last four are a quaternion. The row of the table corresponding to the current node is always highlighted.

Back in the view editor window, press the Parameters button and examine the posted menu. There are five different view parameter combinations to choose from. Select size eye ypr. Note that the last four columns in the view curve, respresenting the orientation as a quaternion, are automatically converted to three columns representing the orientation as yaw, pitch, and roll.

Making the Eye Follow View Curves

Next you will create a view animation script using your view curve as a basis. Press the Clone button on the view curve display window. This creates a new table editor and loads it with the contents of the view curve. Before creating the view animation script, you need to smoothly interpolate your view curve. Press the Interpolate button on the table editor to pop up a table interpolation window.

Each entry at the top of the interpolator window represents a column of the output table that will be produced. Each entry box should contain an interpolation command, such as spline or linear. All of the possible interpolation commands are listed when you post the Active Command menu. If the command spline 1 were placed in entry box 2, that would mean that column 1 of the input table will be spline interpolated and placed in column 2 of the output table. By default, AnimMate spline-interpolates all of the columns of the input table. Since the viewsize, eye point, and yaw, pitch, and roll can all be spline interpolated, the default entries are exactly what you want. The start and end times for the interpolation are by default set to the start and end times for the input table. Press OK to do the interpolation.

Go back to the view animation window, and identify as the source the table editor you just interpolated. Enable Rotation specified as ypr and Read viewsize from source. The label below the Source label should read 8 input columns needed: t v x y z y p r. These are the columns of the view curve: time, viewsize, x, y, and z coordinates, yaw, pitch, and roll. Press OK to create the script, and then show it. The view should move smoothly between the views you saved in the view curve.

When interpolating between orientations, quaternion interpolation sometimes produces better results than interpolating yaw, pitch, and roll. You can create another view script using quaternion interpolation to see the difference. Go back to the view editor and select size eye quat from the Parameters menu. Next, go back to a table editor and select from v-curve view from the Read menu. Read in all the columns, using Replace mode. Then press the Interpolate button. Although the view size and eye point can be interpolated with spline interpolation, the quaternions must be interpolated with a special quaternion interpolator. Select Quaternion (src) from the Active Command menu, and then click on the column labels for entry boxes 5 through 8. This replaces the interpolation command spline with quat, for columns five through eight. Then press OK to do the interpolation.

Go back to the view animation window, and enable Rotation specified as quat. Change the name of the Output file to view2.script, so that you can compare the new script with the previous one. Create and show the new script.

Take a few moments to compare the animations produced by view.script and view2.script.. In the script created with yaw, pitch, and roll, notice how far the view center strays from the small white sphere after passing through the top view. This is an indication that the orientation is swinging too wildly between the views you specified. Quaternion interpolation usally avoids problems of this type. On the other hand, yaw, pitch, and roll interpolation usually works fine in situations where the roll values remain small and vertical views such as the top view are avoided.

Whether or not you use quaternions, you can fix the center of the view exactly to a given point in the following way. Go back to the table editor you used for the quaternion interpolation and press the Edit Columns button. There should be nine entry windows, labeled from zero to eight, representing the time, viewsize, eye position, and quaternion orientation. In the entry windows labeled 2, 3, and 4, type 20, -13.5, and 5.0 respectively. These are the approximate coordinates of the small white shere. Press OK to replace the eye path with those constant values. Next, go to the view animation window. You will use the Eye point entry box to set the eye back a certain distance from the white sphere. Note the viewsize from the second column of the table editor, divide this number in half, negate it, and enter the result followed by two space-separated zeros in the Eye point entry box. (The distance from the eye to the center point is always one half the viewsize.) For example, if you used a viewsize of 200 in the second column of the table editor, then you would enter -100 0 0. This puts the eye 100mm behind the invisible tripod, which is being firmly attached to the small white sphere. Make sure that the correct table editor is identified as the source. Enable Rotation specified as quat, and press OK to create the script. When you show the script now, the white sphere should remain fixed in the center of the screen.

Go back to the view editor window and post the Parameters menu. The last combination on the list, eye center, is different from the others because it always stores a "right-side up" view. The eye point and view center are not quite enough to completely specify the view, which is still free to twist around the axis defined by those two points. To resolve the ambiguity, AnimMate always selects a right-side up view when a center point and eye point are stored in a view curve. Select eye center to convert the view curve to that format. Enable Apply current node to view and step back and forth through the saved views. Notice that all of the views are now "right-side up". Note also that the second view in the view curve is probably no longer a normal top view. The eye center orientation is ill-conditioned when the axis they define is nearly vertical, because slight floating point errors in the coordinates can cause big changes in the resulting orientation.

Disable Apply current node to view and execute the command:

mged> ae -90 80
This is close to a top view, but not close enough to cause ill- conditioning problems. Use the view editor arrow buttons to make node 1 of the view curve current, and press MOVE to overwrite node 1 with the current view. Go back to a table editor and read in the new view curve, replacing the old editor contents. Press the Interpolate button and then OK to spline interpolate the eye point and center point. Go back to the view animation window and select Eye path and look-at path in the orientation controls. Make sure that the correct table editor is identified as the source for the view animation. Click on the Eye point entry box with the left mouse and use the keyboard sequence <Ctrl>-a <Ctrl>-k to delete the contents of that line. Now re-create and show the view script. Note that the view always stays perfectly centered on the small white sphere, and the view is always right-side up. The eye center interpolation method is probably the best in view animations where only right-side up views are wanted.

At this point, you have all the tools you need to use AnimMate for a variety of object and view animations. The last and final section of this tutorial introduces a specialized tool for animating vehicles with articulated tracks. You might also be interested in the appendix, which offers some hints on ray-tracing your animation scripts.


Next Section: Track Animation

Previous Section: Object Animation

Index