Esempio n. 1
0
 private void ReadMatrix(XElement xNode, Node node)
 {
     Node.FrameData frame = new Node.FrameData(Node.FrameType.matrix, (string)xNode.Attribute("sid"));
     frame.mat      = ReadMatrix(xNode);
     node.finalMat *= frame.mat;
     node.frameData.Add(frame);
 }
Esempio n. 2
0
 private void ReadTranslate(XElement xNode, Node node, NodeSettings settings)
 {
     Node.FrameData frame = new Node.FrameData(Node.FrameType.translate, (string)xNode.Attribute("sid"));
     frame.vec1 = ReadVector3(xNode, 0);
     if (IsZero(frame.vec1, settings.GetTolerance("VECTOR")))
     {
         return;
     }
     node.finalMat *= Matrix.CreateTranslation(frame.vec1);
     node.frameData.Add(frame);
 }
Esempio n. 3
0
 private void ReadSkew(XElement xNode, Node node, NodeSettings settings)
 {
     Node.FrameData frame = new Node.FrameData(Node.FrameType.skew, (string)xNode.Attribute("sid"));
     frame.value = MathHelper.ToRadians(ReadFloat(xNode, 0));
     frame.vec1  = ReadVector3(xNode, 1);
     frame.vec2  = ReadVector3(xNode, 4);
     if (IsZero(frame.value, settings.GetTolerance("ANGLE")))
     {
         return;
     }
     //TODO apply skew to matrix
     node.frameData.Add(frame);
 }
Esempio n. 4
0
 private void ReadLookAt(XElement xNode, Node node, NodeSettings settings)
 {
     Node.FrameData frame = new Node.FrameData(Node.FrameType.lookat, (string)xNode.Attribute("sid"));
     frame.vec1 = ReadVector3(xNode, 0);
     frame.vec2 = ReadVector3(xNode, 3);
     frame.vec3 = ReadVector3(xNode, 6);
     if (IsZero(frame.vec1, settings.GetTolerance("VECTOR")) && IsZero(frame.vec2, settings.GetTolerance("VECTOR")) && IsZero(frame.vec3, settings.GetTolerance("VECTOR")))
     {
         return;
     }
     node.finalMat *= Matrix.CreateLookAt(frame.vec1, frame.vec2, frame.vec3);
     node.frameData.Add(frame);
 }
Esempio n. 5
0
 private void ReadRotate(XElement xNode, Node node, NodeSettings settings)
 {
     Node.FrameData frame = new Node.FrameData(Node.FrameType.rotate, (string)xNode.Attribute("sid"));
     frame.vec1  = ReadVector3(xNode, 0);
     frame.value = MathHelper.ToRadians(ReadFloat(xNode, 3));
     if (IsZero(frame.value, settings.GetTolerance("ANGLE")))
     {
         return;
     }
     if (IsZero(frame.vec1 - new Vector3(1, 0, 0), settings.GetTolerance("VECTOR")))
     {
         frame.type = Node.FrameType.rotateX;
     }
     else if (IsZero(frame.vec1 - new Vector3(0, 1, 0), settings.GetTolerance("VECTOR")))
     {
         frame.type = Node.FrameType.rotateY;
     }
     else if (IsZero(frame.vec1 - new Vector3(0, 0, 1), settings.GetTolerance("VECTOR")))
     {
         frame.type = Node.FrameType.rotateZ;
     }
     node.finalMat *= Matrix.CreateFromAxisAngle(frame.vec1, frame.value);
     node.frameData.Add(frame);
 }
Esempio n. 6
0
        public override void Load(XElement item)
        {
            LoadBase(item, "frame", true);
            parent.gotFrame = true;
            Node baseNode = (Node)parent.nodeData;

            string xPos   = null;
            string xRot   = null;
            string xScale = null;

            if (item != null)
            {
                xPos   = mgr.configure.ReadAttrOrElem(item, "pos");
                xRot   = mgr.configure.ReadAttrOrElem(item, "rot");
                xScale = mgr.configure.ReadAttrOrElem(item, "scale");
            }
            if (xPos != null)
            {
                float[] data = xPos.Split(' ').Select((s) => float.Parse(s)).ToArray();
                pos = new Vector3(data[0], data[1], data[2]);
            }
            else if (baseNode != null)
            {
                Node.FrameData data = baseNode.frameData.FirstOrDefault((f) => f.type == Node.FrameType.translate);
                if (data != null)
                {
                    pos = data.vec1;
                }
            }
            if (xRot != null)
            {
                float[] data = xRot.Split(' ').Select((s) => float.Parse(s)).ToArray();
                rot = new Quaternion(data[0], data[1], data[2], data[3]);
            }
            else if (baseNode != null)
            {
                Vector3        euler = Vector3.Zero;
                Node.FrameData x     = baseNode.frameData.FirstOrDefault((f) => f.type == Node.FrameType.rotateX);
                Node.FrameData y     = baseNode.frameData.FirstOrDefault((f) => f.type == Node.FrameType.rotateY);
                Node.FrameData z     = baseNode.frameData.FirstOrDefault((f) => f.type == Node.FrameType.rotateZ);
                if (x != null)
                {
                    euler.X = x.value;
                }
                if (y != null)
                {
                    euler.Y = y.value;
                }
                if (z != null)
                {
                    euler.Z = z.value;
                }
                rot = Quaternion.CreateFromYawPitchRoll(euler.Y, euler.X, euler.Z);
            }
            if (xScale != null)
            {
                float[] data = xScale.Split(' ').Select((s) => float.Parse(s)).ToArray();
                scale = new Vector3(data[0], data[1], data[2]);
            }
            else if (baseNode != null)
            {
                Node.FrameData data = baseNode.frameData.FirstOrDefault((f) => f.type == Node.FrameType.scale);
                if (data != null)
                {
                    scale = data.vec1;
                }
            }
        }