Esempio n. 1
0
        //Check all facesB in our floor
        //Check the faces edges if they are parallel or orthogonal to the moveVector of faceA

        //if orthogonal
        //check if faceA has an edge with contains the orthogonal Edge of faceB
        //if so, add faceB´s orthogonal edge to the verticesToMoveList and start with the next face
        //check if faceA only shares one vertex with B

        //If parallel
        //check if faceA shares an edge with faceB
        //if so, then add all edges of faceA to the verticesToMove list and rerun the whole process with faceA=faceB
        //continue untill all parallel edges are added, then start with next face
        private void AddAttachedToMove(Face movingFace, Vector2 moveVector, List <Face> checkedFaces, ref List <Vertex> verticesToMove)
        {
            foreach (Face face in currentFloor.GetFaces())
            {
                if (!movingFace.Equals(face) && !checkedFaces.Contains(face) && face.GetType().ToString() != "wunderZone")
                {
                    foreach (Edge edge in face.GetEdges())
                    {
                        if (Angle(moveVector, edge.GetEdgeVector()) != 0)
                        {
                        }

                        if (Angle(moveVector, edge.GetEdgeVector()) == 0)
                        {
                            if (FaceEdgeEuqlasEdge(movingFace, edge)) //this works!
                            {
                                AddEdgeToMove(face.GetEdges(), ref verticesToMove);
                                checkedFaces.Add(face);
                                Console.WriteLine("Entering addAttacehdFace for face" + face.GetFaceName());
                                AddAttachedToMove(face, moveVector, checkedFaces, ref verticesToMove);
                            }

                            if (VerticesToMoveContains(verticesToMove, edge))
                            {
                                AddEdgeToMove(edge, ref verticesToMove);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calls the Transform function for given floor. Moves and Scales all the floors faces
        /// </summary>
        /// <param name="floor"></param>
        public void Transform()
        {
            foreach (Floor floor in variation.GetFloors())
            {
                currentFloor = floor;
                foreach (Face face in currentFloor.GetFaces())            //iterate through all faces
                {
                    if (face.GetMoveVector() != new Vector2(0, 0))        //if moveVector exists
                    {
                        List <Vertex> verticesToMove = new List <Vertex>();
                        AddFaceToMove(face, ref verticesToMove);
                        List <Face> checkedFaces = new List <Face>()
                        {
                            face
                        };
                        if (face.GetObjectType() != "stair")
                        {
                            AddAttachedToMove(face, face.GetMoveVector(), checkedFaces, ref verticesToMove);                                    //find faces which need to be added to the list
                        }
                        else
                        {
                            FindStairVertices(variation.GetFloors(), floor, verticesToMove);
                        }
                        Move(face.GetMoveVector(), ref verticesToMove);
                        //verticesToMove.Clear();
                        //checkedFaces.Clear();
                    }

                    if (face.GetScale() != 0)
                    {
                        //CalculateMidpoint
                        Vector2 midPoint  = face.CalculateMidPoint();
                        int     diminuend = 0;
                        if (face.GetVertices()[0] == face.GetVertices()[face.GetVertices().Count - 1])
                        {
                            diminuend = 1;
                        }
                        //GetLongestEdge
                        for (int i = 0; i < face.GetVertices().Count - diminuend; i++)
                        {
                            Vector2 straight = face.GetVertices()[i].ToVector2() - midPoint;
                            Vector2 moveVector;
                            if (Math.Abs(straight.X) > Math.Abs(straight.Y))
                            {
                                moveVector = new Vector2(straight.X * face.GetScale(), straight.Y);
                            }
                            else
                            {
                                moveVector = new Vector2(straight.X, straight.Y * face.GetScale());
                            }
                            face.GetVertices()[i].VertexVector = midPoint + moveVector;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Parse Xml.Floor into our fileformat
        /// </summary>
        /// <param name="path">The path we are reading from and into</param>
        /// <param name="fileStatus">read and write</param>
        public static void ParseFloor(string path, FileStatus fileStatus, Variation variation, Floor floor)
        {
            XmlDocument tempXmlDoc = Globals.xmlDoc;                                                                    //copy our document, so that if we save the changes it doesnt get defined

            if (fileStatus == FileStatus.input)
            {
                tempXmlDoc = Globals.xmlInput;
            }
            foreach (string objectType in Globals.objectTypes)                                                          //Iterate through all simObjs (wall, door ...)
            {
                XmlNodeList genericNodes = tempXmlDoc.SelectNodes("//floor/layer/" + objectType);
                {
                    foreach (XmlNode genericNode in genericNodes)
                    {
                        Face        tempObj    = new Face(genericNode.Attributes["id"].Value, ref variation, SetObjectType(genericNode.Attributes["id"].Value));
                        XmlNodeList pointNodes = genericNode.ChildNodes;

                        switch (fileStatus)
                        {
                        case FileStatus.read:
                        {
                            List <Vertex> vertices = new List <Vertex>();                                                   //Empty list containing the vertices of the face beeing created
                            foreach (XmlNode pointNode in pointNodes)
                            {
                                Vertex tempVertex = new Vertex();                                                          //Empty Vertex object

                                float x = float.Parse(pointNode.Attributes["x"].Value, Globals.culture);
                                float y = float.Parse(pointNode.Attributes["y"].Value, Globals.culture);

                                if (variation.FindVertex(x, y) != null)                                                       //Check if thge vertex was already created
                                {
                                    vertices.Add(variation.FindVertex(x, y));                                                 //if so, add the vertex to the list
                                }
                                else
                                {
                                    tempVertex = new Vertex(x, y);
                                    variation.AddVertex(tempVertex);
                                    vertices.Add(tempVertex);                                                         //ifnot, create a new vertex and add it to the list
                                }
                            }
                            Face testObj = new Face(genericNode.Attributes["id"].Value, ref variation, SetObjectType(genericNode.Attributes["id"].Value));
                            testObj.AddVertex(vertices);                                                                    //add the vertex list to our tempObj
                            variation.SetFacesVertices(testObj);                                                            //setup the face reference for the vertices in the globals.vertices
                            floor.AddFace(testObj);                                                                         //add the face to our floors facelist
                            break;
                        }

                        case FileStatus.write:
                        {
                            int i = 0;
                            foreach (XmlNode pointNode in pointNodes)
                            {
                                pointNode.Attributes["x"].Value = floor.GetFace(genericNode.Attributes["id"].Value).GetVertices()[i].ToVector2().X.ToString().Replace(",", ".");
                                pointNode.Attributes["y"].Value = floor.GetFace(genericNode.Attributes["id"].Value).GetVertices()[i].ToVector2().Y.ToString().Replace(",", ".");
                                i++;
                            }
                            break;
                        }

                        case FileStatus.input:
                        {
                            foreach (Face face in floor.GetFaces())
                            {
                                if (face.GetFaceName() == genericNode.Attributes["id"].Value)
                                {
                                    floor.AddFacesToMove();
                                    foreach (XmlNode pointNode in pointNodes)
                                    {
                                        if (pointNode.Attributes["Type"].Value == "Move")
                                        {
                                            float x = float.Parse(pointNode.Attributes["x"].Value, Globals.culture);
                                            float y = float.Parse(pointNode.Attributes["y"].Value, Globals.culture);
                                            face.SetMoveVector(new Vector2(x, y));
                                        }
                                        if (pointNode.Attributes["Type"].Value == "Scale")
                                        {
                                            float scaleFactor = float.Parse(pointNode.Attributes["factor"].Value, Globals.culture);
                                            face.SetScale(scaleFactor);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                        }
                    }
                }
            }
            if (fileStatus == FileStatus.write)
            {
                Globals.xmlDoc.Save(Path.Combine(path + "\\" + floor.GetID()));
                Console.WriteLine("Successfully created and updated: " + path);
                //Console.ReadLine();
            }
        }