30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

744 Graphics and Multimedia Chapter 16<br />

Lines 55–59 disable txtLocation and enable the rest of the controls. Lines 62–64<br />

set Genie as the default character, obtain all animation names via method GetAnimationNames<br />

and then call IAgentCtlCharacter method Show <strong>to</strong> display the character.<br />

We access characters through property Characters of mainAgent, which<br />

contains all characters that have been loaded. We use the indexer of the Characters<br />

property <strong>to</strong> specify the name of the character that we wish <strong>to</strong> load (Genie).<br />

When a user clicks the character (i.e., pokes it with the mouse), event handler<br />

mainAgent_ClickEvent (lines 93–100) executes. First, mSpeaker method Play<br />

plays an animation. This method accepts as an argument a String representing one of the<br />

predefined animations for the character (a list of animations for each character is available<br />

at the Microsoft Agent Web site; each character provides over 70 animations). In our<br />

example, the argument <strong>to</strong> Play is "Confused"—this animation is defined for all four<br />

characters, each of which expresses this emotion in a unique way. The character then<br />

speaks, "Why are you poking me?" via a call <strong>to</strong> method Speak. Finally, the Rest-<br />

Pose animation is played, which returns the character <strong>to</strong> its neutral, resting pose.<br />

The list of valid commands for a character is contained in the Commands property of<br />

the IAgentCtlCharacter object (mSpeaker, in this example). The commands for an<br />

Agent character can be viewed in the Commands pop-up window, which displays when<br />

the user right-clicks an Agent character (the last screenshot in Fig. 16.37). Method Add of<br />

the Commands property adds a new command <strong>to</strong> the command list. Method Add takes<br />

three String arguments and two Boolean arguments. The first String argument identifies<br />

the name of the command, which we use <strong>to</strong> identify the command programmatically.<br />

The second String is optional and defines the command name as it appears in the Commands<br />

pop-up window. The third String also is optional and defines the voice input<br />

that triggers the command. The first Boolean specifies whether the command is active,<br />

and the second Boolean indicates whether the command is visible in the Commands<br />

pop-up window. A command is triggered when the user selects the command from the<br />

Commands pop-up window or speaks the voice input in<strong>to</strong> a microphone. Command logic<br />

is handled in the Command event of the AxAgent control (mainAgent, in this example).<br />

In addition, Agent defines several global commands that have predefined functions (for<br />

example, speaking a character name causes that character <strong>to</strong> appear).<br />

Method GetAnimationNames (lines 119–154) fills the actionsCombo<br />

ComboBox with the current character’s animation listing and defines the valid commands<br />

that can be used with the character. The method contains a SyncLock block <strong>to</strong> prevent<br />

errors resulting from rapid character changes. The method obtains the current character’s<br />

animations as an enumera<strong>to</strong>r (125–127), then clears the existing items in the ComboBox<br />

and character’s Commands property. Lines 136–147 iterate through all items in the animation<br />

name enumera<strong>to</strong>r. For each animation, in line 139, we assign the animation name <strong>to</strong><br />

String voiceString. Line 140 removes any underscore characters (_) and replaces<br />

them with the String "underscore"; this changes the String so that a user can pronounce<br />

and employ it as a command activa<strong>to</strong>r. The Add method (lines 145–146) of the<br />

Commands property adds a new command <strong>to</strong> the current character. The Add method adds<br />

all animations as commands by providing the following arguments: the animation name as<br />

the new command’s name and voiceString for the voice activation String. The<br />

method’s Boolean arguments enable the command, but make it unavailable in the Commands<br />

pop-up window. Thus, the command can be activated only by voice input. Lines

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!