/// <summary> /// Constructor /// </summary> /// <param name="data">The asset data for the custom animation.</param> public AvatarAnimationWrapper( CustomAvatarAnimationData data ) { animation = null; customAnimation = new CustomAvatarAnimation( data.Name, data.Length, data.Keyframes ); customAnimation.CurrentPosition = TimeSpan.Zero; customID = data.Name; }
/// <summary> /// Constructor. /// </summary> /// <param name="preset">The specified standard animation.</param> public AvatarAnimationWrapper( AvatarAnimationPreset preset ) { customAnimation = null; animation = new AvatarAnimation( preset ); animation.CurrentPosition = TimeSpan.Zero; standardID = preset; }
public Player(Gamer gamer) { AvatarDescription.BeginGetFromGamer(gamer, LoadGamerAvatar, null); PlayersName = gamer.Gamertag; CurrentAvatarAnimation = new AvatarAnimation(AvatarAnimationPreset.MaleIdleLookAround); Ship = new Ship(); NumberOfLives = 3; Level = 1; ScoreMultiplier = 1; SpeedMultiplier = 1; EnemyShipList = new EnemyShip[GameConstants.NumberOfEnemyShip]; BulletList = new Bullet[GameConstants.NumBullets]; LoadBulletList(); CurrentGameState = GameState.TitleScreen; ResetEnemyShips(); }
public CustomAvatarAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0); GameObjectService.Objects.Add(_cameraObject); // Create a random avatar. _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Wrap the Stand0 AvatarAnimationPreset (see WrappedAnimationSample) to create an // infinitely looping stand animation. AvatarAnimation standAnimationPreset = new AvatarAnimation(AvatarAnimationPreset.Stand0); TimelineGroup standAnimation = new TimelineGroup { new WrappedAvatarExpressionAnimation(standAnimationPreset), new WrappedAvatarSkeletonAnimation(standAnimationPreset), }; _standAnimation = new TimelineClip(standAnimation) { LoopBehavior = LoopBehavior.Cycle, // Cycle the Stand animation... Duration = TimeSpan.MaxValue, // ...forever. }; // Load animations from content pipeline. _faintAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Faint"); _jumpAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Jump"); _kickAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Kick"); _punchAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Punch"); // The walk cycle should loop: Put it into a timeline clip and set a // loop-behavior. TimelineGroup walkAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Walk"); _walkAnimation = new TimelineClip(walkAnimation) { LoopBehavior = LoopBehavior.Cycle, // Cycle the Walk animation... Duration = TimeSpan.MaxValue, // ...forever. }; }
public ITimeline WrapAnimation(AvatarAnimationPreset preset) { // Return a timeline group that contains one animation for the Expression and one // animation for the SkeletonPose. var avatarAnimation = new AvatarAnimation(_currentAvatarAnimationPreset); var expressionAnimation = new WrappedExpressionAnimation(avatarAnimation); var skeletonAnimation = new WrappedSkeletonAnimation(avatarAnimation); return new TimelineGroup { expressionAnimation, skeletonAnimation, }; }
public AdvancedAvatarRagdollSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // This sample uses for a DebugRenderer to draw text and rigid bodies. _debugRenderer = new DebugRenderer(GraphicsService, SpriteFont) { DefaultColor = Color.Black, DefaultTextPosition = new Vector2F(10), }; // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0); GameObjectService.Objects.Add(_cameraObject); // Add some objects which allow the user to interact with the rigid bodies. _grabObject = new GrabObject(Services); _ballShooterObject = new BallShooterObject(Services) { Speed = 20 }; GameObjectService.Objects.Add(_grabObject); GameObjectService.Objects.Add(_ballShooterObject); // Add some default force effects. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Create a random avatar. _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Use the "Wave" animation preset. var avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); _expressionAnimation = new AnimationClip<AvatarExpression>(new WrappedAvatarExpressionAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _skeletonAnimation = new AnimationClip<SkeletonPose>(new WrappedAvatarSkeletonAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Add a ground plane in the simulation. Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3F.UnitY, 0)) { MotionType = MotionType.Static }); // Distribute a few dynamic spheres and boxes across the landscape. SphereShape sphereShape = new SphereShape(0.3f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(sphereShape) { Pose = new Pose(position) }); } BoxShape boxShape = new BoxShape(0.6f, 0.6f, 0.6f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(boxShape) { Pose = new Pose(position) }); } }
void StateManager_ScreenStateChanged(object sender, EventArgs e) { if (Visible) { #if XBOX _elapsedAvatarRender = TimeSpan.Zero; hasrenderedavatar = false; avatarDesc = AvatarDescription.CreateRandom(); if (Gamer.SignedInGamers.Count > 0) { AvatarDescription.BeginGetFromGamer(Gamer.SignedInGamers[0], avatarRetrieved, null); } else { SignedInGamer.SignedIn += new EventHandler<SignedInEventArgs>(SignedInGamer_SignedIn); } avatarRenderer = new AvatarRenderer(avatarDesc, true); avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); avatarRenderer.World = Matrix.CreateRotationY(MathHelper.Pi); avatarRenderer.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, StateManager.GraphicsManager.GraphicsDevice.Viewport.AspectRatio, .01f, 200.0f); avatarRenderer.View = Matrix.CreateLookAt(new Vector3(0, 1, 3), new Vector3(0, 1, 0), Vector3.Up); #endif } }
protected override void LoadContent() { _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Use the "Wave" animation preset. var avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); _expressionAnimation = new AnimationClip<AvatarExpression>(new WrappedExpressionAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _skeletonAnimation = new AnimationClip<SkeletonPose>(new WrappedSkeletonAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Add a ground plane in the simulation. Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3F.UnitY, 0)) { MotionType = MotionType.Static }); // Distribute a few dynamic spheres and boxes across the landscape. SphereShape sphereShape = new SphereShape(0.3f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(sphereShape) { Pose = new Pose(position) }); } BoxShape boxShape = new BoxShape(0.6f, 0.6f, 0.6f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(boxShape) { Pose = new Pose(position) }); } base.LoadContent(); }
private static void BonesToWorldSpace(AvatarRenderer renderer, AvatarAnimation animation, List<Matrix> boneToUpdate) { IList<Matrix> bindPose = renderer.BindPose; IList<Matrix> animationPose = animation.BoneTransforms; IList<int> parentIndex = renderer.ParentBones; for (int i = 0; i < AvatarRenderer.BoneCount; i++) { Matrix parentMatrix = (parentIndex[i] != -1) ? boneToUpdate[parentIndex[i]] : renderer.World; boneToUpdate[i] = Matrix.Multiply(Matrix.Multiply(animationPose[i], bindPose[i]), parentMatrix); } }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); gameFont = content.Load<SpriteFont>("menufont"); square = content.Load<Texture2D>("square"); disc = content.Load<Texture2D>("disc"); gameplaybackground = content.Load<Texture2D>("gameplaybackground"); guy = content.Load<Texture2D>("guy"); blueguy = content.Load<Texture2D>("blueguy"); girl = content.Load<Texture2D>("girl"); pinkgirl = content.Load<Texture2D>("pinkgirl"); p0 = content.Load<Texture2D>("images/0"); p1 = content.Load<Texture2D>("images/1"); p2 = content.Load<Texture2D>("images/2"); p3 = content.Load<Texture2D>("images/3"); p4 = content.Load<Texture2D>("images/4"); p5 = content.Load<Texture2D>("images/5"); p6 = content.Load<Texture2D>("images/6"); p7 = content.Load<Texture2D>("images/7"); p8 = content.Load<Texture2D>("images/8"); p9 = content.Load<Texture2D>("images/9"); p10 = content.Load<Texture2D>("images/10"); p11 = content.Load<Texture2D>("images/11"); p12 = content.Load<Texture2D>("images/12"); p13 = content.Load<Texture2D>("images/13"); p14 = content.Load<Texture2D>("images/14"); p15 = content.Load<Texture2D>("images/15"); p16 = content.Load<Texture2D>("images/16"); p17 = content.Load<Texture2D>("images/17"); p18 = content.Load<Texture2D>("images/18"); p19 = content.Load<Texture2D>("images/19"); p20 = content.Load<Texture2D>("images/20"); p21 = content.Load<Texture2D>("images/21"); p22 = content.Load<Texture2D>("images/22"); p23 = content.Load<Texture2D>("images/23"); p24 = content.Load<Texture2D>("images/24"); p25 = content.Load<Texture2D>("images/25"); p26 = content.Load<Texture2D>("images/26"); p27 = content.Load<Texture2D>("images/27"); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); //MediaPlayer.Stop(); // stop current audio playback // generate a random valid index into Albums //int i = rand.Next(0, sampleMediaLibrary.Albums.Count - 1); spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice); //video = content.Load<Video>("xblcg"); //videoDimensions = new Vector2(video.Width, video.Height); //Avatar Stuff try { avatarDescription = Gamer.SignedInGamers[ControllingPlayer.Value].Avatar; } catch { avatarDescription = AvatarDescription.CreateRandom(); } if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); //avatar stuff // Create random avatar description and load the renderer and animation //avatarDescription = AvatarDescription.CreateRandom(); avatarRenderer = new AvatarRenderer(avatarDescription); // Load the preset animations waveAnimation = new AvatarAnimation(AvatarAnimationPreset.Clap); celebrateAnimation = new AvatarAnimation(AvatarAnimationPreset.Celebrate); standAnimation0 = new AvatarAnimation(AvatarAnimationPreset.MaleIdleShiftWeight); // Find the bone index values for the right arm and its children //rightArmBones = FindInfluencedBones(AvatarBone.ShoulderRight, // avatarRenderer.ParentBones); for (int i = 0; i < AvatarRenderer.BoneCount; ++i) { finalBoneTransforms.Add(Matrix.Identity); } // Initialize the rendering matrices world = Matrix.CreateRotationY(MathHelper.Pi); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, .01f, 200.0f); }
private ITimeline BakeAnimation(AvatarAnimation avatarAnimation) { // Create an AvatarExpression key frame animation that will be applied to the Expression // property of an AvatarPose. AvatarExpressionKeyFrameAnimation expressionAnimation = new AvatarExpressionKeyFrameAnimation { TargetProperty = "Expression" }; // Create a SkeletonPose key frame animation that will be applied to the SkeletonPose // property of an AvatarPose. SkeletonKeyFrameAnimation skeletonKeyFrameAnimation = new SkeletonKeyFrameAnimation { TargetProperty = "SkeletonPose" }; // In the next loop, we sample the original animation with 30 Hz and store the key frames. int numberOfKeyFrames = 0; AvatarExpression previousExpression = new AvatarExpression(); TimeSpan time = TimeSpan.Zero; TimeSpan length = avatarAnimation.Length; TimeSpan step = new TimeSpan(333333); // 1/30 seconds; while (true) { // Advance time in AvatarAnimation. avatarAnimation.CurrentPosition = time; // Add expression key frame if this is the first key frame or if the key frame is // different from the last key frame. AvatarExpression expression = avatarAnimation.Expression; if (time == TimeSpan.Zero || !expression.Equals(previousExpression)) expressionAnimation.KeyFrames.Add(new KeyFrame<AvatarExpression>(time, expression)); previousExpression = expression; // Convert bone transforms to SrtTransforms and add key frames to the SkeletonPose // animation. for (int i = 0; i < avatarAnimation.BoneTransforms.Count; i++) { SrtTransform boneTransform = SrtTransform.FromMatrix(avatarAnimation.BoneTransforms[i]); skeletonKeyFrameAnimation.AddKeyFrame(i, time, boneTransform); numberOfKeyFrames++; } // Abort if we have arrived at the end time. if (time == length) break; // Increase time. We check that we do not step over the end time. if (time + step > length) time = length; else time += step; } // Compress animation to save memory. float numberOfRemovedKeyFrames = skeletonKeyFrameAnimation.Compress(0.1f, 0.1f, 0.001f); Debug.WriteLine("Compression removed " + numberOfRemovedKeyFrames * 100 + "% of the key frames."); // Finalize the skeleton key frame animation. This optimizes the internal data structures. skeletonKeyFrameAnimation.Freeze(); return new TimelineGroup { expressionAnimation, skeletonKeyFrameAnimation, }; }
void TryLoadAvatar() { if (!Shorewood.presetAvatarAnimations.Keys.Contains<AvatarAnimationPreset>(AvatarAnimationPreset.Celebrate)) { Shorewood.presetAvatarAnimations.Add(AvatarAnimationPreset.Celebrate, new AvatarAnimation(AvatarAnimationPreset.Celebrate)); Shorewood.presetAvatarAnimations.Add(AvatarAnimationPreset.Clap, new AvatarAnimation(AvatarAnimationPreset.Clap)); } avatarDescription = AvatarDescription.CreateRandom(); // Load avatar animation information avatarAnimation = Shorewood.presetAvatarAnimations[AvatarAnimationPreset.Celebrate]; // Create new avatar Renderer avatarAnimation.CurrentPosition = TimeSpan.Zero; avatarRenderer = new AvatarRenderer(avatarDescription, false); }
protected override void LoadContent() { _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Wrap the Stand0 AvatarAnimationPreset (see WrappedAnimationSample) to create an // infinitely looping stand animation. AvatarAnimation standAnimationPreset = new AvatarAnimation(AvatarAnimationPreset.Stand0); TimelineGroup standAnimation = new TimelineGroup { new WrappedExpressionAnimation(standAnimationPreset), new WrappedSkeletonAnimation(standAnimationPreset), }; _standAnimation = new TimelineClip(standAnimation) { LoopBehavior = LoopBehavior.Cycle, // Cycle the Stand animation... Duration = TimeSpan.MaxValue, // ...forever. }; // Load animations from content pipeline. _faintAnimation = Game.Content.Load<TimelineGroup>("Faint"); _jumpAnimation = Game.Content.Load<TimelineGroup>("Jump"); _kickAnimation = Game.Content.Load<TimelineGroup>("Kick"); _punchAnimation = Game.Content.Load<TimelineGroup>("Punch"); // The walk cycle should loop: Put it into a timeline clip and set a // loop-behavior. TimelineGroup walkAnimation = Game.Content.Load<TimelineGroup>("Walk"); _walkAnimation = new TimelineClip(walkAnimation) { LoopBehavior = LoopBehavior.Cycle, // Cycle the Walk animation... Duration = TimeSpan.MaxValue, // ...forever. }; base.LoadContent(); }
private void CheckGameOver() { if (NumberOfLives == 0) { CurrentGameState = GameState.GameEnded; CurrentAvatarAnimation = new AvatarAnimation(AvatarAnimationPreset.FemaleCry); } }
public AvatarAnimationStreamControl(Microsoft.Xna.Framework.GamerServices.AvatarAnimationPreset animation, bool useExpression) { this.animationPreset = animation; this.animation = new Microsoft.Xna.Framework.GamerServices.AvatarAnimation(animation); this.useExpression = useExpression; }
/// <summary> /// Loads graphics content for this screen. The background texture is quite /// big, so we use our own local ContentManager to load it. This allows us /// to unload before going from the menus into the game itself, wheras if we /// used the shared ContentManager provided by the Game class, the content /// would remain loaded forever. /// </summary> public override void LoadContent() { try { avatarDescription = Gamer.SignedInGamers[ControllingPlayer.Value].Avatar; } catch { avatarDescription = AvatarDescription.CreateRandom(); } if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); //avatar stuff // Create random avatar description and load the renderer and animation //avatarDescription = AvatarDescription.CreateRandom(); avatarRenderer = new AvatarRenderer(avatarDescription); // Load the preset animations waveAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); celebrateAnimation = new AvatarAnimation(AvatarAnimationPreset.Celebrate); standAnimation0 = new AvatarAnimation(AvatarAnimationPreset.MaleIdleShiftWeight); // Find the bone index values for the right arm and its children //rightArmBones = FindInfluencedBones(AvatarBone.ShoulderRight, // avatarRenderer.ParentBones); for (int i = 0; i < AvatarRenderer.BoneCount; ++i) { finalBoneTransforms.Add(Matrix.Identity); } // Initialize the rendering matrices world = Matrix.CreateRotationY(MathHelper.Pi); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, .01f, 200.0f); }