GREENHORNS 2009

                           Learn to Program using Alice
                                    Objects in 3D...
Because Alice is an interactive graphic 3D programming environment, it is not only useful for learning how to
program, Ali...
•    Figure 4. Center point of a surface.
    •    Figure 5. A partially transparent version of the cube.
    •    Figure ...
When you rotate an object around one of its axes, that axis remains stationary and the other two axes do the
rotation. The...
A 3D coordinate system

While those middle-school children probably don't realize it, they are already drawing in a 3D coo...
Similarly, the red axis in Figure 2 is the axis that would be sticking out of the man's eyeball toward his right.
Once aga...
for each wing and we must know what constitutes front, right, and up from the viewpoint of the wing. In other
words, we mu...
Make a right turn
                                                                    combination of yaw and roll.
If we w...
Can be rotated and translated

Just like any other object, the surface can be rotated around any of the three axes, and ca...
However, in Figure 1, I caused the 3D axes belonging to the cube to be displayed. In Figure 5, I caused the 3D
axes belong...
Figure 7. Left arm of the Coach object.




The coach looks like a headless ghost

You may be wondering how I produced the...
Therefore, unless we are animating a torture chamber, the three translation possibilities available for the arm
aren't ver...
Rotate around the red axis

We could turn the arm backwards so as to rotate it around the red axis by as much as one-half ...
As you can see, this caused the coach to lift his arm so as to point skyward.

Difference between a right roll and a left ...
I explained that many of the objects in the Alice gallery are constructed from smaller component objects, and
that every c...
Save your world in a file named Alice110LabProj.a2w and be prepared to deliver it to your instructor in
whatever manner th...
Alice 3
Upcoming SlideShare
Loading in...5
×

Alice 3

