Learn to Program using Alice

Setting the Stage Manually, Part 1

Learn about the various ways that you can set the stage for an Alice program.  Learn how to start from scratch and begin to write a new program, including getting objects from the gallery and placing them in the world.  Learn how to use the object tree.  Learn how to use the camera controls and the object manipulator buttons.  Learn how to get a quad view of your world.

Published:  March 27, 2007
Last updated:  April 29, 2007
By Richard G. Baldwin

Alice Programming Notes # 115


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.

Have some fun

Because Alice is an interactive graphics 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.

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 earlier lesson titled "Objects in 3D Space" (see Resources), I taught you some of the general concepts as well as some of the Alice-specific concepts surrounding an object in 3D space.

I taught you about the center point and the color coding used for each of the axes in an Alice object, and I taught you about yaw, pitch, and roll and how they are accomplished in Alice programming by calling the methods named turn and roll.

I taught you that Alice objects are constructed from smaller component objects where every Alice object has its own 3D coordinate system.

I taught you how every Alice object has six degrees of freedom.

Finally, 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.

I promised that in this lesson, I would show you how to accomplish some of the moves, turns, and rolls that resulted in the images shown in that earlier 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.

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.

Preview

Three scenarios

I will describe three real-world scenarios by which a director and stage manager for a stage play or movie can set the stage.  I will relate those three ways to the ways that can be used to set the stage for an Alice program.  I will explain that Alice can be used to model only two of those three ways.

I will explain how some people may elect to manually arrange every aspect of the stage, including the locations and the poses of the actors.  I will also explain how other people may elect to manually create the actors, drop them onto the stage (the world), and then write the necessary code to move them to their correct locations, arrange their poses etc.  The use of either approach or a combination of the two is simply a matter of preference on the part of the programmer.

Writing a program

I will explain how to start from scratch and begin writing a new program, including two different ways to get objects from the gallery and place them in the world.  I will explain how to manipulate the object tree in order to obtain information about the makeup of each of the objects shown in the tree.

Camera controls and object manipulation buttons

I will introduce you to the camera controls and explain how to use them.  I will also introduce you to the object manipulator buttons and explain how to use them.  I will show you how to get a quad view of your world.

Discussion

The purpose of this discussion is to teach you how to set the stage for an Alice animation before you begin actually writing the program code.

I will begin by relating the possible approaches for setting the stage to the real world.  I will describe three real-world scenarios by which the director and the stage manager might elect to set the stage for a stage play or a movie.  (Please be aware, however, that these may not be realistic scenarios in the world in which we live.)

Scenario 1, treat the actors like smart manikins or automatons

In this scenario, the actors are like smart manikins, or automatons (see Resources).  In particular, the actors are not capable of transporting themselves from their dressing rooms to the stage, are not capable of moving to the correct location on the stage once they get there, and are not capable of arranging themselves into a prescribed pose.

Therefore, the stage manager must dress them, carry them from the dressing room to the stage, place them in the correct location on the stage, physically arrange their body parts in the correct poses, etc.  However, once the play actually begins, the actors are capable of following the script and performing their parts.

Scenario 2, treat the actors like smarter automatons

In this scenario, the actors are still not capable of transporting themselves from their dressing rooms to the stage.  However, they are capable of moving to the correct location on the stage once they get there, arranging themselves in a prescribed pose when instructed to do so, etc.  As before, once the play begins, the actors are capable of following the script and performing their parts.

Scenario 3, treat the actors like humans

In this scenario, the actors are capable of transporting themselves from their dressing rooms to the stage when instructed to do so.  They are capable of moving to the correct location on the stage, arranging themselves in a prescribed pose when instructed to do so, etc.  As before, once the play begins, the actors are capable of following the script and performing their parts.

How does this relate to Alice?

It is my understanding that Alice 2.0 is not capable of modeling scenario 3.  In particular, it is not possible to write Alice code that will go to the gallery (the dressing room) and instruct an actor (object) to materialize itself and go to the stage.  Rather, all of the actors (objects) that will appear at any point in the play must be manually created and transported to the stage at some point during the development of the program.

However, once all of the objects have been manually created and transported to the stage, they can be made invisible.  Then they can be caused to become visible at the appropriate point in the play.

What about the first two scenarios?

It is my understanding that Alice can model either or a combination of the first two scenarios described above.  For example, a person who is more inclined toward art than programming may elect to manually arrange every aspect of the stage, including the locations and the poses of the actors.

