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

📄 animationclamped.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髇 entre l韒ites
    /// </summary>
    public class AnimationClamped : AnimationBase
    {
        // 羘gulo inicial de la rotaci髇 en radianes
        private float m_RotationFrom = 0f;
        // 羘gulo final de la rotaci髇 en radianes
        private float m_RotationTo = 0f;
        // 羘gulo actual en radianes
        private float m_CurrentAngle = 0f;
        // Velocidad angular en radianes
        private float m_AngularVelocity = 0f;

        /// <summary>
        /// Indica si la rotaci髇 tiene l韒ites establecidos
        /// </summary>
        public bool HasLimits
        {
            get
            {
                return (m_RotationFrom != m_RotationTo);
            }
        }
        /// <summary>
        /// Indica si se ha alcanzado el inicio de la rotaci髇
        /// </summary>
        public bool RotationFromReached
        {
            get
            {
                if (HasLimits)
                {
                    return (m_RotationFrom == m_CurrentAngle);
                }

                return false;
            }
        }
        /// <summary>
        /// Indica si se ha alcanzado el final de la rotaci髇
        /// </summary>
        public bool RotationToReached
        {
            get
            {
                if (HasLimits)
                {
                    return (m_RotationTo == m_CurrentAngle);
                }

                return false;
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bone">Bone que se va a animar</param>
        public AnimationClamped(ModelBone bone)
            : base(bone)
        {

        }

        /// <summary>
        /// Actualiza los datos de animaci髇
        /// </summary>
        /// <param name="gameTime">Tiempo de juego</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            //Animaci髇 autom醫ica
            if (m_AngularVelocity != 0f)
            {
                this.Rotate(m_AngularVelocity);

                if (RotationFromReached || RotationToReached)
                {
                    m_AngularVelocity = 0f;
                }
            }
        }
        /// <summary>
        /// Inicializa la animaci髇
        /// </summary>
        /// <param name="axis">Eje de rotaci髇</param>
        /// <param name="angleFrom">羘gulo desde</param>
        /// <param name="angleTo">羘gulo hasta</param>
        public virtual void Initialize(Vector3 axis, float angleFrom, float angleTo)
        {
            base.Initialize(axis);

            m_RotationFrom = MathHelper.ToRadians(angleFrom);
            m_RotationTo = MathHelper.ToRadians(angleTo);
        }
        /// <summary>
        /// Reinicia la animaci髇
        /// </summary>
        public override void Reset()
        {
            base.Reset();

            m_CurrentAngle = 0f;
        }
        /// <summary>
        /// Establece el 醤gulo de rotaci髇 entre los l韒ites informados
        /// </summary>
        /// <param name="angle">羘gulo de rotaci髇</param>
        public override void SetRotationAngle(float angle)
        {
            // Cortar el 醤gulo si traspasa los l韒ites
            m_CurrentAngle = Clamp(angle);

            base.SetRotationAngle(m_CurrentAngle);
        }
        /// <summary>
        /// A馻de el 醤gulo a la rotaci髇 entre los l韒ites de rotaci髇
        /// </summary>
        /// <param name="angle">羘gulo de rotaci髇</param>
        public override void Rotate(float angle)
        {
            // A馻dir el 醤gulo
            m_CurrentAngle += angle;
            // Cortar el 醤gulo si est

⌨️ 快捷键说明

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