Chapter 3 Animation at last! - Plymouth State...

11
Chapter 3 Animation at last! If you’ve made it to this point, and we certainly hope that you have, you might be wondering about all the animation that you were supposed to be doing as part of your work with Alice. Well, the time has arrived to start doing some animations! Creating an animation in a virtual world is a problem solving task. The solution to the problem consists of two parts: creating the initial scene, and writing a script to generate the actual animation. Well, by now, you’ve had a fair bit of practice in creating an opening scene, so it is about time to create the second part of the solution (an animation). Before we begin developing an animation, we need to talk about the problem solving process. In other words, at some abstract level, how do we solve animation problems? To solve a problem (perform a task) in a virtual world, we must accomplish the following: 1) define the problem setting -- the opening scene, 2) determine the object(s) and parts that will perform the task, 3) place the object(s) at a beginning location in the opening scene, and 4) supply a list of instructions (commands) to perform the task. These steps are all part of the problem solving process. The result of our work is an opening scene for the virtual world and a script. A script (also called a program) is a collection of commands that tells Alice what actions the objects are to perform in the virtual world. You can think of an Alice script as being somewhat like a script for a theatrical play. The theatrical script outlines the actions to be taken by actors on stage while an Alice script outlines the actions to be taken by objects in a virtual world. The remaining portion of this section uses an example to model the problem solving process, as used with Alice. Alice Problems: Tasks and Situations We define a problem as consisting of two parts: n A task to be performed. This is generally some animation we want to do. n A world situation. A situation tells us what we know about the Alice world at a particular instant in time. The situation includes the location of any objects and the original scene. There are three kinds of situations:

Transcript of Chapter 3 Animation at last! - Plymouth State...

Page 1: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

Chapter 3 Animation at last! If you’ve made it to this point, and we certainly hope that you have, you might be wondering about all the animation that you were supposed to be doing as part of your work with Alice. Well, the time has arrived to start doing some animations! Creating an animation in a virtual world is a problem solving task. The solution to the problem consists of two parts: creating the initial scene, and writing a script to generate the actual animation. Well, by now, you’ve had a fair bit of practice in creating an opening scene, so it is about time to create the second part of the solution (an animation). Before we begin developing an animation, we need to talk about the problem solving process. In other words, at some abstract level, how do we solve animation problems?

To solve a problem (perform a task) in a virtual world, we must accomplish the following: 1) define the problem setting -- the opening scene, 2) determine the object(s) and parts that will perform the task, 3) place the object(s) at a beginning location in the opening scene, and 4) supply a list of instructions (commands) to perform the task.

These steps are all part of the problem solving process. The result of our work is an opening scene for the virtual world and a script. A script (also called a program) is a collection of commands that tells Alice what actions the objects are to perform in the virtual world. You can think of an Alice script as being somewhat like a script for a theatrical play. The theatrical script outlines the actions to be taken by actors on stage while an Alice script outlines the actions to be taken by objects in a virtual world. The remaining portion of this section uses an example to model the problem solving process, as used with Alice. Alice Problems: Tasks and Situations We define a problem as consisting of two parts:

n A task to be performed. This is generally some animation we want to do. n A world situation. A situation tells us what we know about the Alice world at a

particular instant in time. The situation includes the location of any objects and the original scene. There are three kinds of situations:

Page 2: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

2

v The initial situation – This is the situation at the start of a task. The objects of interest are the opening scene and original positions of the objects that make up that scene.

v The intermediate situation – This is the situation that occurs at any time during the action, between the start of the task and its conclusion.

v The final situation – This is the situation at the conclusion of the task . Let us explain an animation problem by means of an example. Suppose we have the White Rabbit and a Butterfly positioned as shown in the initial situation, Figure 3-0-1 below. What we would like to accomplish (our task) is to have the White Rabbit walk over to the Butterfly. By "walk", we mean animate the legs of the rabbit as it moves toward the Butterfly, so that it appears that the White Rabbit is actually “walking”.

Figure 3-0-1. The initial situation As the animation progresses, the White Rabbit will begin walking towards the Butterfly. At some time during the animation, we would see an intermediate situation where the rabbit has walked part of the way toward the Butterfly. In the intermediate situation shown in Figure 3-0-2, the rabbit's right leg is "in the air."

Figure 3-0-2. An intermediate situation

Page 3: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

3

Note that there are several intermediate situations. We have just shown the intermediate situation that has occurred about one third of the White Rabbit’s walk towards the Butterfly. At last, we see the final situation in Figure 3-0-3. The White Rabbit has completed its walk and is now just behind the butterfly.

Figure 3-0-3. The final situation

Obviously, we could use the mouse to move the rabbit from the initial situation to the final situation. But, that is not what we really want to do. In order to make our animation appear realistic, we want the White Rabbit to move its legs in a pattern that make it look like it is walking as it moves across the world. The mouse cannot be used to move the parts of the rabbit and we want the rabbit's legs to appear to be walking. Let us now take a look at the script we will need to write to make this animation work. Writing our first Alice Program Let us start with the 4 problem solving steps (from the above discussion). For step 1: We need to define the task. We can define it as follows: "Suppose that we have the White Rabbit and the Butterfly positioned on a default world (as shown in Figure 3-0-1). Our task is to have the White Rabbit walk over to the Butterfly." For step 2: We need to know what objects and parts we will need. We need the Default Scene, the White Rabbit, and the Butterfly. What parts will we need? Taking a look at the object tree (after clicking on the ‘+’ to the left of the White Rabbit), we see:

Page 4: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

4

As we want the White Rabbit to walk, we are probably going to need to work with the White Rabbit’s rleg (right leg) and his lleg (left leg). For step 3: We need to place the objects in their starting positions. Here is a possible initial scene that we could create for the animation. It contains all of the objects we will need.

Page 5: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

5

Figure 12 – Initial Scene Note that on the top center of the screen is the tab “Opening Scene”. That is because we are creating the opening scene. Next to that tab is a tab for “Animations”. By clicking on the Animations tab, we open an editor where we can write the animation sequence for moving the White Rabbit to the Butterfly. Animations Editor Hidden behind the Opening Scene is an Animation editor. In the computer science community, the term program (or program code) is often used when talking about a script or animation sequence. We will use the terms interchangeably. In the Alice interface, a program is a list of actions (instructions) to be performed by Alice and the objects in the virtual world. For step 4: We will use the Animation editor to write the instructions for the White Rabbit to walk in the world. Walking forward, of course, is a translational motion. So, the instruction that springs to mind is the Move() instruction. Of course, our script should probably consist of several move instructions. We'll issue a command to have the rabbit pick up its left foot. Then, we'll have the rabbit move forward followed by putting

Page 6: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

6

its left foot back down. Let’s try this out to see how it looks. The Animations window looks something like the following:

To begin with, click the ‘+’ to the left of the WhiteRabbit in the object tree. This is because we want to move the White Rabbit’s right leg. Now, click on the word .rleg that appears below the White Rabbit with the left mouse button. With the button clicked, drag the rleg directly underneath the “Action1 = DoInOrder” line in the main Animation window. When you release the mouse button, you should see something like the following:

Page 7: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

7

Now, select Move from the pull down menu, and select Up from the next pull down menu, and Other from the next pull down menu. Then enter a value of 1/16. Your command should look like the following:

Now we would like to move the whole White Rabbit forward while we have the White Rabbit put its foot back down again. To move the White Rabbit forward, use the left mouse button and click on the White Rabbit in the object tree. Drag the mouse to a location immediately below the “WhiteRabbit.rleg.Move(Up, 1/16,more…)” line, and then select Move (from the drop down menu), then select Forward (from the next drop down menu), then select Other, and enter in a value of ¼. Your new script should look like the following:

Now, add a command to move the White Rabbit’s right leg (rleg) back down 1/16, so that your resulting script appears as follows:

Page 8: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

8

This sequence of animations moves the White Rabbit forward one step. As the White Rabbit is approximately 4 steps from the Butterfly, we should repeat this sequence of animation steps 4 times, once with the right leg, once with the left, once with the right, and then finally with the left leg. The resulting script should look something like the following:

Now we are ready to try out the animation! Click on the Start button. The White Rabbit picks up its right leg. Then it moves its whole body forward. Then it moves its right leg back down. This entire motion is somewhat stilted

The problem is that Alice executes all of the move commands in our script sequentially. So, the White Rabbit must move completely forward before it begins to put its leg down. To get around this problem, Alice provides two special commands that only work in a script (where the sequencing of commands is important): DoInOrder(), and DoTogether(). The DoInOrder() command means that all of the commands which occur inside the command are performed one right after another, not at the same time. DoTogether() means that all of the commands which occur inside of the command are done at the same time. So, if we want the White Rabbit to walk in a more realistic fashion, we should perform the whole body move and the placing of the leg back on the ground at the same time. To do this, click with the left mouse button on the word DoTogether located below the word Combinations on the left of the screen, and drag it in between instructions 1 and 2:

Page 9: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

9

Now, left mouse click on the 3 next to the instruction WhiteRabbit.Move(Forward,1/4,more…). Drag the 3 to just below the DoTogether, resulting in the following:

Repeat the same for the 3 next to the instruction WhiteRabbit.rleg.Move(Down,1/16,more…). Drag the 3 to just below the line WhiteRabbit.Move(Forward,1/4,more…), resulting in the following:

Page 10: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

10

Repeat the same steps for each of the other 3 steps to result in a script that looks like the following:

Let us examine the script in more detail. The first statement, DoInOrder(), tells Alice to execute the statements one by one. However, we do still want two of the instructions to be performed together (namely the White Rabbit moving forward and putting its foot down). So we use a DoTogether() control statement for that purpose. With this new modification, the White Rabbit now walks!

Page 11: Chapter 3 Animation at last! - Plymouth State Universityjupiter.plymouth.edu/~wjt/IntroToComp/Alice/animation.pdf · 2 v The initial situation – This is the situation at the start

11

The White Rabbit's walk is still a little bit on the "stilted" side, so we take advantage of one of the keywords associated with the Move() instruction, the duration= keyword. (Keywords are further discussed in the next section of this chapter.) This keyword modifies the Move() instruction by indicating how long Alice should take in running a particular command. The default value (if you do not specify this keyword) is 1 unit of time. To add this keyword to a move command, click (with the left mouse button) on the more… on the right side of each command, and select the Duration keyword from the drop down box. Now, specify an appropriate duration. So here is the (once again) modified code for the animation:

Now, Start the animation, and watch the White Rabbit “walk” over to the Butterfly.