On the other hand, a person who is more inclined toward programming than art may elect to manually create the actors, drop them onto the stage (the world), and then write the necessary code to move them to their correct locations, arrange their poses, and to do everything else necessary to set the stage automatically after the program starts running and before the actors become visible.

Neither approach is right or wrong.  Either or a combination of the two approaches is totally valid.  The choice between them is simply a matter of preference on the part of the programmer.

Will emphasize the first scenario

In this lesson, I will teach you some of what you will need to know to model the first scenario.  Future lessons will teach you what you need to know to model the second scenario.  As mentioned earlier, the third scenario is not possible with Alice 2.0.

The Alice development environment

Let's get an overview by reviewing the Alice environment in scene edit mode as shown in Figure 1.

Figure 1. Alice environment in scene edit mode.

Sections of the Alice scene edit mode

As you learned in an earlier lesson, when in the scene edit mode, the Alice development screen can be divided into the following sections:

The menus and the button bar

We will use them in this lesson, but there is nothing special about them that is significantly different from most Windows programs.

The object tree

The large white section shown in the upper left of Figure 1 is often referred to as the object tree.

A bounding box
The yellow box surrounding the Coach object in Figure 1 is called a bounding box. When that box is visible, that means that the object has been selected either by clicking directly on the picture of the object or by clicking on the item that represents it in the object tree.
When you create a world, you begin with a background scene (such as the desert shown in Figure 1) and add various objects to that scene (such as the coach shown in Figure 1)As you add each object to the world, an item appears in the object tree that represents that object.  Later on, you can click on an item in the object tree to select that object for a variety of purposes.

The details section

The large white area in the bottom left of Figure 1 is often referred to as the details section.  When you select an object in either the object tree or in the world, this section provides a variety of different types of detailed information about that object.  This includes information about the properties, the methods, and the functions belonging to the object.

For the most part, this section is used when writing the program to animate the world.  However, sometimes an object's properties are manually set when setting the stage and that will be the case in this lesson. 

The gallery

The section with all of the pictures that covers the bottom center and bottom right in Figure 1 is called the gallery.  It has a horizontal scroll bar and therefore extends far to the right of what you see in Figure 1.

The gallery is where you go to construct objects to populate your world.  We will get an object from the gallery to populate our world in this lesson.

A coach in a desert
I have already added a Coach object to the world in Figure 1 so it shows a Coach object in the desert.  In other words, the world in Figure 1 has already been populated with a single Coach object.
The world section

Please direct your attention to the section near the top of Figure 1 that looks like a desert.  The desert is a picture of a world that is to be populated. 

The camera controls

You can think of your animated world as consisting of animated objects on a stage that is being photographed by a movie or TV camera.  The picture of your world is what you see when you look into the viewfinder on the camera.  There are two sets of camera controls, only one of which is showing in Figure 1.  The blue arrows near the center of Figure 1 are used to control the location and the orientation of the camera relative to the objects in the world.  I will explain how to use these controls in this lesson.

The other camera control is a slider that is hidden in Figure 1.  When needed, it can be exposed on the right in Figure 1 immediately above the green button by clicking the button labeled more controls.  This control is used to adjust the camera lens angle.  I will also explain how to use this control in this lesson.

The object manipulator buttons

For want of a better name, I will refer to the set of seven buttons in a row near the upper-right corner as object manipulator buttons.  Once you place an object in the world, you can select that object and manipulate it in a variety of ways using the mouse.  For example, you can make it larger or smaller.  You can drag it to the right, to the left, toward the viewer, away from the viewer, up, or down.  You can rotate it about any of three different axes.

By selecting one of the object manipulator buttons near the upper right, you select the family of behaviors that will result when you select an object and drag the mouse pointer in the vicinity of the selected object.  I will also provide a few examples of the use of these buttons in this lesson.

Starting from scratch

Now, let's start from scratch, create a new world, and perform a variety of manual operations to set the stage for an animated movie.  (I will defer the explanation of writing the code to animate the movie until a future lesson.)

Start the Alice program running

I am assuming that you have already installed the Alice software and are ready to use it.  If not, see the lesson titled "Learn to Program using Alice, Getting Started" in Resources.

When you start Alice running and the flash screen goes away, you should see a welcome screen that looks something like Figure 2.

Figure 2. The Alice welcome screen.

In case the Templates tab is not selected, the screen will look different from that shown in Figure 2.  In that case, select the Template tab to produce a screen similar to that shown in Figure 2.

Select a pre-designed background

