Example #1
0
        // Ya no pinta el titulo de la postura de forma automatica, solo su esqueleto :)
        public int postureAdd(PostureInformation skeletonToRecord, Texture2D spriteGraphic)
        {
            Tuple <PostureInformation, Texture2D> data = new Tuple <PostureInformation, Texture2D>(skeletonToRecord, spriteGraphic);

            this.postureComponents.Add(data);
            return(this.postureComponents.LastIndexOf(data));
        }
        public static PostureInformation loadPosture(String name)
        {
            Vector3[] joints = new Vector3[20];
            int index = 0;
            XmlDocument xDoc = new XmlDocument();

            //xDoc.Load("../../../../personas1.xml");
            xDoc.Load(name + ".xml");
            XmlNodeList postura = xDoc.GetElementsByTagName("Posture");

            XmlAttribute nam = ((XmlElement)postura[0]).GetAttributeNode("name");
            XmlAttribute des = ((XmlElement)postura[0]).GetAttributeNode("description");
            XmlAttribute dif = ((XmlElement)postura[0]).GetAttributeNode("difficulty");

            XmlNodeList listaJoints = ((XmlElement)postura[0]).GetElementsByTagName("joint");

            foreach (XmlElement nodo in listaJoints)
            {
                XmlAttribute a = nodo.GetAttributeNode("x");
                XmlAttribute b = nodo.GetAttributeNode("y");
                XmlAttribute c = nodo.GetAttributeNode("z");

                joints[index] = new Vector3(float.Parse(a.Value), float.Parse(b.Value), float.Parse(c.Value));
                index++;
            }

            PostureInformation postureI = new PostureInformation(nam.Value, des.Value, System.Convert.ToInt16(dif.Value), joints);
            return postureI;
        }
        public static PostureInformation loadPosture(String name)
        {
            Vector3[] joints = new Vector3[20];
            int index = 0;
            SqliteConnector conn = new SqliteConnector();
            string postid = conn.postureGetId(name);
            if (postid == "")
            {
                conn.CloseConnection();
                return null;
            }
            Tuple<string,string,string> tPost = conn.postureGetData(name);
            if (tPost == null)
            {
                conn.CloseConnection();
                return null;
            }
            List<Tuple<string, string, string, string>> tJoint= conn.postureGetJoints(postid);
            if (tJoint.Count!=20)
            {
                conn.CloseConnection();
                return null;
            }

            foreach (Tuple<string, string, string, string> joint in tJoint)
            {
                joints[System.Convert.ToInt16(joint.Item1)] = new Vector3(float.Parse(joint.Item2), float.Parse(joint.Item3), float.Parse(joint.Item4));
                index++;
            }

            PostureInformation postureI = new PostureInformation(tPost.Item1, tPost.Item2, System.Convert.ToInt16(tPost.Item3), joints);
            conn.CloseConnection();
            return postureI;
        }
        public static Boolean storePosture(PostureInformation p)
        {
            try
            {
                //XmlDocument originalXml = new XmlDocument();
                //originalXml.CreateXmlDeclaration("1.0", "utf-8", null);

                XmlDocument xmlDoc = new XmlDocument();
                // Write down the XML declaration
                XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

                // Create the root element
                XmlElement rootNode = xmlDoc.CreateElement("Posture");
                XmlAttribute _Name = xmlDoc.CreateAttribute("name");
                _Name.Value = p.name;
                XmlAttribute _Des = xmlDoc.CreateAttribute("description");
                _Des.Value = p.description;
                XmlAttribute _Dif = xmlDoc.CreateAttribute("difficulty");
                _Dif.Value = System.Convert.ToString(p.difficulty);

                rootNode.Attributes.Append(_Name);
                rootNode.Attributes.Append(_Des);
                rootNode.Attributes.Append(_Dif);
                xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
                xmlDoc.AppendChild(rootNode);

                int index = 0;
                foreach (Vector3 v in p.joints)
                {

                    XmlNode newSub = xmlDoc.CreateNode(XmlNodeType.Element, "joint", null);
                    XmlAttribute _X = xmlDoc.CreateAttribute("x");
                    _X.Value = System.Convert.ToString(v.X);
                    XmlAttribute _Y = xmlDoc.CreateAttribute("y");
                    _Y.Value = System.Convert.ToString(v.Y);
                    XmlAttribute _Z = xmlDoc.CreateAttribute("z");
                    _Z.Value = System.Convert.ToString(v.Z);

                    //los agregamos
                    newSub.Attributes.Append(_X);
                    newSub.Attributes.Append(_Y);
                    newSub.Attributes.Append(_Z);
                    rootNode.AppendChild(newSub);

                    index++;
                }

                //grabamos
                xmlDoc.Save("./postures/" + p.name + ".xml");

                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return false;
            }
        }
Example #5
0
 /// ?? Esto iría mejor en Posture.Posture (static) ??
 /// <summary>
 /// Mezcla un array de <code>Posture</code>.
 /// </summary>
 /// <param name="postures">Posturas a mezclar</param>
 private void shufflePostures(PostureInformation[] postures)
 {
     for (int t = 0; t < postures.Length; t++)
     {
         PostureInformation tmp = postures[t];
         Random             rr  = new Random();
         int r = rr.Next(t, postures.Length);
         postures[t] = postures[r];
         postures[r] = tmp;
     }
 }
 public static Boolean storePosture(PostureInformation p)
 {
     SqliteConnector conn = new SqliteConnector();
     if (conn.postureGetId(p.name) != "")
     {
         conn.CloseConnection();
         return false;
     }
     conn.insert("INSERT INTO POSTURE (NAME,DESCRIPTION,DIFFICULTY) VALUES ('" + p.name + "','" + p.description + "'," + System.Convert.ToString(p.difficulty) + ")");
     string postid = conn.postureGetId(p.name);
     int index = 0;
     foreach (Vector3 v in p.joints)
     {
         conn.insert("INSERT INTO JOINT (ID_POSTURE,JOINT_ORDER,X,Y,Z) VALUES (" + postid + "," + index + "," + v.X.ToString().Replace(",", ".") + "," + v.Y.ToString().Replace(",", ".") + "," + v.Z.ToString().Replace(",", ".") + ")");
         index++;
     }
     conn.CloseConnection();
     return true;
 }
        public static PostureInformation[] getPostureList()
        {
            String[] nombresficheros = System.IO.Directory.GetFiles("./postures/");
            int a = 0;
            foreach (String n in nombresficheros)
            {
                if (n.Contains(".xml")) a++;
            }

            PostureInformation[] allPostures = new PostureInformation[a];
            a = 0;
            foreach (String n in nombresficheros)
            {
                if (n.Contains(".xml"))
                {
                    allPostures[a] = loadPosture(n.Replace(".xml", ""));
                    a++;
                }
            }

            return allPostures;
        }
 /// ?? Esto iría mejor en Posture.Posture (static) ??
 /// <summary>
 /// Mezcla un array de <code>Posture</code>.
 /// </summary>
 /// <param name="postures">Posturas a mezclar</param>
 private void shufflePostures(PostureInformation[] postures)
 {
     for (int t = 0; t < postures.Length; t++ )
     {
         PostureInformation tmp = postures[t];
         Random rr = new Random();
         int r = rr.Next(t, postures.Length);
         postures[t] = postures[r];
         postures[r] = tmp;
     }
 }