Ejemplo n.º 1
0
        private int seekRightKeyFrame(int aboveFrameNumber, ShapeElement forElement, int forFlag)
        {
            int firstIndex = -1;

            for (int i = 0; i < KeyFrames.Length; i++)
            {
                AnimationKeyFrame keyframe = KeyFrames[i];

                AnimationKeyFrameElement kelem = keyframe.GetKeyFrameElement(forElement);
                if (kelem != null && kelem.IsSet(forFlag))
                {
                    if (firstIndex == -1)
                    {
                        firstIndex = i;
                    }
                    if (keyframe.Frame <= aboveFrameNumber)
                    {
                        continue;
                    }

                    return(i);
                }
            }

            return(firstIndex);
        }
Ejemplo n.º 2
0
        protected void lerpKeyFrameElement(AnimationKeyFrameElement prev, AnimationKeyFrameElement next, int forFlag, float t, ref ElementPose transform)
        {
            if (prev == null && next == null)
            {
                return;
            }

            t = GameMath.SmoothStep(t);

            // Applies the transforms in model space
            if (forFlag == 0)
            {
                transform.translateX = GameMath.Lerp((float)prev.OffsetX / 16f, (float)next.OffsetX / 16f, t);
                transform.translateY = GameMath.Lerp((float)prev.OffsetY / 16f, (float)next.OffsetY / 16f, t);
                transform.translateZ = GameMath.Lerp((float)prev.OffsetZ / 16f, (float)next.OffsetZ / 16f, t);
            }
            else if (forFlag == 1)
            {
                transform.degX = GameMath.Lerp((float)prev.RotationX, (float)next.RotationX, t);
                transform.degY = GameMath.Lerp((float)prev.RotationY, (float)next.RotationY, t);
                transform.degZ = GameMath.Lerp((float)prev.RotationZ, (float)next.RotationZ, t);
            }
            else
            {
                transform.scaleX = GameMath.Lerp((float)prev.StretchX, (float)next.StretchX, t);
                transform.scaleY = GameMath.Lerp((float)prev.StretchY, (float)next.StretchY, t);
                transform.scaleZ = GameMath.Lerp((float)prev.StretchZ, (float)next.StretchZ, t);
            }
        }
Ejemplo n.º 3
0
        internal AnimationKeyFrameElement GetKeyFrameElement(ShapeElement forElem)
        {
            if (forElem == null)
            {
                return(null);
            }
            AnimationKeyFrameElement kelem = null;

            ElementsByShapeElement.TryGetValue(forElem, out kelem);
            return(kelem);
        }
Ejemplo n.º 4
0
        private int seekLeftKeyFrame(int leftOfKeyFrameIndex, ShapeElement forElement, int forFlag)
        {
            for (int i = 0; i < KeyFrames.Length; i++)
            {
                int index = GameMath.Mod(leftOfKeyFrameIndex - i - 1, KeyFrames.Length);
                AnimationKeyFrame keyframe = KeyFrames[index];

                AnimationKeyFrameElement kelem = keyframe.GetKeyFrameElement(forElement);
                if (kelem != null && kelem.IsSet(forFlag))
                {
                    return(index);
                }
            }

            return(-1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resolves the keyframe animation for which elements are important.
        /// </summary>
        /// <param name="anim"></param>
        /// <param name="allElements"></param>
        public void Resolve(Animation anim, ShapeElement[] allElements)
        {
            if (Elements == null)
            {
                return;
            }

            foreach (var val in Elements)
            {
                val.Value.Frame = Frame;
            }

            foreach (ShapeElement elem in allElements)
            {
                AnimationKeyFrameElement kelem = FindKeyFrameElement(elem);
                if (kelem != null)
                {
                    ElementsByShapeElement[elem] = kelem;
                }
            }
        }
Ejemplo n.º 6
0
        protected void getTwoKeyFramesElementForFlag(int frameNumber, ShapeElement forElement, int forFlag, out AnimationKeyFrameElement left, out AnimationKeyFrameElement right)
        {
            left  = null;
            right = null;

            int rightKfIndex = seekRightKeyFrame(frameNumber, forElement, forFlag);

            if (rightKfIndex == -1)
            {
                return;
            }

            right = KeyFrames[rightKfIndex].GetKeyFrameElement(forElement);

            int leftKfIndex = seekLeftKeyFrame(rightKfIndex, forElement, forFlag);

            if (leftKfIndex == -1)
            {
                left = right;
                return;
            }

            left = KeyFrames[leftKfIndex].GetKeyFrameElement(forElement);
        }