The welcome screen shown in Figure 2 allows you to select a pre-designed background for your new world.  These backgrounds are rather plain.  You can dress them up later with hills, etc., if you want to.

Select the Sand template and click the Open button.

Click the green ADD OBJECTS button if need be to switch into scene edit mode.  When you do, your world should look very similar to Figure 1 except that the Coach object won't be there yet.

Save your world

Pull down the File menu and save your world in whatever directory with whatever name you prefer.  Don't enter an extension for the file name.  An extension of .a2w will be automatically added to the file name that you specify.  (Depending on how your Alice preferences are configured, you may be notified periodically that you need to save your world.)

Add an object from the gallery

Use the controls above the pictures in the gray area of the gallery in Figure 1 (if need be) to make certain that you are viewing the Local Gallery.

Scroll the gallery to the right and click on the tan rectangle (thumbnail) labeled People.

Scroll to the right if necessary to expose the gray rectangle labeled Class Coach.  This is the dressing room, so to speak, containing the definition for a class named Coach from which any number of 3D objects can be created that look like the coach in Figure 1.  We will only need one, but we could create two or more coaches if we were inclined to do so.

The Coach dialog

Click on the gray rectangle (thumbnail) labeled Class Coach.  The dialog shown in Figure 3 should appear on your screen.

Figure 3. Dialog describing the Coach object.

The dialog in Figure 3 gives us some information about a Coach object.  It shows us a picture of what he looks like.  It tells us that the object is composed of 13 separate body parts (component objects). This indicates that some rather sophisticated animation would be possible using this object.  It tells us the size of the object in terms of memory consumption in case that is something that we are concerned about.

Keep him or toss him

If we decide that a Coach object is not appropriate for the animated presentation that we are creating, we can simply click the Cancel button.  If we decide to add him to the cast, we can click the button labeled "Add instance to world."

Go ahead and add the Coach object to your new world.

Once you do that, your new world should look a lot like the world showing in Figure 1.  The coach will have been added to the world.  In addition, a new item labeled coach will have been added to the object tree in the upper-left on your development screen.

Manipulating the object tree

At this point, there are several things that you can do with the new item in your object tree.  For example, if you would prefer that this object be known by a different name, such as footballCoach, you could right-click the item in the object tree, select rename from the popup menu, and replace the name coach with a different name.

Go ahead and try it.  Rename the object to footballCoach.  Then rename it back to simply coach so that I don't have to type so much to refer to the object during the remainder of this lesson.

Exposing body parts

Something else that you can do with the object tree is to expose the body parts that were used to construct the coach.  The tree uses relatively standard plus and minus signs to expand and collapse the items in the tree.  Click on all of the plus signs to fully expose all of the body parts of the coach object.  The dialog shown in Figure 3 indicates 13 parts.  If you count, you will see that the number 13 consists of 12 individual parts plus the whole coach as shown in Figure 4.

Figure 4. Exposing the different parts of a Coach object.

Dragging boundaries in the development screen

By the way, you can use your mouse to drag the boundaries that separate the different sections of the Alice development environment in order to reallocate the available space among the different sections.  I had to increase the size of the object tree section to make everything fit in order to capture the screen shot of that section shown in Figure 4.

Collapse the object tree

We won't need access to all of the coach's body parts yet, so you can click on all the minus signs in the object tree to restore the coach to a single item.  We will expand it again later on an as-needed basis to expose the body parts that we need to see.

A shortcut for adding objects

When we added the coach to our world earlier, we went through a two-step process.  First we clicked the gray rectangle (thumbnail) to produce the dialog shown in Figure 3.  Then we clicked the button to add the object to the world.

If we already know that we want to add an object to the world and don't need to see the information in the dialog before adding it to the world, we can simply drag the object from the gallery and drop it into the world.

Go ahead and try it.  Find the mad scientist and drag him into your world.  Depending on where you drop him, the result should look similar to Figure 5.  Note that a new item labeled madScientist also appeared in the object tree.

Figure 5. Result of dragging the mad scientist into the world.

Delete the mad scientist

We really don't want a mad scientist in our world.  You can get rid of him by right-clicking on the picture of the mad scientist and selecting delete from the popup menu.  Or, you could right-click on his item in the object tree and select delete from that popup menu.  A third alternative is to drag his item from the object tree and drop it into the trash can shown near the top of Figure 1.  He does an interesting little dance before he actually disappears from the world.

At this point, your world should be back to the point that it looks very similar to Figure 1.

Using the camera controls

