⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animationbase.cs

📁 非常优秀的棋牌类游戏源码包含AI及机器的难度调节算法人工智能非常经典
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SceneryComponent.Components.Animation
{
    /// <summary>
    /// Representa una rotaci髇 sobre un eje espec韋ico
    /// </summary>
    public class AnimationBase
    {
        // Indice del bone que se va a animar
        public readonly int Index = -1;
        // Nombre del bone que se va a animar
        public readonly string Name = null;

        // Bone que se va a animar
        private ModelBone m_Bone = null;
        // Transformaci髇 a aplicar al bone
        private Matrix m_Transform = Matrix.Identity;
        // Eje de sobre el que se realiza la rotaci髇
        private Vector3 m_Axis = Vector3.Up;
        // Rotaci髇
        private Quaternion m_Rotation = Quaternion.Identity;

        /// <summary>
        /// Obtiene la rotaci髇
        /// </summary>
        public Quaternion Rotation
        {
            get
            {
                return m_Rotation;
            }
        }
        /// <summary>
        /// Obtiene la transformaci髇
        /// </summary>
        public Matrix Transform
        {
            get
            {
                return m_Transform;
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bone">Bone que se va a animar</param>
        public AnimationBase(ModelBone bone)
        {
            if (bone != null)
            {
                this.m_Bone = bone;
                this.Name = m_Bone.Name;
                this.Index = m_Bone.Index;
            }
        }

        /// <summary>
        /// Actualiza la informaci髇 de rotaci髇
        /// </summary>
        /// <param name="gameTime">Tiempo de juego</param>
        public virtual void Update(GameTime gameTime)
        {
            // La matriz de transformaci髇 es la representaci髇 del quaternion
            m_Transform = Matrix.CreateFromQuaternion(m_Rotation);
        }
        /// <summary>
        /// Inicializa la animaci髇
        /// </summary>
        /// <param name="axis">Establece el eje de rotaci髇</param>
        public virtual void Initialize(Vector3 axis)
        {
            m_Axis = axis;
        }
        /// <summary>
        /// Reinicia la animaci髇 al origen
        /// </summary>
        public virtual void Reset()
        {
            m_Rotation = Quaternion.Identity;
        }
        /// <summary>
        /// Establece el 醤gulo de rotaci髇
        /// </summary>
        /// <param name="angle">羘gulo de rotaci髇</param>
        public virtual void SetRotationAngle(float angle)
        {
            m_Rotation = Quaternion.CreateFromAxisAngle(m_Axis, angle);
        }
        /// <summary>
        /// A馻de el 醤gulo a la rotaci髇
        /// </summary>
        /// <param name="angle">羘gulo a a馻dir a la rotaci髇</param>
        public virtual void Rotate(float angle)
        {
            m_Rotation *= Quaternion.CreateFromAxisAngle(m_Axis, angle);
        }
        /// <summary>
        /// Obtiene la representaci髇 en texto de la animaci髇
        /// </summary>
        /// <returns>Devuelve la representaci髇 en texto de la animaci髇</returns>
        public override string ToString()
        {
            string mask = "{0}:{1}";

            return string.Format(mask, this.GetType(), this.Name);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -