public override void Update(GameTime gameTime) { GoToPosition(gameTime); if (Body.GetVelocity() == Vector2.Zero) { SourceRect = new Rectangle(0, 0, CurrentAnim.SpriteWidth, CurrentAnim.Animation.Height); } else { if (Force.Y < 0) { CurrentAnim = DownWalk; } if (Force.Y > 0) { CurrentAnim = UpWalk; } if (Force.X > 0) { CurrentAnim = RightWalk; } if (Force.X < 0) { CurrentAnim = LeftWalk; } SourceRect = CurrentAnim.Animate(gameTime, Delay); } }
public void Update(IUpdateArgs args, Matrix characterMatrix, Vector3 diffuseColor) { if (CurrentAnim == null && Animations.TryDequeue(out var animation)) { animation.Setup(); CurrentAnim = animation; } if (CurrentAnim != null) { CurrentAnim.Update(args.GameTime); if (CurrentAnim.IsFinished()) { CurrentAnim.Reset(); CurrentAnim = null; } } CharacterMatrix = characterMatrix; foreach (var part in Parts) { if (part.Effect != null) { part.Effect.DiffuseColor = diffuseColor; } if (!part.IsDirty) { continue; } _isDirty = true; part.Update(args); } foreach (var attachable in Attachables.ToArray()) { //attachable.R //attachable.Update(RotationMatrix); } if (_isDirty) { UpdateVertexBuffer(args.GraphicsDevice); } }
public void Update(IUpdateArgs args, Matrix characterMatrix, Vector3 diffuseColor, PlayerLocation modelLocation) { var device = args.GraphicsDevice; if (Effect == null) { Effect = new AlphaTestEffect(device); Effect.Texture = Texture; } else { if (CurrentAnim == null && Animations.TryDequeue(out var animation)) { animation.Setup(); animation.Start(); CurrentAnim = animation; } if (CurrentAnim != null) { CurrentAnim.Update(args.GameTime); if (CurrentAnim.IsFinished()) { CurrentAnim.Reset(); CurrentAnim = null; } } Matrix yawPitchMatrix = Matrix.Identity; if (ApplyHeadYaw || ApplyPitch) { var headYaw = ApplyHeadYaw ? MathUtils.ToRadians(-(modelLocation.HeadYaw - modelLocation.Yaw)) : 0f; var pitch = ApplyPitch ? MathUtils.ToRadians(modelLocation.Pitch) : 0f; yawPitchMatrix = Matrix.CreateTranslation(-EntityModelBone.Pivot) * Matrix.CreateFromYawPitchRoll(headYaw, pitch, 0f) * Matrix.CreateTranslation(EntityModelBone.Pivot); } var userRotationMatrix = Matrix.CreateTranslation(-EntityModelBone.Pivot) * Matrix.CreateRotationX(MathUtils.ToRadians(Rotation.X)) * Matrix.CreateRotationY(MathUtils.ToRadians(Rotation.Y)) * Matrix.CreateRotationZ(MathUtils.ToRadians(Rotation.Z)) * Matrix.CreateTranslation(EntityModelBone.Pivot); Effect.World = yawPitchMatrix * userRotationMatrix * DefaultMatrix * Matrix.CreateTranslation(_position) * characterMatrix; Effect.DiffuseColor = diffuseColor; var children = Children; if (children.Length > 0) { foreach (var child in children) { child.Update(args, userRotationMatrix * characterMatrix, diffuseColor, modelLocation); } } if (_isDirty) { UpdateVertexBuffer(args.GraphicsDevice); } } }
public void Update(IUpdateArgs args, Matrix characterMatrix, Vector3 diffuseColor, PlayerLocation modelLocation) { if (_disposed || Effect == null) { return; } //if (!Monitor.TryEnter(_disposeLock, 0)) // return; try { //var device = args.GraphicsDevice; if (CurrentAnim == null && Animations.TryDequeue(out var animation)) { animation.Setup(); animation.Start(); CurrentAnim = animation; } if (CurrentAnim != null) { CurrentAnim.Update(args.GameTime); if (CurrentAnim.IsFinished()) { CurrentAnim.Reset(); CurrentAnim = null; } } Matrix yawPitchMatrix = Matrix.Identity; var pivot = (Definition.Pivot ?? Vector3.Zero) * new Vector3(-1f, 1f, 1f); if (ApplyHeadYaw || ApplyPitch) { var headYaw = ApplyHeadYaw ? MathUtils.ToRadians(-(modelLocation.HeadYaw - modelLocation.Yaw)) : 0f; var pitch = ApplyPitch ? MathUtils.ToRadians(modelLocation.Pitch) : 0f; yawPitchMatrix = Matrix.CreateTranslation(-pivot) * Matrix.CreateFromYawPitchRoll(headYaw, pitch, 0f) * Matrix.CreateTranslation(pivot); } var userRotationMatrix = Matrix.CreateTranslation(-pivot) * Matrix.CreateRotationX(MathUtils.ToRadians(Rotation.X)) * Matrix.CreateRotationY(MathUtils.ToRadians(Rotation.Y)) * Matrix.CreateRotationZ(MathUtils.ToRadians(Rotation.Z)) * Matrix.CreateTranslation(pivot); var world = yawPitchMatrix * userRotationMatrix * DefaultMatrix * characterMatrix; var forward = world.Forward; var backward = world.Backward; var left = world.Left; var right = world.Right; world.Left = right; world.Right = left; // world.Forward = backward; //world.Backward = forward; Effect.World = world; Effect.DiffuseColor = diffuseColor; var children = Children.ToArray(); if (children.Length > 0) { foreach (var child in children) { child.Update(args, userRotationMatrix * characterMatrix, diffuseColor, modelLocation); } } //if (_isDirty || Indices.Length > Buffer.IndexCount) { UpdateVertexBuffer(args.GraphicsDevice); // _isDirty = false; } } finally { // Monitor.Exit(_disposeLock); } }
public void Update(IUpdateArgs args, MCMatrix characterMatrix) { if (_disposed) { return; } //if (!Monitor.TryEnter(_disposeLock, 0)) // return; try { //var device = args.GraphicsDevice; if (CurrentAnim == null && Animations.TryDequeue(out var animation)) { animation.Setup(); animation.Start(); CurrentAnim = animation; } if (CurrentAnim != null) { CurrentAnim.Update(args.GameTime); if (CurrentAnim.IsFinished()) { CurrentAnim.Reset(); CurrentAnim = null; } } if (Definition.Pivot.HasValue) { var pivot = (Definition.Pivot ?? Vector3.Zero); WorldMatrix = MCMatrix.CreateTranslation(-pivot) * MCMatrix.CreateRotationDegrees(BindingRotation + Rotation) * MCMatrix.CreateTranslation(pivot) * characterMatrix; } else { WorldMatrix = MCMatrix.CreateRotationDegrees(BindingRotation + Rotation) * characterMatrix; } var children = Children.ToArray(); if (children.Length > 0) { foreach (var child in children) { child.Update(args, WorldMatrix); } } } finally { // Monitor.Exit(_disposeLock); } }