As I mentioned earlier, the picture of the world shown in Figure 1 can be thought of as what you would see when you look through the viewfinder on the camera.  This picture can be changed in several different ways:

  1. Change the position and orientation of the camera.
  2. Change the lens angle (a wider lens angle will let you see more of the world)
  3. Change the position and orientation of the objects in the world.

Let's begin our discussion of using the camera controls with the first item in the above listChanging the location and orientation of the camera is accomplished using the blue arrows that appear below the picture of the world in Figure 1.  A better view of those controls is shown in Figure 6.

Figure 6. View showing some of the manual camera controls.

Translation of the camera

The camera can be moved (translated) in either of six directions:

  1. up
  2. down
  3. left
  4. right
  5. forward
  6. backward

The four arrows on the left in Figure 6 are used to move the camera in the first four directions in the above list.  The direction of camera motion matches the directions pointed to by the arrows.

The arrows that point up and down in the middle group of four arrows in Figure 6 are used to move the camera forward and backward respectively.

Changing the orientation of the camera

With the camera located at a particular point in 3D space, its orientation can be changed by turning it in any of four directions:

  1. left
  2. right
  3. forward (tilt downward)
  4. backward (tilt upward)

The left and right arrows in the center group are used to turn the camera to the left and to the right respectively.  The top curved arrow on the far right is used to turn the camera forward, causing it to tilt downward.  The bottom curved arrow on the far right is used to turn the camera backward, causing it to tilt upward.

Clicking versus dragging

In all cases, you can either click on the arrow to move or turn the camera an incremental amount, or you can point to the arrow and hold the mouse button down to get a continuous motion.  If you drag the mouse pointer away from the arrow, you will increase the speed of the motion.

Rolling the camera

As near as I can tell, there are no arrows or other manual camera controls that make it possible to roll the camera.  However, it is possible to use program code in interactive mode to roll the camera producing a result similar to that shown in Figure 7.  (I will teach you how to use program code in interactive mode in a future lesson.)

Figure 7. Camera rolled ninety degrees (one-fourth revolution).

The Undo button

As you perform manual operations to set the stage, if you do something that you are not pleased with, you can reverse the process by clicking the Undo button shown in the button bar near the top of Figure 1.  Each time you click the button, you will reverse one operation.  I'm not certain how many successive operations you can undo, but if you don't encounter a numeric limit, you can continue clicking the Undo button until you have completely un-populated your world.  When you get back to that point, the Undo button will turn gray and will be disabled.

It's time to experiment

At this point, I recommend that you experiment with the blue arrow keys to manually move and turn the camera to get different views of the Coach object.  When you feel comfortable with the controls, see if you can accomplish the following.

Move the camera forward straight through the coach's belly until you emerge on the other side.  (You may need to use the other arrows to keep the camera aimed in the right direction.)  Continue moving the camera for a short distance after you emerge on the back side.  Then turn the camera to the left or the right until you can see the back of the coach similar to the view shown in Figure 8.

Figure 8. A view of the coach from behind.

Getting back to where you started

Then repeatedly click the Undo button until you get back to a front view similar to that shown in Figure 1.  If you are unable to accomplish that, scrap the program and start a new one to get to that point.

More controls

Now we are going to work with some of the controls shown in Figure 9.  These controls are shown in the upper right in Figure 1.

Figure 9. Controls for manipulating the object and the camera.

The bottom portion of Figure 9 shows the controls that you will see if you click the button labeled "more controls >>" on the right side of Figure 1.  To get back to the view shown in Figure 1, click the button labeled "fewer controls <<" in Figure 9.

Get a quad view

At any point along the way, you can click the radio button labeled quad view in Figure 9 to produce a view similar to that shown in Figure 10.

Figure 10. The quad view.

You can use the two radio buttons to switch back and forth between the quad view and the single view on an as-needed basis.

Two additional buttons

When you select the quad view, two additional buttons appear in the group of buttons near the top of Figure 9.  These two buttons provide two additional camera controls.  The effect of switching to quad view is as if you have three additional cameras available, one for the top right panel and one for each of the bottom panels in quad view(The top left panel in quad view is a reduced version of the main panel in single view.)  The two additional buttons mentioned above provide two controls for each of the new cameras.  These three cameras are independent of the main camera that is tied to the camera controls shown at the bottom of Figure 8.

One of the buttons has a picture of a hand on its face.  When you click that button, you can use the mouse in any of the three new quad view panels to move the camera to get a better look at an object. 