986

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
986
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Alice 3"

  1. 1. GREENHORNS 2009 Learn to Program using Alice Objects in 3D Space Learn the concepts surrounding an object in 3D space, as well as some of the Alice-specific concepts surrounding an object in 3D space. Learn about the center point and the color coding used for each of the axes in an Alice object. Learn about yaw, pitch, and roll and how they are accomplished in Alice programming. Learn how Alice objects are constructed from smaller objects where every Alice object has its own 3D coordinate system. Learn how every Alice object has six degrees of freedom. Walk through the procedure of applying motion to one of the arms belonging to a computer replica of a human while avoiding putting the arm in unnatural positions. Published: March 26, 2007 Updated: May 31, 2007 By Richard G. Baldwin Alice Programming Notes # 110 • Preface o General o Preview o Figures o Supplementary material • An object in 3D space • Summary • What's next? • Resources • Lab project • Copyright • About the author Preface Part of a series This tutorial lesson is part of a series designed to teach you how to program using the Alice programming environment under the assumption that you have no prior programming knowledge or experience. My objective in writing this series of lessons is to make it possible for people who have no previous programming experience to learn programming fundamentals using Alice. As such, I intend to discuss programming issues at a very fundamental level. A lot of fun
  2. 2. Because Alice is an interactive graphic 3D programming environment, it is not only useful for learning how to program, Alice makes learning to program fun. Therefore, you should be sure to explore the many possibilities for being creative provided by Alice while you are learning to program using these tutorials. And above all, have fun in the process of learning. Not especially difficult Computer programming is not especially difficult. However, it does require an aptitude for solving problems. In fact, a computer program is usually a model for a solution to someone's problem. One step at a time If you can learn to program a VCR, you can probably also learn to program a computer. Of course, a computer is somewhat more complicated than a VCR, so there is more to learn. The important thing is to take the learning process in deliberate steps making certain that you understand each step before moving on to the next. General In the previous lesson titled "Learn to Program using Alice, Setting the Stage," (see Resources) I explained that there are two distinctly different views of the Alice environment. One view, often called thescene edit mode, is used to set the stage. The other view, which I often refer to as the program edit mode, is used to animate the world. The eight section of the scene edit mode I explained that the scene edit mode is divided into the following eight major sections: 1. The menus 2. The button bar 3. The object tree 4. The world's detail section 5. The gallery 6. The world that is to be populated and animated 7. The camera controls 8. The object manipulator buttons I provided an overall description of the purpose and use of each of the eight sections. I promised that in this lesson, I would begin the process of drilling down into more detail and start showing you how to use the eight sections in the above list to set the stage for a simple world. Preview An important part of setting the stage is getting objects from the gallery and using them to populate the 3D world. Before getting into that, however, I need to teach you some things about objects in 3D space in general, and objects in Alice's 3D space in particular. That will be the major thrust of this lesson. Figures I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures while you are reading about them. • Figure 1. A 3D cube. • Figure 2. Outline of a 3D cube (note the yellow lines). • Figure 3. An airplane with its 3D axes exposed.
  3. 3. • Figure 4. Center point of a surface. • Figure 5. A partially transparent version of the cube. • Figure 6. A Coach object. • Figure 7. Left arm of the Coach object. • Figure 8. Left arm moved to the left. • Figure 9. Arm turned 90 degrees to the right. • Figure 10. Arm turned backwards by 180 degrees. • Figure 11. Arm rolled right by 45 degrees. • Figure 12. Arm point to the left and up with palm up. • Figure 13. Final pose needed for lab project. Supplementary material Once you have mastered Alice, I recommend that you also study the other lessons in my extensive collection of online programming tutorials. You will find a consolidated index at www.DickBaldwin.com. An object in 3D space An object's viewpoint Every Alice object has a viewpoint. The viewpoint of an object is determined by: • The position of the object in 3D space. • The orientation of the object relative to a 3D coordinate system. For example, causing the Coach object in Figure 6 to move to a different position or to face in a different direction, or both would change his viewpoint. An object's center point Every Alice object has a center point and three axes. The center point is the position in space (relative to the object) at which that object's three coordinate axes cross. (This is often called the origin.) For example, the center point of the Coach object shown in Figure 6 is a point on the ground midway between his feet, and approximately below the top of his shoelaces. An object's motion A disconnected object If you move an Alice object, you are actually moving its Note, however, that it is possible to center point. The rest of the object comes along for the break the connection between an ride. (See sidebar.) object and its component parts. For example, you could cause the Coach If you turn an Alice object to the right or to the left, you are object to move away and leave his rotating the object around one of its three axes. (We will see arms behind. later that this causes the object to rotate around its green axis.) If you turn an Alice object forward or backward, you are rotating the object around a different axis. (We will see later that this causes the object to rotate around its red axis.) If you roll an Alice object to the right or the left, you are rotating the object around a third axis. (We will see later that this causes the object to rotate around its blue axis.) Think in terms of rotating axes instead of rotating objects
  4. 4. When you rotate an object around one of its axes, that axis remains stationary and the other two axes do the rotation. The remainder of the object comes along for the ride. Often when rotating objects, it is easier to visualize rotating two of the axes around a third axis than it is to visualize rotating the object itself. We will see an example of this later when we roll the Coach object's left arm to the right in order to cause him to lift his arm. Italicized method names Why did I represent the words move, turn, and roll in boldface Italics in the above text? I did that to emphasize that I wasn't simply using a generic term for producing motion. Rather I was using a very specific term that has an official connotation. The official connotation is that move, turn, and roll are the names of methods that are used to produce very specific kinds of motion. (You will learn a great deal about methods in subsequent lessons.) Drawing a 3D cube By the time most children reach middle school, they already know how to draw a 3D cube on a sheet of 2D paper. This is true even if they have never had a drawing class. (Does this mean that humans have some inherent knowledge of 3D coordinate systems?) The pictures that they draw are likely to look a lot like Figure 1, or possibly like the yellow outline in Figure 2 without the red, green, and blue lines. Figure 1. A 3D cube. Figure 2. Outline of a 3D cube (note the yellow lines).
  5. 5. A 3D coordinate system While those middle-school children probably don't realize it, they are already drawing in a 3D coordinate system. A 3D coordinate system is typically thought of as consisting of three axes where the angle between any pair of axes is ninety degrees. (In mathematical terminology, the axes are orthogonal.) Thus, the three axes are related to one another in the same way that any set of three edges that meet at a corner on the cube in Figure 1 are related to one another. The X, Y, and Z axes Scientists and engineers typically think of the three axes as the horizontal axis (often called X), the vertical axis (often called Y), and a third axis that is perpendicular to the plane formed by X and Y (often called Z). Don't worry, however, because Alice doesn't deal with X, Y, and Z axes. Rather, Alice deals with one axis that runs from left to right, a second axis that runs from bottom to top, and a third axis that runs from front to back. A man with one eye Going back to Figure 1, imagine that a man with one eye is inside the cube. His eye is located at the exact center of the cube and he is facing the inside surface of the medium blue panel. In other words, he is looking directly at the exact center of the medium blue panel with his one good eye. This causes the dark panel to be at his right. It also causes the light blue panel to form a ceiling above his head. A 3D coordinate system in this case would have its origin inside his eyeball. One axis would be sticking out directly in front of his eye (we will refer to this axis as the blue axis). A second axis would be sticking out to his right (we will refer to this axis as the red axis). A third axis would be sticking straight up from his eyeball (we will refer to this axis as the green axis). A picture of the 3D coordinate system described above Now look at Figure 2 and you will see the 3D coordinate system described above. The blue axis in Figure 2 is the axis that would be sticking out directly from the front of the man's eyeball. In fact, if you take a closer look at Figure 1, you can see that blue axis protruding slightly from the center of the medium blue panel.
  6. 6. Similarly, the red axis in Figure 2 is the axis that would be sticking out of the man's eyeball toward his right. Once again, a close examination of Figure 1 shows a small portion of that red axis protruding from the dark panel to the man's right. Finally, the green axis in Figure 2 is the axis that is sticking directly up from the man's eyeball. A small portion of that green axis can be seen protruding from the top panel of the cube in Figure 1. Memorize these colors Memorize these colors. In Alice, when you see a blue axis, it is protruding from the front of an object. When you see a red axis, it is protruding from the right side of an object and when you see a green axis, it is protruding from the top of an object. It is important to remember that the directions front/back, right/left, and up/down are relative to the viewpoint of the object, and not relative to the viewpoint of you the viewer. For example, once the object is drawn (rendered) in the world, the right/left, front/back, and up/down directions relative to the viewpoint of that object don't change. If I were to rotate the cube in Figure 1 so as to turn it "upside down", the green axis would then point downward, but that would still be the top of the cube relative to the cube's viewpoint. A penguin diving into the water As another example, I recently created an animation where a penguin walks over to a hole in the ice to dive in. When he arrives at the hole, the green axis is pointing out of the top of his head. He jumps up and rotates in the air (turns forward around his red axis) so that his feet are up and his head is down. At that point, the green arrow is still pointing out of the top of his head but now it points at the water below the penguin. I had to write code to move him "up" to make him fall "down" into the water. The object's center point As mentioned earlier, every object in the gallery has a center point and it may not be where you expect it to be. The center point is the origin where the three axes join with respect to that object's viewpoint. The case for the cube shown in Figure 1 and Figure 2 is straightforward. The center point of the cube is at the exact center of the cube. The center point for a penguin, on the other hand, is at a point in space on the ground midway between the penguin's feet. Many gallery objects have component parts To complicate matters even further, a penguin object is made up of five smaller component objects: • head • right leg • left leg • right wing • left wing Each of those component objects may contain other component objects. For example, the head contains the following component objects: • upper beak • lower beak Every component object has its own center point Because the right and left wings of a penguin object are themselves objects, it is possible for us to animate a penguin causing it to flap its wings independently of one another. We can do that by rotating each wing around one of its axes. However, in order for us to figure out how to do that, we must know where the center point is
  7. 7. for each wing and we must know what constitutes front, right, and up from the viewpoint of the wing. In other words, we must know the directions of the red, green, and blue axes relative to the center point of the wing. Turn and/or rotate As I explained earlier, if we tell a penguin or any other object, (such as a penguin's wing) to turn to the right or to the left, that object will rotate around the green axis that goes through the object's center point. If we tell an object to turn forward or backward, the object will rotate around the red axis that goes through that object's center point. Finally, if we tell an object to roll to the right or to the left, the object will rotate around the blue axis that goes through that object's center point. As you can see, in order to cause a penguin to flap a wing, we must know the position of the wing object's center point, and we must also know the directions of the red, green, and blue axes that go through the center point for that wing. An airplane example Now consider another example. Take a look at the airplane shown in Figure 3. Figure 3. An airplane with its 3D axes exposed. Suppose we wanted to animate the airplane to make it appear that it is flying in 3D space. Note that the green axis protrudes out of top of the airplane, the red axis protrudes out of the end of the right wing, and the blue axis protrudes out of the front of the airplane. These directions are respectively, up, right, and forward from the viewpoint of the pilot in the cockpit. Airplane motion is complex If we wanted to cause the animation to be realistic, we would need to combine at least two of the three possible rotations for each different type of airplane motion. For example, when an airplane turns to the right or to the left, it doesn't remain level from side to side. In more common terminology, the airplane banks, which is a
  8. 8. Make a right turn combination of yaw and roll. If we wanted to cause the airplane to make a right turn at the same altitude, we would tell the airplane to turn right. That would cause the airplane to rotate around the green axis. In airplane jargon, this is known as yaw. Dive toward the ground If we wanted the airplane to dive toward the ground, we would need to tell the airplane to turn forward. This would cause it to rotate around the red axis. In airplane jargon, this is known as pitch. Roll If we wanted the airplane to turn over and fly upside down, we would tell it to roll right or to roll left. That would cause it to rotate around its blue axis. In airplane jargon, this is known as roll. Roll, pitch, and yaw More on airplane motion In addition, an airplane always needs Thus, an object in 3D space can yaw, pitch, or roll, and can to be moving forward in order for the do any one of the three in either of two directions. wing surfaces to create lift and cause Therefore, the object can experience any combination of the the airplane to stay in the air. following three rotations: 1. yaw left or yaw right (it cannot yaw left and yaw right at the same time) 2. pitch down or pitch up (it cannot pitch down and pitch up at the same time) 3. roll left or roll right (it cannot roll left and roll right at the same time) Translation In addition to rotation about the three axes, an object can also move (translate): 1. forward or backward (but not both at the same time) 2. right or left (but not both at the same time) 3. up or down (but not both at the same time) Six degrees of freedom The combination of the three possible rotational motions and the three possible translational motions results in what is often called six degrees of freedom. Thus, Alice objects can be animated with six degrees of freedom (or more if you count the fact that the legs, arms, wings, etc., can experience independent rotation and/or translation while the object to which they belong is also experiencing rotation and/or translation). A little more discussion about the cube Now let's go back and discuss the cube a little more. The surface on which the cube is setting in Figure 1 and Figure 2 is also an object. Thus, it has a center point where its 3D axes join. The center point and the corresponding forward, right, and up axes are shown in Figure 4. (Remember, green is up, red is right, and blue is forward.) Figure 4. Center point of a surface.
  9. 9. Can be rotated and translated Just like any other object, the surface can be rotated around any of the three axes, and can be translated in three different directions. There is one major difference, however. If you roll the airplane in Figure 3, it will look like an upside-down airplane. It was created using artwork that was designed to be viewed from any direction in 3D space. The Alice surface shown in Figure 4, on the other hand, was not created with that in mind. Therefore, if you roll the surface, until you turn it upside down, the result won't be very pleasing. A partially transparent version of the cube The cube that you see in Figure 5 is the same cube that you saw in Figure 1. Figure 5. A partially transparent version of the cube.
  10. 10. However, in Figure 1, I caused the 3D axes belonging to the cube to be displayed. In Figure 5, I caused the 3D axes belonging to the surface on which the cube is setting to be displayed. In addition, the cube in Figure 1 is 100% opaque while the cube in Figure 5 is only 50% opaque. This makes it possible to see the 3D axes belonging to the surface showing through the cube. In other words, the cube in Figure 5 is 50-percent transparent. (Opacity and transparency are the reverse of one another.) An object's axes travel with the object Every object has a center point and has its own set of 3D axes. The center point and the 3D axes belonging to an object travel with and rotate with the object, independently of the other objects in the world. Thus, the 3D axes belonging to the penguin that I mentioned earlier traveled and rotated with him. When I caused him to turn forward one-half revolution in order to dive head-first into the water, this caused his green axis, which originally pointed up (from my viewpoint) to be pointing down (from my viewpoint) . As a result, I had to move him up to force him to fall down into the water head first. Animating component objects belonging to an object There is one other topic that I want to explain before we leave this lesson. I told you earlier that many Alice objects are composed of other objects and that every Alice object has six degrees of freedom. Even the smaller component objects that make up other objects have six degrees of freedom. However, it may not make sense to exercise all six in all cases. (In real life, an airplane cannot fly backwards, but a helicopter can fly backwards.) Consider a Coach object Consider, for example, the Coach object shown in Figure 6. Figure 6. A Coach object. The Coach object is actually made up of a large number of component objects, each of which has six degrees of freedom. Consider the left arm at the shoulder Let's consider just his left arm at the shoulder joint as shown in Figure 7.
  11. 11. Figure 7. Left arm of the Coach object. The coach looks like a headless ghost You may be wondering how I produced the image shown in Figure 7. To begin with, I repositioned the camera so that it would provide a better view of the center point on the left arm, which is what I wanted to see in detail. Then I made his head invisible just to get it out of the way. Then I set the opacity property of the upper body to 30-percent so that we can still see it for reference, but we can also see through it in order to see the shoulder joint. Finally, I caused the left arm to be rendered as a wireframe drawing instead of a solid drawing. This made it possible for us to see the center point of the left arm along with the 3D axes associated with that center point. Note the directions of the axes To begin our analysis, we recognize that the green axis is pointed up at this point. Similarly, the blue axis is pointing toward the front (from the coaches viewpoint), and the red axis is pointing into the coach's upper body toward his right side. Should we move his arm? Three of the motion possibilities having to do with six degrees of freedom involve movement or translation along those axes. We can quickly recognize, however, that if we move the arm along any of those axes without causing the coach's upper body to move at the same time, we will simply rip the coach's left arm off of his body. For example, Figure 8 shows the result of moving the arm a short distance to the left along the red axis. Figure 8. Left arm moved to the left.
  12. 12. Therefore, unless we are animating a torture chamber, the three translation possibilities available for the arm aren't very useful. Rotate around the green axis Another motion possibility is to rotate the arm around the green axis. If we turn the arm one-fourth of a revolution (90 degrees) to the right, the coach will be pointing to the front. That would be OK, as shown in Figure 9. Figure 9. Arm turned 90 degrees to the right. However, if we turn the arm to the left instead of the right, we can't turn it very far until we would put it in a position that is not possible for most humans. So, we would need to be careful as to the limits if we turn the arm to the right or to the left.
  13. 13. Rotate around the red axis We could turn the arm backwards so as to rotate it around the red axis by as much as one-half revolution (180 degrees) as shown in Figure 10. However, turning the arm backwards by more than this, or turning the arm forward by any amount at all would put the arm in an unnatural position. Figure 10. Arm turned backwards by 180 degrees. Rotate the arm around the blue axis That leaves us with two more possibilities. We can roll the arm to the left or to the right, thus causing it to rotate around the blue axis. For example, Figure 11 shows the arm rolled to the right by one-eighth of a revolution (45 degrees). Figure 11. Arm rolled right by 45 degrees.
  14. 14. As you can see, this caused the coach to lift his arm so as to point skyward. Difference between a right roll and a left roll The difference between a right roll and a left roll can be a little confusing. To avoid the confusion, don't think primarily in terms of what happens to the arm proper. Rather, think of what happens to the red axis. For example, a right roll around the blue axis will cause the red axis to tilt downward, just like a right roll in an airplane will cause the right wing to tilt downward. In the case of the coach's left arm, if the red axis tilts downward, then the arm proper, which protrudes in the opposite direction from the red axis will tilt upward. The grand finale It is important to note that when one of these turn or roll operations is performed, the arm's 3D axes travel or rotate with the arm. For example, the green axis no longer points straight up in Figure 11. As a result, we could follow the motion in Figure 11 by a turn to the right by 45 degrees (rotation around the new position of the green axis) and follow that by a turn backwards by 180 degrees (rotation around the new position of the red axis) resulting in the image shown in Figure 12. Figure 12. Arm point to the left and up with palm up. Note that I made all of the coach's body parts visible in Figure 12 so that we can see the new position of the left arm in the context of the entire body. In this case, the coach is pointing slightly upward and slightly to his left with his palm turned up. Summary In this lesson, I explained some of the concepts surrounding an object in 3D space in general, as well as some of the Alice-specific concepts surrounding an object in 3D space. For example, I explained the concept of an Alice center point and the color coding used by Alice for each of the three axes that intersect at the center point in an Alice object. I explained the concept of yaw, pitch, and roll and related them to the methods named turn and roll in Alice programming.
  15. 15. I explained that many of the objects in the Alice gallery are constructed from smaller component objects, and that every component object that is used to construct a larger object has its own center point and its own 3D coordinate system. I explained the meaning of the commonly used term "six degrees of freedom" and explained that every Alice object has six degrees of freedom. I also explained however, that it may not be realistic to exercise all six in a particular animation. I walked you through the fairly difficult procedure of applying motion to one of the arms belonging to a computer replica of a human while avoiding putting the arm in unnatural positions. What's next? In the next lesson, I will show you how to accomplish some of the moves, turns, and rolls that resulted in the images shown in this lesson. Resources • Dick Baldwin's website • Alice v2.0, Learn to Program Interactive 3D Graphics • Download Alice v2.0 • When Things Go Wrong • Alice v2.0 known bugs (04/05/2005) • 100 Learn to Program using Alice, Getting Started • 105 Learn to Program using Alice, Setting the Stage • 900 Appendix A, Behavior of Primitive Methods Lab project Create a new world, select the Snow template, and add an IceSkater object from the People thumbnail. Arrange the skater's limbs into the pose shown in Figure 13. In other words, Figure 13 shows what should appear in the World Running... pane when you Play your world. Note, however, that the World Running... pane is re-sizable so yours may be a different size. Hints: You may need to read ahead in the next lesson to learn about the camera controls and the object manipulator buttons. You may also need to check the box labeled affect subparts. Adjust the camera position and orientation (viewpoint) to approximate the image shown in Figure 13 when you manually resize your World Running... pane to approximately match the size of Figure 13. Figure 13. Final pose needed for lab project.
  16. 16. Save your world in a file named Alice110LabProj.a2w and be prepared to deliver it to your instructor in whatever manner the instructor specifies. Copyright Copyright 2007, Richard G. Baldwin. Faculty and staff of public and private non-profit educational institutions are granted a license to reproduce and to use this material for purposes consistent with the teaching process. This license does not extend to commercial ventures. Otherwise, reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited. About the author Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web. Richard has participated in numerous consulting projects and he frequently provides onsite training at the high- tech companies located in and around Austin, Texas. He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine. In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP). His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments. (TI is still a world leader in DSP.) In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics. Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems. Baldwin@DickBaldwin.com -end-

×