mged> e all.gWhen animating an object, you need to decide where you want the object to go and what orientation it should have. The position is usually more straightforward than the orientation.
Click on the ADD button, and a cyan cross should appear in the center of the mged display. Use the middle mouse button to center the display on another point, and then click the ADD button again. The cyan cross should move to the center of the display, and a yellow line should connect the previous center point to the current one. You have created a curve consisting of two points.
Curves in AnimMate are simply lists of points in space with associated time parameters. The time parameter and point together are called a node. Curves are displayed by line segments connecting all the points. The curve editor allows you to edit curves in several ways, interpolate them to create smoother curves, and read and write them to files.
When a curve is being edited, one node is always considered the current node. Near the top of the curve editor should be the text: Node 1 of 2, meaning that the current node is node number 1 and that there are two nodes in the current curve. Nodes are numbered beginning with zero, so node 1 is actually the second node in the list. The time parameter of node 1 is 1.0, and its position is marked by the cyan cross. Next, click on the smaller left-arrow. This decrements the index of the current node, which becomes zero. Notice that the position of node zero is now marked by the cyan cursor, and that the time parameter of the first node is 0.0.
As you may have realized, the center point of the MGED display is important to the curve editor. This is the active point which is added or inserted into the list when those buttons are activated, or the point to which the current node is moved when the MOVE button is activated. Play around with the curve editor buttons. Note that the ADD button inserts points into the curve just after the current node, while the INSERT button inserts points just before the current curve. The MOVE button moves the current node to the current display center point, and the DELETE button deletes the current node.
Next, you will create a curve and use it to animate the magenta cone.
The name of the curve you have been editing so far was called
vdraw. Open a new curve by clicking on the Current curve
label, and then selecting New Curve from the posted menu. A
pop-up window asks for the name for the new curve - enter
path
into the entry box and hit return.
The new curve name should appear next to the Current curve label.
You will want to make the cone fly through the center of the torus. Center the display on a point along the bottom edge of the large square platform, as seen from the top view, and press the ADD button. Then center the display on the center of the yellow torus, and press the ADD button again. Center the display on a point on the other side of the torus, and press the button again. Two yellow line segments should now connect the three points you selected. Change the color to green by clicking on the Color label, then selecting Current curve from the posted menu, then selecting green from the posted color list.
The next step is to interpolate the curve. Press the Spline
Interpolate button. A
smooth yellow curve appears connecting the
three points of your original curve. Although it looks smooth, it
also consists of straight line segments. The difference is
that the new curve has 10 points for every second of time. The name of
the new curve, spl_path
, is found next to the into
curve label. You can experiment with editing the nodes of
path
and re-interpolating until spl_path
takes
on a pleasing shape.
spl_path
. If the main menu is hidden from view, raise it to
the top of the window stack by clicking on the curve editor's
Up button. Click on the CREATE SCRIPT button and select
Object from the posted menu to pop up the
object animation window.
Fill in the entry boxes from top to bottom. The output file defaults to
foo.script - this is the name of the file the script will be written
into. On the next line, labeled Source curve, enter
spl_path
, the name of the curve specifying the desired
path. The Object name should be all.g/cone.r
. This is the
name of the magenta cone which is to be animated and its immediate
parent. Although the name cone.r
would also work in this
case, in general it's best to include the name of a parent to avoid
confusion. If cone.r were being displayed at the top level (i.e. by itself
and not as part of all.g), then the name /cone.r
would be
used.
Leave the rest of the entries with their default values and click on the OK button to create the script. From a shell window, take a look at foo.script. It should look something like the following:
%> head -n 20 foo.script start 0; clean; anim all.g/cone.r matrix lmul 1 0 0 21.4994 0 1 0 -69.5377 0 0 1 -20.2931 0 0 0 1; end; start 1; clean; anim all.g/cone.r matrix lmul 1 0 0 19.4385 0 1 0 -65.7729 0 0 1 -13.7696 0 0 0 1; end; start 2; clean; anim all.g/cone.r matrix lmul 1 0 0 17.4095This file demonstrates the basic format of all animation scripts. There is a start command for each frame, followed by a clean command. Then there are are number of animation commands. In this case, there is just one anim command which applies the given matrix to the object cone.r in each frame. Note that in this case, the matrix is only a translation matrix, with no rotation. Finally each frame is terminated with an end command.
To view the results of this animation, click on the Show Script button to pop up the corresponding window. The entry box labeled Script file should already be filled in with the name of the script file you just created. Make sure that the MGED display window is visible, and press the Show button.
The magenta cone should move in a smooth curve. However, you should notice that the path that the cone follows is offset from the path you specified. This is is because you didn't fill out the Object center box, which tells AnimMate where the object initially is in the model. Since AnimMate thinks the cone is originally at the point (0,0,0), the translations it applies are incorrect. Of course this isn't your fault - you were just following instructions.
Before going back to correct this problem, note that the display left the cone where it stopped in the last frame of the animation. Return it to its true modeled position by pressing the Restore button. Although showing animation scripts causes the displayed position of an object to change, the actual modeled position of the object is never changed by animation commands. To display an object in its true position, you can always use the Restore button or MGED's "e" command.
Now go back to the CREATE OBJECT SCRIPT window. Center the MGED display on the center of the cone by clicking on the cone center with the middle mouse button. Be sure to verify the centering from the top and right views to make sure the view is centered in three dimensions. When the view is centered on the cone, press the Object center button to automatically fill in the entry box with the coordinates of the center point you selected. Now press OK again to recreate the script. AnimMate will probably warn that the file foo.script already exists; go ahead and overwrite the file. Again make sure that the MGED display is visible, and press the Show button on the SHOW SCRIPTS window again. This time, the magenta cone should follow the path specified by spl_path. Watch the animation from several different views to get a feel for the full three dimensional motion.
In this case, let's designate the narrow end of the cone to be the
front, and designate its up direction to be perpendicular to the long
axis of the ellipse at the narrow end. If
the cone were in the default orientation, with the narrow end facing the
x-axis, and the long axis of the ellipse lying flat, it would have to
yaw 45 degrees and then pitch up 90 degrees to get to its current
orientation.
Enter the numbers 45 90 0
into the Object
yaw, pitch, roll entry box, and press the OK button to
recreate the script. This time, when you show the script, the cone
should move point-first along its trajectory.
Another option on the Orientation control section is automatic steering and banking. To demonstrate this effectively, it might be a good idea to add another point or two to the path. Go back to the Curve Editor window and make sure that the curve "path" is selected. Press the right arrow button until the last node of the curve is current. Then add one or two more points in a zig-zag fashion so that the path curve bends one way and then another. Press the Spline Interpolate button to update the interpolation curve.
Now go back to the CREATE OBJECT SCRIPT window and select Automatic steering and banking. Press the OK button to recreate foo.script. When you show this script the cone should "fly" along the curve, banking into the turns like an aircraft would.
Depending on the shape of the path curve that you picked, you may have discovered that the interpolating spline curve varied widely in places from the path you had intended. This effect is especially strong when the distribution of the curve nodes through space doesn't match their distribution through time. When a curve is first created, AnimMate spaces the nodes of the curve evenly through time at one-second intervals. This works well only if the nodes are evenly distributed through space.
To see more clearly the effects that poor time
parameters can have, go back to the curve editor and make node 1 of the
path curve current. The time parameter of this node, visible next to the
Time label, should be "1.0". Click on the time parameter with the
left mouse button, and then key-board edit the entry to read
0.3
. This moves this node much closer in time to node 0 and
farther from node 2. Be sure to press the Return key to apply the
new time parameter to the curve.
Change the name of the interpolation curve to
spl_path2
and press Spline Interpolate to create a
new interpolation curve. Use the Current Spline option in the
Color menu to color spl_path2 red, to help make the new curve
visible.
You should see that spl_path2 strays far from the path
curve between nodes 1 and 2.
Trying to choose the best time parameters for curve nodes can be difficult and tedious. Fortunately, the table editor contains a tool which helps to automate the process. Press the Up button on one of the windows to pop the main menu to the top of the window stack, and select Table Editor. Select New editor, the only option on the posted menu.
A large table editor window should appear. The purpose of this window is to allow you to edit animation tables, which are tables of data in which the columns represent animation parameters and the rows represent animation frames. When it first pops up, the table editor is by default filled in with the contents of the current curve. There is one row for each node of the curve, and there are four columns representing the time and the x, y, and z coordinates of each node. Note that the times for each node are evenly spaced at one second intervals, except for node 1 which you just modified.
Click on the table editor's Estimate Time button to pop up the time estimator window
The time estimator window uses the distances between curve nodes to
estimate the best time parameter for each node. It always assumes that
the first column of the table editor is the time column, and that the
first and last rows in the time column are the desired starting and
ending time. Three other columns of the table, listed in the Path
Columns entry box, specify a path which will be used as a basis for
the estimation. The other two entry boxes allow you to specify the
starting and ending speeds of the object's motion. Speeds specified with
percentages are relative to the speed that would move the object along
the path at a constant rate. Thus if both the starting and ending speeds
are 100%
, then the object moves at a constant rate
throughout. These are the default values - press the OK button to
accept them.
Look at the first column of the animation table in the table editor, and
Note that the time parameters are no
longer evenly spaced - they have been changed to reflect the distances
between the points.
To apply the new time parameters to the path curve, click on the table
editor's Write button, and then select to Curve from the
posted menu. An pop-up window should ask if you want
to write all
columns to the path
curve. Press
OK, and the path curve is updated. Press
Spline Interpolate to recreate spl_path2 using the new time
parameters. The curve should now fit the original path much better.
Now, go back to the table editor and click on Estimate Time
again. This time, enter an absolute speed of 0
for both the
starting and ending speeds. This means that the object will start and
end at rest, accelerating at the beginning and decelerating at the end.
Write the new parameters back to the path curve using the Write
button. Go back to the curve editor and change the interpolation curve
name to spl_path3
, then redo the interpolation. This time
the interpolation curve may not fit the path curve as closely,
particularly near the beginning and end. However, when you use spl_path3
to animate the cone, it should appear to start slowly, accelerate, and
then slow at the end of its motion.
Go back to the object animation window and change the name of the source
curve to spl_path3
before recreating and showing
foo.script.
Besides helping to control the speed of animated objects, time estimation can give you the freedom to put nodes closer together in sections of the path which require the most control, and to space them widely in other areas. For example, if you are particular about the direction that you want an object to move at a certain point, it is a good idea to put two closely spaced nodes which define the direction at that point. You can use this technique to make the cone fly perpendicularly through the torus.
Go back to the curve editor and make sure that the path curve is current. Use the arrow buttons to make node 1, the node in the center of the torus, the current node. Center the display on the position of node 1, making sure that you check the centering from at least two orthogonal views. Go to a top view, and use the MGED's yslew slider to move the display center to the edge of the torus closest to the top of the screen. Press the curve editor's ADDbutton to add this point to the curve. Now nodes 1 and 2 should define a straight line perpendicular to the center of the torus.
Go back to the table editor, and read in the current state of the path curve by pressing the Read button and selecting from path curve from the menu that appears. Press Estimate Time and make sure that the Start and End speeds are both zero before pressing OK. Note that the new time parameters for nodes 1 and 2 are close together, reflecting their closeness in space. Write the new values back to the path curve with the Write button, and then go back to the curve editor to re-create the interpolation curve. Go back to the object animation window and recreate and show foo.script. The cone should fly perpendicularly through the torus.
Because you selected zero start and end speeds during the time estimation, the cone should appear to start from rest, accelerate, and then slow down at the end of its motion. If this is difficult to see, the problem may be that the interpolation curve and the original curve being interpolated are too different. The closer that the length of the interpolation curve is to the length of the path curve, the more accurate the time estimation values are, and the greater control you have over the speed of the object. For example, if spl_path3 varies widely from the path curve in some sections, you may get better control over the speed of the object by adding another node or two to the path curve in that section. If you do this, don't forget to redo the time estimation step before re-interpolating spl_path3.
One other trick of the trade to keep in mind is you may need three closely spaced nodes, rather than two, in order to define a direction of motion at the beginning or end of an object's path.
foo.script
to rel.script
so that foo.script
is available
for later use.
You will use the table editor to create an animation table for bobbing the cone sinusoidally up and down. Go back to the table editor, and press Clear to empty the table. Press the Edit Columns button to pop up the column editing window. On the column editor, press the Add Column button three times to make three new entry boxes appear at the top of the window.
Each entry box of the column editor corresponds to a column that will be
produced as output. The box may contain any valid Tcl expression, plus
some column editor substitutions associated with the @
symbol. Type @i
in the first entry box, type
@n
in the second, and type 4*@pi*@i/(@n-1)
in
the third. In the entry labeled Number of Rows, type
31
. Now press OK to create the table you specified.
The first column now contains the row index (substituted for @i), the second column contains the number of rows in the table (substituted for @n). The third column ranged linearly from zero to four times the mathematical constant pi (substituted for @pi). The other possible substitutions are @e for the mathematical constant e, and @k, for the contents of the k-th column.
Click on the Edit Columns button again. Note that the default
behavior of the window is for the output table to simply be a copy of
the input table. Add another column by pressing the Add Column
button. Type @i*3/(@n-1)
into the first box, to create a
time column ranging from 0 to 3 seconds. Type 0
in the
second and third entry boxes, and type 5*sin(@2)
into the
fourth entry box, to create a column which varies sinusoidally between
5 and -5. Note that the
argument to the sine function will be taken from row 2 of the current
table for each row of the output column.
Leave the
Number of rows as all
to keep the same number of
rows, and press the
OK button to create the new table.
Now we can create an animation based on this table. Go back to the
object script window and press down on the word curve in the
Source curve label. Use the posted option menu to select table
editor. The label should now read Source table editor.
In the corresponding entry box, remove the curve name
spl_path2
and type in the integer which identifies the
table editor you have been using. (This integer is displayed on the top
line of the table editor.)
Now the animation table driving the script will come
directly from the table editor. Change the orientation control to
No Rotation and press OK to create the script. When you
show the script, you should see the magenta cone bobbing up and down at the
origin. Note that the front of the cone, as defined by Object yaw,
pitch, roll, lies in the default position (facing the x-axis)
when no rotation is
specified.
To make the cone bob up and down in place, select Relative Displacement. Now the displacements in the table editor are considered to be relative to the object center. Recreate and show the new script. The object bobs up and down in place, although the orientation is still changed to face the x-axis.
Now enable Relative Orientation as well. In this mode, all
displacements and orientations are considered relative to the object's
own axes, as defined by Object yaw, pitch, roll. Note that the
object now moves "up and down" relative to its own coordinate system.
To see that orientations are also relative to the object's own
orientation, go back to the table editor and pop up the column editor.
Press the Add Column button three time and enter
@0*120
into the first new column entry box next to the
label 4:. Enter 0
into entry boxes 5: and 6:, and press OK
to add the three new
columns.
These columns represent yaw, pitch, and roll for the cone. The yaw column will cause the cone to yaw through 360 degrees during the animation. Go back to the object script window and select Rotation specified as ypr from the orientation controls section. Note that the column description label near the top of the window changes to 7 input columns needed: t x y z y p r, meaning that the source table should specify time, x,y, and z coordinates, yaw, pitch, and roll. Create and show this script. Note that both the "up and down" motion and the yaw are relative to the cone's own coordinate system.
Now that you've mastered object animation, it's time to move on to the view.