Animating your Iam
From AI Wiki
Animating your Iam is easy. All you have to do is call the following method
public void action(String animationID, double duration);
in your behavior class. For example, making the following call will make the Iam bow:
Actually, this code is for a female bow, but it looks more or less right in males as well. But where to find this actionID and the appropriate duration? Again, just like for dressing your Iam, initially we'll have to make do with a temporary solution. In the future we expect users to be able to design their own animations and give them to others or possibly sell them. Just like with clothes items. But for now we only have access to a fixed set of animations available to everyone. They are listed in the following XML file [ARAvatarAnimList.xml] Additionally, there's a helper class to lookup the animation IDs and their duration based on their name. So the previous example will actually in practice look more like the following:
AnimationManager manager = AnimationManager.getSingleton(); String animationID = manager.getID("AR_Bow-01"); double duration = manager.getDuration(animationID); action(animationID,duration);
This will perform the correct animation with the correct duration depending on whether your Iam is male or female. If you take a look in the XML file provided you'll see that there are a lot of animations that your Iam can perform already. But in the future you can expect many more animations to become available. Most likely some of these will have to be looked up dynamically on a server (and possibly checked if they've been paid for) but we'll do everything possible to ensure that this will all be taken care of by the AnimationManager class for you.
Also, since the code above is quite likely to be used very often, we've provided a convenience method called doAnimation(String animation). So the same as above could be accomplished by:
In Blue Mars there's also another type of animation called 'interaction'. These are basically synchronized animations between two avatars. Examples of these are: shaking hands, kissing, hugging, slapping and a few more. An important difference with simple animations is that instead of simply performing them, they need to be requested. And then they will only be executed if and when the other avatar agrees to it. The process is simple enough, you simply call the request() method to request for an interaction with another avatar. You will then receive a call on the receiveGrantAction() method that will notify you whether the other party accepted it or not. Conversely you can receive a request on the receiveRequestAction and then call the grant() method to notify whether your Iam accepts it or not. Whenever an interaction is accepted, both avatars perform the animation automatically, no explicit calls are required.
The request-ids for the interactions are in the same XML file as the other animations and can be looked up using the AnimationManager class. These animations come in pairs with suffixes -01 and -02. So for shaking hands for example you have "AR_ShakeHands-01" and "AR_ShakeHands-02" where the former is the animation played by the avatar requesting the interaction and the latter by the avatar accepting the request. To initiate the interaction you need to pass "ShakeHands" to the request() function. That function also needs a unique ID, the actual value of which is not so critical. It's mostly for reference to know which 'grant' refers to which 'request'. So in actual code, making a request looks something like this:
request(entityName, "ShakeHands", 1);
The system will do the rest of the work of matching the right animations synchronously so that you'll see two avatars shaking hands.