Exemplo n.º 1
0
        private XmlElement createKeyframe(Keyframe keyframe)
        {
            string type = "translate";
            if (keyframe.Type == KeyframeType.Rotation)
                type = "rotate";
            XmlElement keyframeElem = xmlDoc.CreateElement(type);
            XmlAttribute timeAttr = xmlDoc.CreateAttribute("time");
            timeAttr.Value = keyframe.Time.ToString();
            //Get transformation values
            float x = keyframe.Transformation.X;
            float y = keyframe.Transformation.Y;
            float z = keyframe.Transformation.Z;
            //If rotation, convert to radians
            if (keyframe.Type == KeyframeType.Rotation)
            {
                x = Convert.degreesToRadians(x);
                y = Convert.degreesToRadians(y);
                z = Convert.degreesToRadians(z);
            }
            XmlAttribute xAttr = xmlDoc.CreateAttribute("x");
            xAttr.Value = x.ToString();
            XmlAttribute yAttr = xmlDoc.CreateAttribute("y");
            yAttr.Value = y.ToString();
            XmlAttribute zAttr = xmlDoc.CreateAttribute("z");
            zAttr.Value = z.ToString();
            keyframeElem.Attributes.Append(timeAttr);
            keyframeElem.Attributes.Append(xAttr);
            keyframeElem.Attributes.Append(yAttr);
            keyframeElem.Attributes.Append(zAttr);

            return keyframeElem;
        }
Exemplo n.º 2
0
        public Keyframe createKeyframe(string boneName, float time, int type, string vector)
        {
            KeyframeType typ = KeyframeType.Translation;
            if (type == 2) typ = KeyframeType.Rotation;
            string[] xyz = vector.Split(':');
            Vertex vertex = new Vertex(
                float.Parse(xyz[0]), float.Parse(xyz[1]), float.Parse(xyz[2]));
            Keyframe keyframe = new Keyframe(time, typ, vertex);
            foreach (Bone bone in model.Bones)
            {
                if (bone.Name == boneName)
                {
                    bone.Animation.Add(keyframe);

                    if (ModelUpdated != null)
                        ModelUpdated(this, new EventArgs());

                    break;
                }
            }
            return keyframe;
        }