Esempio n. 1
0
        private void CheckMovingAnimation(ref Vector3D previousPosition, ref Vector3D currentPosition, double threshold)
        {
            var    distanceSquared = Vector3D.DistanceSquared(previousPosition, currentPosition);
            string animationFrameName;

            switch (this.DynamicEntity.DisplacementMode)
            {
            case EntityDisplacementModes.Flying:
            case EntityDisplacementModes.Dead:
                animationFrameName = "Flying";
                break;

            case EntityDisplacementModes.Walking:
                animationFrameName = "Walk";
                break;

            case EntityDisplacementModes.Swiming:
                animationFrameName = "Walk";
                break;

            case EntityDisplacementModes.FreeFlying:
                animationFrameName = "Flying";
                break;

            case EntityDisplacementModes.God:
                animationFrameName = "Flying";
                break;

            default:
                animationFrameName = "Walk";
                break;
            }

            //Activate / deactivate Model Playing animation
            if (_moving && distanceSquared < threshold)
            {
                if (ModelInstance != null)
                {
                    ModelInstance.Stop(animationFrameName);
                }
                _moving = false;
            }

            if (!_moving && distanceSquared >= threshold)
            {
                if (ModelInstance != null)
                {
                    ModelInstance.TryPlay(animationFrameName, true);
                }
                _moving = true;
            }
        }