Ejemplo n.º 1
0
        private static KeyframeBlock ParseKeyframeBlock(XElement root, string name)
        {
            var result  = new KeyframeBlock();
            var isScale = name.StartsWith("Scale", true, CultureInfo.InvariantCulture);
            var element = root.ElementCaseInsensitive(name);

            if (element != null)
            {
                var isRotate = name.StartsWith("Rotate", true, CultureInfo.InvariantCulture);
                result.DefaultValue = element.GetAttributeValueWithDefault <float>("Value", isScale ? 1 : 0);
                result.Keyframes    = element.ElementsCaseInsensitive("Keyframe")
                                      .Select(e => new Keyframe(e.GetAttributeValueWithDefault <float>("Time"),
                                                                isRotate ? (float)
                                                                (e.GetAttributeValueWithDefault <double>("Value", isScale ? 1 : 0) * Math.PI / 180)
                            : e.GetAttributeValueWithDefault <float>("Value", isScale ? 1 : 0),
                                                                isRotate ? (float)
                                                                (e.GetAttributeValueWithDefault <double>("Velocity") * Math.PI / 180)
                            : e.GetAttributeValueWithDefault <float>("Velocity"))).ToArray();
            }
            else if (isScale)
            {
                result.DefaultValue = 1;
            }
            return(result);
        }
Ejemplo n.º 2
0
 private static TwoTribesAnimation GetAnimation(RepeatBehavior repeatBehavior, float duration,
                                                KeyframeBlock block, double k = 1)
 {
     //var animation = new DoubleAnimationUsingKeyFrames
     //    { RepeatBehavior = repeatBehavior, Duration = new Duration(TimeSpan.FromSeconds(duration / 30.0)) };
     //animation.KeyFrames.Add(new DiscreteDoubleKeyFrame(block.DefaultValue * k, TimeSpan.Zero));
     //foreach (var keyframe in block.Keyframes) animation.KeyFrames.Add(
     //    new LinearDoubleKeyFrame(keyframe.Value * k, TimeSpan.FromSeconds(keyframe.Time / 30.0)));
     //return animation;
     return(new TwoTribesAnimation(block, k)
     {
         RepeatBehavior = repeatBehavior, Duration = new Duration(TimeSpan.FromSeconds(duration / 30D))
     });
 }
Ejemplo n.º 3
0
        private static XElement GetKeyframeBlockElement(KeyframeBlock keyframeBlock, string name)
        {
            var  result   = new XElement(name);
            bool isScale  = name.StartsWith("Scale", StringComparison.Ordinal),
                 isRotate = name.StartsWith("Rotate", StringComparison.Ordinal);

            result.SetAttributeValueWithDefault("Value", keyframeBlock.DefaultValue, isScale ? 1 : 0);
            foreach (var keyframe in keyframeBlock.Keyframes)
            {
                var element = new XElement("Keyframe");
                element.SetAttributeValueWithDefault("Time", keyframe.Time);
                element.SetAttributeValueWithDefault("Value",
                                                     isRotate ? keyframe.Value * 180 / Math.PI : keyframe.Value, isScale ? 1 : 0);
                element.SetAttributeValueWithDefault("Velocity",
                                                     isRotate ? keyframe.Velocity * 180 / Math.PI : keyframe.Velocity);
                result.Add(element);
            }
            return(result);
        }
Ejemplo n.º 4
0
 public TwoTribesAnimation(KeyframeBlock block, double k = 1)
 {
     Block = block;
     K     = k;
 }