Rendering and Animating Avatars (Xbox 360)
|Avatar-related APIs are exposed on Windows to ease cross-platform development between Windows and Xbox 360. By design, all avatar-related methods return default values, and rendering methods do not draw anything on the screen.|
The code in this topic shows you the technique for rendering and animating a gamer's avatar. Use IAvatarAnimation if you want to integrate custom avatar animations with standard animations. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
To render a random model with a standard animation
Initialize the gamer services dispatcher for your application.
For more information, see Initializing and Updating Gamer Services.
Declare three new members in your main game class to store the various objects needed to render and animate the random avatar.
Because the avatar gender is unknown at the time of rendering, for this example use the gender-neutral clap animation.
Note Gender-specific animations work with any avatar, but each is designed with the proportions of that gender in mind. This prevents the avatar model from clipping through itself during the animation cycle.
avatarRenderer.World = Matrix.CreateRotationY(MathHelper.ToRadians(180.0f)); avatarRenderer.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), GraphicsDevice.Viewport.AspectRatio, .01f, 200.0f); avatarRenderer.View = Matrix.CreateLookAt(new Vector3(0, 1, 3), new Vector3(0, 1, 0), Vector3.Up);
Note The values used in this example are for demonstration purposes only. Although they provide a good location and orientation for the camera (in terms of this sample), your application will require different values, which are determined by your application's needs.
Make any necessary modifications to the current values of the avatar's ambient light and directional light properties by using the similarly-named properties of the
avatarobject (for example, AvatarRenderer.AmbientLightColor).
Update the current animation of the avatar.
The recommended place for this code is within the Update method of your application.
When you render the avatar, keep in mind that various parts (for example, glasses) of the avatar model can be transparent. Transparent parts are rendered with the depth buffer disabled. For this reason, first render all opaque objects (except the avatar) in the scene, and then render the avatar and any other transparent objects sorted by depth (from back to front).