Tuesday, 21 February 2012

Character Animation


Using keyframePlayer

This tutorial assumes you have completed my others in the series. You'll need to start with characteranim.dir, which has the shockwave 3D cast member with animation in the form of movement in the legs and arms. I've also included another model, a hat, which you can see in the pic on the left.
1. Open the characteranim.dir movie, and open the scene control behavior. For now, we'll run through some code already added. 

At the top, you'll see:
  global gWearHat
  property pTofuBB, pHatBB
  property pCamera, pFlip

I have a global variable, gWearHat, which will define when the character is wearing the hat. Properties pTofuBB and pHatBB are the bounding boxes for the tofu character and hat models respectively. The pFlip variable is one that will flip the movement depending on which camera angle you' re using. 

Scroll down the behavior. In the beginSprite handler, we have:
  hat = pMember.model("hat")
Here we set the hat local variable to the related model.

After we've defined the hat model, we create a hat bounding box, starting with a model resource as follows.
  -- create tofu bounding box  tofuBB_MR = pMember.newModelResource("tofuBox",#box)
  tofuBB_MR.height = 25
  tofuBB_MR.width = 25
  tofuBB_MR.length = 50

  pTofuBB = pMember.newModel("tofuBox",tofuBB_MR)
The above numbers relate to the proportions of the tofu. If you were doing this with your own model, you' d need to keep track of the units in your 3D application. In my case, it was 3DS Max. You could create the bounding box in your 3D application to avoid the need to do it via Lingo as I have.

Next we have:
  pTofuBB.worldPosition = tofu.worldPosition
  
pTofuBB.worldPosition.z = 23
This locates the Tofu character Bounding Box in the scene. I moved the z co-ordinate up 23 units. Otherwise my character would sink through the ground. Again, doing this in the 3D application would have been simpler.

We then have:
  invisShader = pMember.newShader("invisShader",#standard)  invisShader.transparent = TRUE  invisShader.blend = 50  ptofuBB.shaderList = pMember.shader("invisShader")
The above creates a new shader that is meant to be invisible. I have set the blend to 50 so that we can see the bounding box (as seen in the pic). We'll change it to 0 later. The pic shows the bounding box (sphere) for the hat, which we'll create later.
2. We' re now going to create some parent child relationships.  You can read more about parent-child relationship in 3D at my The make-up of shockwave 3D casts page. Here' s a quick reason why we' re using this technique:

The primary benefit of these parent-child relationships is that they make it easier to move complex models around in the 3D world and to have the component parts of those models move together in the proper way.

Hopefully that will make sense in the context of this tutorial. After the line:
  -- create parent child relationships
insert
  ptofuBB.addChild(tofu, #preserveworld)  ptofuBB.addChild(pMember.model("armR"), #preserveWorld)  ptofuBB.addChild(pMember.model("armL"), #preserveWorld)  ptofuBB.addChild(pMember.model("legR"), #preserveWorld)  ptofuBB.addChild(pMember.model("legL"), #preserveWorld)

In the above code, we made the character bounding box the parent of a number of child models. In a parent child relationship, you can link multiple child objects to a parent but each child can only have one parent. The child objects are the tofu character, and the arms and legs.

3. Let's inspect some other code I have. 
  -- create hat bounding box  hatMR = pMember.newModelResource("hatSphere",#sphere)  hatMR.radius = 18  pHatBB = pMember.newModel("hatSphere", hatMR)  pHatBB.worldPosition = hat.worldPosition  pHatBB.shaderList = pMember.shader("invisShader")  pHatBB.addChild(hat, #preserveWorld)

By
 now, I' d hope the above would all make sense to you. So, I won' t say anything more.

4. You can scroll through the more code which should all be clear. Finally, you'll get to:
  -- set starting motion speed
Follow this statement with:
  pMember.model("armR").keyframePlayer.playRate = 0  pMember.model("armL").keyframePlayer.playRate = 0  pMember.model("legR").keyframePlayer.playRate = 0  pMember.model("legL").keyframePlayer.playRate = 0  pMember.registerForEvent(#timeMS,#SetCollision,me,2500,50,0)

The keyframe playRate is a property which defines how fast or slow to play back the keyframe motion. A value of 2 would double the speed, 0.5 would halve it. A value of 0, in our case, sets it to a paused state.

The keyframePlayer registers 2 events - #animationStarted and#animationEnded. And these can be used by handlers declared inregisterforEvent()
5. Scroll down to the keyDown handler and look though the code, which should all make sense. Note the statement:
  if keypressed(8) then changeCamera

This means that if the character c is pressed, the changeCamera custom message will be executed.

6. Scroll down to the changeCamera handler.
See the code:
  pCamera.rotate(0,0,180,pTofuBB)
  -- when the camera rotates 180, flip the arrow direction as well  pFlip = pFlip*-1 
What' s happening here is that the camera rotates 180 degrees and the pFlipvariable is multiplied to -1. pFlip will become negative it if was positive or positive if it was originally negative.

7. Scroll up to the keyUp handler. After the pDownArrow statement, add:

  pMember.model("armR").keyframePlayer.playRate = 0
  pMember.model("armL").keyframePlayer.playRate = 0  pMember.model("legR").keyframePlayer.playRate = 0  pMember.model("legL").keyframePlayer.playRate = 0
This sets the leg and arm movement to a paused state when the any key is released.

8. Scroll back up to the exitFrame handler, and at the start you'll seeSetMoving. This is the custom message to define the movement of the character when a key is pressed. Now scroll down to the SetMoving handler. 

At the start, insert the following code: 
  if pRightArrow then pTofuBB.rotate(0,0,-5*pFlip)  if pLeftArrow then pTofuBB.rotate(0,0,5*pFlip)
  if pUpArrow then
    pTofuBB.translate(0,-5*pFlip,0,#self)
    pMember.model("armR").keyframePlayer.playRate = 1
    pMember.model("armL").keyframePlayer.playRate = 1
    pMember.model("legR").keyframePlayer.playRate = 1
    pMember.model("legL").keyframePlayer.playRate = 1
  end if
  if pDownArrow then
    pTofuBB.translate(0,5*pFlip,0,#self)
    pMember.model("armR").keyframePlayer.playRate = 1
    pMember.model("armL").keyframePlayer.playRate = 1
    pMember.model("legR").keyframePlayer.playRate = 1
    pMember.model("legL").keyframePlayer.playRate = 1
  end if
When the up or down arrows are pressed, the playRate is set to 1 (normal speed). We also have a variable, pFlip, in the equation, which switches between positive and negative, as we saw earlier.

9. The code that you'll see in the rest of the SetMoving handler just moves the character up and down the terrain using the modelUnderRay technique. It is explained in the Terrain following tutorial.

10. Scroll down to the SetCollision handler. In here, I have code that uses themodelUnderRay technique to test when the character collides with objects. But I have included 2 bits of collision scripting. One collision detect will activatecheckObjectFoundDistance, the other checkForCollision.checkForCollision is exactly as described in the collision detection tutorial.checkObjectFoundDistance is what' s used for finding the hat.

11. Scroll down to checkObjectFoundDistance handler. Here we check the distance from the starting point of the ray to the hat and if the distance represents a collision, gWearHat becomes TRUE.

12. Scroll backup to the exitFrame handler. After the SetMoving statement add:
  if gWearHat = TRUE then
    ptofuBB.addChild(pHatBB,#preserveParent)
    pHatBB.worldPosition = pTofuBB.worldPosition
    pHatBB.worldPosition.z = 87    gWearHat = FALSE
  end if
Following the result of step 11, we now have gWearHat being TRUE and so we make changes accordingly. The hat bounding box is made a child of the character bounding box so that when the character walks, the hat will not be left behind. We change the world position of the hat to correspond to the bounding box of the tofu character. Then we move the hat up 87 along the z axis so it sits on the character' s head. We must set gWearHat back to FALSE otherwise theif gWearHat = TRUE will be put into a infinite loop. The variable can' t be set back to TRUE since the ray that was created to detect the hat is downwards below the character' s head.

13. Now it's time to play the movie and see how it all works. Notice the bounding boxes. To make them completely invisible, change the blend to 0. This was referred to at the end of step 1 just before step 2. 

Another thing to note is that when you press c, you can toggle between a camera looking from behind and in front. But, no matter what camera view you're using, the up arrow will always move the character up the screen, down arrow will move it down. You can download the completed movie from here

If you're wondering why I used a global variable for gWearHat (it could have worked as a property variable like the others used), you can email me or check back this page in the near future as there is a planned addition. 

How the legs and arms were set up in 3DS Max
In Max, the arms and legs were animated as individual objects in a keyframed manner. Lingo made them a child to the body. Often, character animation is created using mesh deformation using a skelteton or bones hierachy. For more info on biped and bones animation setup in Max, look at the Preparing 3D content for Shockwave 3D technote (for general info) and the Character Animation for Shockwave 3D article (detailed info).

Editing Information in a Cell


Information in a spreadsheet is likely to change over time. Information can be changed in either of two ways.
Quick and Easy Method:

Click the cell that contains the information to be changed.
Type the new entry. The old entry is replaced by the new entry.
If the original entry is long and requires only a minor adjustment (in spelling, for example), then you can directly edit the information in the cell.
To Edit Information in a Cell:

Method 1: Direct Cell Editing
Double-click on the cell that contains the information to be changed.
The cell is opened for direct editing.



Make the necessary corrections.

Press Enter or click the Enter button on the Formula bar  to complete the entry.

Method 2: Formula Bar Editing
Click the cell that contains the information to be changed.
Edit the entry in the formula bar.

HTML Meta tags - Keyword - Refresh - Redirect

Meta tags are generally used to include information about a document such as author name, creation date, copyright information etc. They always placed between the <HEAD> tags of an HTML document.
Each Meta tag has two important attributes:
  • HTTP-EQUIV or NAME
  • CONTENT
<META HTTP-EQUIV="some_name" CONTENT="some_content">

OR

<META NAME="some_name" CONTENT="some_content">

<META HTTP-EQUIV>

The HTTP-EQUIV attribute takes one of the values mentioned below:
  • CONTENT-TYPE: The most commonly used content type is text/html. Other types can be employed to include the character set for the document. This helps the browser to load the appropriate character before document display.
  • EXPIRES: Specifies the date and time after which a document should be considered expired. This can be used by web robots update content in a search engine.
  • CACHE-CONTROL: Determines the caching of the document.
  • CONTENT-LANGUAGE: Used to specify the language in which the document is written.
  • REFRESH: This value is commonly used to either redirect users to a different page or refresh the contents of the present page.
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html">
<META HTTP-EQUIV="EXPIRES" CONTENT="May 1, 2002 00:00:00 EST">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="no-cache">
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="hi">
<META HTTP-EQUIV="REFRESH" CONTENT="5">
Note that all the META tags with HTTP-EQUIV attributes also contain the CONTENT attribute.
The HTTP-EQUIV="REFRESH" demands more attention here, so let us have a detailed look at it.
The tag above simply refreshes the contents of the page in 5 seconds. However, you can supply a URL to this tag, which redirects users to that page.
<META HTTP-EQUIV="REFRESH" CONTENT="2; URL=new.html">
This takes the user to new.html after 2 seconds.
Note that there is only one set of quotes that encloses the content of CONTENT. Both the time in seconds and the URL are inside the same quotes.
A cheap trick is to construct a looping (or non-looping) slide show making use of these tags. Let's say you have three html pages named slide1.html,slide2.html and slide3.html. You can make a looping slide show by including the appropriate META tag in each document.
slide1.html contains
<META HTTP-EQUIV="REFRESH" CONTENT="10; URL=slide2.html">

slide2.html contains
<META HTTP-EQUIV="REFRESH" CONTENT="10; URL=slide3.html">

slide3.html contains
<META HTTP-EQUIV="REFRESH" CONTENT="10; URL=slide1.html">
To start the slide-show, load slide1.html in the browser. After 10 seconds,slide1.html is replaced by slide2.html, which is again replaced by slide3.htmlafter 10 seconds. Finally, after another 10 seconds, slide1.html replacesslide3.html and thus, the slide-show keeps on looping. Note that the <META> tag is placed in the head section of each document.

<META NAME>

Though there are some fixed values for the NAME attribute, you can construct your own meta tags with it. Let's look at the important values
  • KEYWORDS: You can supply keywords for your pages using this. It helps in indexing by search engines. Takes a list of comma separated keywords.
  • COPYRIGHT: Contains copyright information
  • DESCRIPTION: lets you specify a description of the page.
  • AUTHOR: You can write your name here.
  • ROBOTS: This tag is used to stop your pages from being indexed by robots. Its an alternative to the robots.txt file.
<META NAME="KEYWORDS" CONTENT="movies, hollywood, actors">
<META NAME="COPYRIGHT" CONTENT="2001, Some_Company_Name">
<META NAME="DESCRIPTION" CONTENT="Information on the greatest 
movies ever">
<META NAME="AUTHOR" CONTENT="your_name">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

Add a Text Box to a PowerPoint slide

The next thing we'll do is add some text below the image we inserted onto the previous slide. In PowerPoint, you can't just start typing text where you please. It needs to go into a text box. You can then move the text box around the screen, and position your text where you want it.
To add a new text box to your slide, click Insert from the menu bar at the top. From the Insert menu, click Text Box:
Insert > Text Box menu
When you click on Text Box from the menu, you won't see anything happen. That's because text boxes need to be drawn on to the slide.
So move your mouse pointer over to you slide, just below your image. The pointer will change shape to a slim white arrow:
The Text Box Pointer
Hold down you left mouse button. Keep it held down and drag:
Drag out a new Text Box
When your text box is about the same width as your image, let go of the left mouse button. Your text box will then look like this in PowerPoint 2000:
The New Text Box in PowerPoint
And this in PowerPoint 2003:
PowerPoint 2003 Text Box
The white line is the cursor, waiting for you to type some text. So go ahead and type the following into your text box:
The Start of the AutoContent Wizard
When you're done, your text box should like this:
Type your text
The font itself is different from the one we used for the titles. The title font was Arial Narrow; this is Times New Roman. To change the properties of the font, first highlight all of your text. It should turn white:
Highlight the Text
With the text highlighted, click Format > Font from the menu bar at the top of PowerPoint:
The Format > Font menu
When you click on Font, you'll see the following dialogue box appear:
The Font dialogue box
As you can see, the font is Times New Roman, the font style is Regular, and the Size is 24. Change the font to Arial Narrow, and keep the other two values the same:
Change your Font
You can also change the colour of the font. Click the black arrow on the Colour dropdown list:
Add a Font colour
Select the light yellow colour, which is the same as the Title colour we have. When you're done, click the OK button at the bottom of the dialogue box.
The formatted text
The text box above looks a little too wide, though. You can resize the text box by holding your left mouse button down on one of the white square (or round) sizing handles. The mouse pointer will change shape:
Resize the Text Box
Keep your left mouse button held down, and then drag to the left to make the text box narrower, or to the right to make it wider
Make it wider
Let go of your left mouse button when you are happy with the size. (You can also make the text box higher. Use the same technique to drag the top-middle white square or circle upwards.)
To move the text box to a new position, hold you mouse pointer over the shaded edges of the text box. Again, the mouse pointer will change shape:
Move a Text Box
The image above shows the Move pointer. When you see this pointer, hold down your left mouse button. Keep it held down and drag your text box to a new location.
But your Slide 3 should now look like this:

Have a look at your slideshow so far by pressing F5. See if slide 3 looks OK.

Add an Image to a PowerPoint Slide

On the next four slides, we'll have an image and a text box. The images will be the four steps of the Wizard, and the text box will contain a brief description of what the wizard is doing. You can find the images for this presentation by clicking the link below:
Presentation Images
Download the ZIP file on the resources page, and you'll find all the images for this PowerPoint course in separate folders. The images you need are in thepresentation1 folder.
The first thing we need to do is to delete the text box that's holding the bullets. So, from the Outline View on the left, click on slide 3 to highlight it. The "AutoContent Wizard - Step One" slide should display on the main stage:
Click anywhere inside the bulleted list, like you did previously. The outline of the text box should be showing. Click on the text box outline, and then press the Delete key on your keyboard twice. The text box and its contents should then vanish.
Now we can insert an Image in place of the bulleted list. To insert an image on to slide 3, click Insert > Picture from the PowerPoint menu bar at the top. The Picture submenu should display:
The Insert > Picture menu in PowerPoint
The one we want is From File. But note the other picture options you have: Clip Art, AutoShapes, Organization Chart, Word Art, From Scanner or Camera, and Word Table. We'll see a few of these in action in later chapters. But for now, click on From File. When you do, you'll see an Insert dialogue box appear:
The Insert Picture Dialogue Box
From the "Look in" dropdown list at the top, navigate to where on your hard drive you saved your downloaded images files to. Locate the image calledautoContentWizardStep1.jpg. Click on this to highlight it, and then click the Insert button in the bottom right. The picture will appear on your slide 3. Your slide should now look like ours below:
The Image is now on slide 3

Resize and Move an Image

The picture looks a bit big for the slide, and there's not much room for the text we want to add. To resize the image, make sure the image is selected. If it is, you'll see white squares or circles around the edges, as in the previous image.
With the image selected, click it with the right mouse button. You'll then see the following menu:
The Format Picture menu
Click on Format Picture, and you'll see the following dialogue box appear:
The Format Picture dialogue box
This is not the Tab we want, so click the Size tab to see the following settings:
Click the Size tab
Make sure there's a tick in the box that says Lock aspect ratio. If there's a tick in this box, when you change the height, the width will change automatically to match. That way, you don't end up with an odd-shaped image.
On the Size tab, change the Scale > Height from 100% to 80%. You'll see the other values change by themselves. Click the Preview button at the bottom to see what the image looks like at this size. If you're happy with the size of your image, click OK.
To move your image, click on it with your left mouse button. Hold the left button down and drag to a new location. Aim for something like ours below:
What your Slide 3 should look like
In the next part, you'll see how to add a text box just below the image.