The other new button has a picture of a magnifying glass.  When you click that button, you can use the mouse in any of the three new quad view panels to zoom in to get a better look at an individual object, or zoom out to get a better look at the entire world.

Change the lens angle

The last camera control that I will discuss in this lesson is the lens angle slider.  You can use the handle on the slider shown in Figure 9 to continuously adjust the camera from one with a very wide-angle lens to one with a very narrow-angle lens.  You should experiment with this to become accustomed to the behavior.

Manipulating objects

That covers the first two items that I listed earlier regarding three ways to change the picture that you see in the camera's viewfinder.  Now I will begin the discussion of the third item in that list, which is to change the location and orientation of the objects in the world.

The object manipulator buttons

As I mentioned earlier, I will refer to the set of seven buttons in a row near the top of Figure 9 as object manipulator buttons.  Once you place an object in the world, you can select that object and manipulate it in a variety of ways using the mouse.

If you click a particular button and check the checkbox labeled affect subparts immediately below the buttons, you can select a body part, such as the coach's leftLeg, and manipulate it with the mouse.  For example, you can use this procedure to put the objects that have multiple parts into specific poses.  If the checkbox is not checked, whatever you do will be applied to the entire object.

Six faces and an arrow

When you hover your mouse pointer over one of the buttons, a tool tip will appear that explains the purpose of each button.  Take a minute to do that so you will be familiar with the purpose of each button.

As you will see in the tool tip, the button on the left with a picture of a mouse pointer on its face can be used for four different purposes, depending on which key you hold down while you move the mouse:

The best way to appreciate the capabilities provided by this button is to try it.  Use your mouse along with the shift and control keys to manipulate the coach object.

The operations that are enabled by pressing the left button and either one or both of the control and shift keys duplicates the operations assigned to three of the buttons with pictures on their face.

Changing the size of the object

The five buttons on the left end in Figure 9 all enable some sort of movement of the object.  The two buttons on the right end are different.  For example, if you click the second button from the right end, you can use your mouse to make the object larger or smaller.

Make copies of the object

If you click the rightmost button and then click the object, you will make a copy of the object.  Take a minute and try that.  Note that each time you click the object while the rightmost button is selected, a new copy is made.  The new object may hide the old object.  If so, you will need to click the leftmost button and use the mouse to drag and separate all of the copies of the object.

Experiment

Experiment with the camera controls and object manipulator buttons until you feel comfortable using them.  Then see if you can put the coach in a pose that looks like he may be showing someone how to kick a football as shown in Figure 11.  Sometimes it helps to turn the object before you attempt to tumble it into a particular pose.

Figure 11. Coach demonstrating how to kick a football.

Also experiment with the color property on the properties tab in the world's details section, along with the coach's upperBody object, his head, and each of his hands to cause the coach's shirt to be red instead of gray.

Summary

I described three real-world scenarios by which a director and stage manager for a stage play or movie can set the stage.  I related those three ways to the ways that can be used to set the stage for an Alice program and explained that Alice can be used to model only two of those three ways.

I explained that some people may elect to manually arrange every aspect of the stage, including the locations and the poses of the actors.  I explained that some other people may elect to manually create the actors, drop them onto the stage (the world), and then write the necessary code to move them to their correct locations, arrange their poses etc.  Neither approach is right or wrong.  The use of either approach or a combination of the two is simply a matter of preference on the part of the programmer.

I reviewed the purposes of the different sections of the Alice scene editor screen.

I explained how to start from scratch and begin writing a new program.  I explained two ways to get objects from the gallery and place them in the world.  I explained how to manipulate the object tree to obtain information about the makeup of each of the objects shown in the tree.

I introduced you to the camera controls and explained how to use them.  I also introduced you to the object manipulator buttons and explained how to use them.  I showed you how to get a quad view of your world, and how to use the two extra camera controls that appear when you select the quad view.

What's next?

In the next lesson, I will introduce you to methods.  Then I will show you how to use the methods in a semi-manual mode to set the stage without actually running the program.

Resources

Lab project

Create a new world, select the Sand template, and add a Coach object from the People thumbnail.

Modify the color properties of the various subparts of the Coach object to cause the coach to be wearing a red shirt as shown in Figure 11.

Arrange the coach's limbs into the pose shown in Figure 11.

Adjust the camera position and orientation (viewpoint) to approximate the image shown in Figure 11 when you manually resize your World Running... pane to approximately match the size of Figure 11.

Save your world in a file named Alice115LabProj.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-