Chapter 2 Motion Section 1 Object motion At the end of the previous chapter, you used the mouse to move objects around the screen to position them in desired locations. Some of the exercises were probably somewhat difficult, not from the perspective of understanding what you needed to do, but rather from the perspective of actually doing it. It is not that easy using the mouse (and the 6 radio buttons to select mouse actions) to correctly position all of your objects. In this chapter, you will learn how to issue commands to move objects to their correct locations. Before working with the actual motion commands (and how to issue them), it is necessary to review how the position of an object in 3-D space is described. Describing an object in 3-D space It is first necessary to develop a sense of perspective. To start, consider a single point in space -- well, not really a point, more like a little red ball. Now consider a horizontal pipe running through it (left to right). Now, a vertical pipe (top to bottom) runs through the same point.
And, finally, a depth pipe (front to back) runs through the red ball. That last pipe is a bit difficult to see. So, it is necessary to move the camera up and around just a bit to see it better. In the above graphic, the little red ball is located at the origin. Its position is represented using (x, y, z) coordinates where x is the distance of the object along the horizontal axis, y is the distance along the vertical axis, and z is the distance along the depth axis. The position of the red ball is (0, 0, 0). That is, the red ball object is viewed as the center of attention. And, the central intersection of the x, y, z coordinate system is located at the center of the object. Motion: Rotating On Its Own Axis With the red ball object positioned in this 3-dimensional coordinate system as illustrated above, we can think of the object as being able to rotate in any of three different directions. 2
In each case, one axis is stationary while the other two form a rotating plane. The red ball object turns (spins) in the direction of the rotation. Motion: Along an Axis A different kind of motion occurs if the object moves from its current position along an axis. This is a translation from one location to another. In the figure below, the ball is illustrated as moving along each of the axes. Motion: To a Specific Location Of course, the object can be moved to a location in the three-dimensional space around the origin, (0,0,0), where the axes intersect. For example, you could move the red ball object to a location such as (1, 1, 0). The location (1,1,0) is one unit to the right and one unit up from the center. 3
This is a bit difficult to see with the small red ball. For a bit better perception, the little red ball is exchanged with a 3-dimensional cube, like this: Each point on the surface of the cube is located in 3-dimensional space in terms of its distance from the origin, on each axis. Thus, each point on the surface of the cube is described in terms of (x, y, z) coordinates. You can think of x as left/right, y as up/down, and z as front/back. As presented in the previous chapter, objects can be resized. For example, it is possible to double the size of the cube like this: It is important to be aware of the consequences of resizing. The coordinate points on the surface of the object are changed as the object grows or shrinks. So, a side effect of resizing the object is a movement of the object in three-dimensional space. In 3-dimensional space, motion (translation), rotation, and resizing causes objects to be animated. These three processes together are called graphic transformations. You can perform graphic transformations in Alice by using motion instructions. How objects can move In this section, the focus is on the types of motion an object can perform and how to bring about that motion. The lab corresponding to this section is essential to your understanding of how to move objects around in an Alice scene. One way to move objects around the scene is to use a command line instruction, where a command describing the motion is typed into the command line. The command line s location is as described in Figure 2-1-1 below. 4
This is the command line!!!!! Figure 2-1-1 The location of the command line In the command line you will be able to issue commands that will accomplish the same motion as was previously done using the mouse. Commands can also be issued in a program script. Program scripts will be introduced in chapter 3 of this book. In this chapter, the motion commands are illustrated in terms of what actions can be performed and what options are available for each action. 5
Movement An object has the ability to move around in the virtual world space, using its sense of orientation (up, down, left, right, forward, back). For example, you can command the helicopter to move up 0.25 units, as shown in Figure 2-1-2. (A unit measure is a relative measure that depends on the current camera and object positions.) The command to perform this action is Helicopter.move(up,.25). You can type the command in the Figure 2-1-2 -- Move Instruction command line, or you can take advantage of the pull-down menus in Alice to have the command entered automatically. To perform the move instruction using the pull-down menus, simply position the mouse cursor over the Helicopter icon in the object tree (or over the Helicopter object itself), and then click the right mouse button. Then, move the mouse cursor over the Move instruction in the menu. Another pull-down menu automatically appears. Select the Up option and then, from the next pull-down menu select Other and click the mouse. It should now be possible to specify 0.25, and the helicopter will move in an upward direction by 0.25 units. The move() instruction is used for translational motion (movement from place to place). Rotational movement (pivot) commands include turn() and roll(). Translational and rotational movement were described above. Figure 2-1-3 shows a helicopter performing a turn() motion. In this example, the helicopter turns to its right. You will notice that the turn command performs the same type of motion as the mouse radio button Turns left/right. 6
Figure 2-1-3 -- Rotating an object in a right-left rotational axis Figure 2-1-4 shows the effects of using turn() to tell an object to turn in a backward direction. This is the same type of motion as performed by using the mouse radio button Turns forward/back. Figure 2-1-4 Rotating an object backwards Again, instead of typing the command in the command line, it is possible to use the pulldown menus by right-mouse clicking on the Helicopter, and then selecting Turn, Up (Up is the same as Back), and then Other, specifying 0.1 or 0.2 as the amount to turn. Figure 2-1-5 shows the effects of using roll() to turn an object sideways. There is no mouse motion to exactly simulate this motion. The Tumble radio button does allow this type of motion. Actually, the Tumble radio button allows a full range of rotational motion. 7
Figure 2-1-5 rotating an object sideways Like the previous commands, the Roll motion may also be accomplished by right-mouse clicking on the Helicopter, selecting the Roll option, then selecting either Left or Right, and specifying the amount to roll. Awareness An object is aware of other objects in the world -- though objects are not always smart enough to avoid trying to occupy the same space as another object. For example, suppose a cat and a helicopter object have been added to your world (as in Figure 2-1-6). Figure 2-1-6 -- Before MoveTo Figure 2-1-7 -- After MoveTo You could use an instruction to move the cat to the helicopter. cat.moveto(helicopter) This causes the cat to move to a position immediately adjacent to the helicopter, as illustrated by Figure 2-1-7. It is important to understand that the motion of the cat has been affected by its awareness of the position of the helicopter. Other motion instructions that are affected by awareness include TurnTo(), PointAt(), Place( ), and 8
StandUp( ). Of these instructions, note that only the PointAt() and StandUp() instructions may be accomplished by using pull-down menus. The pull-down menus only list the most frequently used commands. Commands such as TurnTo() and Place( ) that are not in the pull-down menus must be typed into the command line when you wish to use them. Position Placement Unfortunately, positioning objects can be a tricky task. This is especially true when using a mouse motion selected by the radio buttons (e.g., Raises/lowers, Turns forward/back, Tumbles). The position of the object relative to the ground can be visually awkward. That is, the object can become mis-aligned with the ground -- not on the ground. This becomes a problem when the object performs several moves in succession and ends up flying into the air or burrowing into the ground. Let s explain by means of an example. Suppose a chicken is placed in a scene, as in Figure 2-1-8. Figure 2-1-8 Chicken before Move Now, suppose the chicken is moved forward 1.3 units, resulting in the scene in Figure 2-1-9. Figure 2-1-9 Chicken after Move 9
This looks fine. But, let s take a closer look by moving the camera to ground level, as seen in Figure 2-1-10. It is now clear that the chicken is no longer standing on the ground. While chickens can fly, this altitude is a bit unlikely! Figure 2-1-10 Chicken is not really on the ground! The problem is one of placement. Before moving the chicken, we should have made sure that the chicken is standing with its two feet firmly on the ground and that its body is properly aligned with the ground. As an analogy, consider an airplane in flight. If the nose of the plane is pointed down, then moving the plane forward also moves the plane downward. If the nose is pointed upward, then moving plane forward moves the plane upward. The plane must be aligned with the ground to maintain a level forward motion. To make sure the object is placed on the ground properly, two commands should have been issued when placing the chicken in the screen. The commands should be issued in the following order: chicken.standup() chicken.place(ontopof, ground) The first command will ensure the chicken is properly aligned with the ground, and the second will ensure that the chicken is standing exactly on the ground, and is not above the ground or in the ground. Had these two commands been issued first, the result of the move would have been that the chicken remained on the ground, as the ground level camera view in Figure 2-1-11 shows. Figure 2-1-11 Chicken still on ground after Move 10