示例#1
0
        /// <summary>
        /// Fragmenta una pared en varias subparedes, en base a todas las colisiones que hubo con cuartos vecinos
        /// </summary>
        private List <Point> fragmentWall(RoomsEditorWall wall, Point wallSegment, List <Point> intersectingLines, List <RoomsEditorRoom> intersectingRooms)
        {
            List <Point> finalWallSegments;

            wall.IntersectingRooms.Clear();

            //Hubo intersecciones, fragmentar
            if (intersectingRooms.Count > 0)
            {
                //Agregar rooms vecinos
                wall.IntersectingRooms.AddRange(intersectingRooms);

                //Calcular intersecciones con vecinos en esta pared que hay que quitar de la pared original
                List <Point> segmentsToExtract = new List <Point>();
                foreach (Point lineSegment in intersectingLines)
                {
                    segmentsToExtract.Add(intersectLineSegments(lineSegment, wallSegment));
                }
                //Quitarle al segmento original los fragmentos
                finalWallSegments = removeSegmentsFromLine(wallSegment, segmentsToExtract);
            }
            //no fragmentar
            else
            {
                finalWallSegments = new List <Point>();
                finalWallSegments.Add(wallSegment);
            }

            return(finalWallSegments);
        }
示例#2
0
 /// <summary>
 /// Actualiza datos de la UI en base a una pared
 /// </summary>
 private void updateUiData(RoomsEditorWall wall, PictureBox image, CheckBox autoUv, NumericUpDown uTile, NumericUpDown vTile)
 {
     image.ImageLocation = wall.Texture.FilePath;
     autoUv.Checked      = wall.AutoAdjustUv;
     uTile.Value         = (decimal)wall.UTile;
     vTile.Value         = (decimal)wall.VTile;
 }
 /// <summary>
 /// Actualizar datos de una pared
 /// </summary>
 private void updateWallData(RoomsEditorWall wall, PictureBox image, CheckBox autoUv, NumericUpDown uTile, NumericUpDown vTile)
 {
     if (wall.Texture != null)
     {
         wall.Texture.dispose();
     }
     wall.Texture = TgcTexture.createTexture(GuiController.Instance.D3dDevice, image.ImageLocation);
     wall.AutoAdjustUv = autoUv.Checked;
     wall.UTile = (float)uTile.Value;
     wall.VTile = (float)vTile.Value;
 }
示例#4
0
 /// <summary>
 /// Actualizar datos de una pared
 /// </summary>
 private void updateWallData(RoomsEditorWall wall, PictureBox image, CheckBox autoUv, NumericUpDown uTile, NumericUpDown vTile)
 {
     if (wall.Texture != null)
     {
         wall.Texture.dispose();
     }
     wall.Texture      = TgcTexture.createTexture(GuiController.Instance.D3dDevice, image.ImageLocation);
     wall.AutoAdjustUv = autoUv.Checked;
     wall.UTile        = (float)uTile.Value;
     wall.VTile        = (float)vTile.Value;
 }
示例#5
0
        public RoomsEditorRoom(string name, RoomsEditorMapView.RoomPanel roomPanel)
        {
            this.name      = name;
            this.roomPanel = roomPanel;

            this.roomPanel.Room = this;

            //crear paredes
            walls    = new RoomsEditorWall[6];
            walls[0] = new RoomsEditorWall(this, "Roof");
            walls[1] = new RoomsEditorWall(this, "Floor");
            walls[2] = new RoomsEditorWall(this, "East");
            walls[3] = new RoomsEditorWall(this, "West");
            walls[4] = new RoomsEditorWall(this, "North");
            walls[5] = new RoomsEditorWall(this, "South");

            //Valores default
            height     = 100;
            floorLevel = 0;
        }
 /// <summary>
 /// Actualiza datos de la UI en base a una pared
 /// </summary>
 private void updateUiData(RoomsEditorWall wall, PictureBox image, CheckBox autoUv, NumericUpDown uTile, NumericUpDown vTile)
 {
     image.ImageLocation = wall.Texture.FilePath;
     autoUv.Checked = wall.AutoAdjustUv;
     uTile.Value = (decimal)wall.UTile;
     vTile.Value = (decimal)wall.VTile;
 }
示例#7
0
        /// <summary>
        /// Actualiza la información de las paredes
        /// </summary>
        public void buildWalls(List <RoomsEditorRoom> rooms, Vector3 sceneScale)
        {
            Rectangle bounds = roomPanel.Label.Bounds;

            //roof
            RoomsEditorWall roof       = walls[0];
            TgcPlaneWall    roofWall3d = new TgcPlaneWall(
                new Vector3(bounds.X * sceneScale.X, (floorLevel + height) * sceneScale.Y, bounds.Y * sceneScale.Z),
                new Vector3(bounds.Width * sceneScale.X, 0, bounds.Height * sceneScale.Z),
                TgcPlaneWall.Orientations.XZplane,
                roof.Texture, roof.UTile, roof.VTile
                );

            roof.WallSegments.Clear();
            roof.WallSegments.Add(roofWall3d);


            //floor
            RoomsEditorWall floor       = walls[1];
            TgcPlaneWall    floorWall3d = new TgcPlaneWall(
                new Vector3(bounds.X * sceneScale.X, floorLevel, bounds.Y * sceneScale.Z),
                new Vector3(bounds.Width * sceneScale.X, 0, bounds.Height * sceneScale.Z),
                TgcPlaneWall.Orientations.XZplane,
                floor.Texture, floor.UTile, floor.VTile
                );

            floor.WallSegments.Clear();
            floor.WallSegments.Add(floorWall3d);



            List <Point>           intersectingLines;
            List <RoomsEditorRoom> intersectingRooms;
            Point        wallSegment;
            List <Point> finalWallSegments;



            //east wall
            RoomsEditorWall eastWall = walls[2];

            //buscar colisiones y particionar
            wallSegment = new Point(bounds.Y, bounds.Y + bounds.Height);
            findIntersectingEastWall(rooms, out intersectingLines, out intersectingRooms);
            finalWallSegments = fragmentWall(eastWall, wallSegment, intersectingLines, intersectingRooms);

            //Crear una una pared 3D por cada segmento final que quedó
            eastWall.WallSegments.Clear();
            foreach (Point seg in finalWallSegments)
            {
                TgcPlaneWall wall3d = new TgcPlaneWall(
                    new Vector3((bounds.X + bounds.Width) * sceneScale.X, floorLevel * sceneScale.Y, seg.X * sceneScale.Z),
                    new Vector3(0, height * sceneScale.Y, (seg.Y - seg.X) * sceneScale.Z),
                    TgcPlaneWall.Orientations.YZplane,
                    eastWall.Texture, eastWall.UTile, eastWall.VTile
                    );
                eastWall.WallSegments.Add(wall3d);
            }

            //Crear paredes para las diferencias de alturas con los otros Rooms
            createEastWallSegmentsForHeightDiff(sceneScale, intersectingLines, intersectingRooms, eastWall);



            //west wall
            RoomsEditorWall westWall = walls[3];

            //buscar colisiones y particionar
            wallSegment = new Point(bounds.Y, bounds.Y + bounds.Height);
            findIntersectingWestWall(rooms, out intersectingLines, out intersectingRooms);
            finalWallSegments = fragmentWall(eastWall, wallSegment, intersectingLines, intersectingRooms);

            //Crear una una pared 3D por cada segmento final que quedó
            westWall.WallSegments.Clear();
            foreach (Point seg in finalWallSegments)
            {
                TgcPlaneWall wall3d = new TgcPlaneWall(
                    new Vector3(bounds.X * sceneScale.X, floorLevel * sceneScale.Y, seg.X * sceneScale.Z),
                    new Vector3(0, height * sceneScale.Y, (seg.Y - seg.X) * sceneScale.Z),
                    TgcPlaneWall.Orientations.YZplane,
                    westWall.Texture, westWall.UTile, westWall.VTile
                    );
                westWall.WallSegments.Add(wall3d);
            }
            //Crear paredes para las diferencias de alturas con los otros Rooms
            createWestWallSegmentsForHeightDiff(sceneScale, intersectingLines, intersectingRooms, westWall);



            //north wall
            RoomsEditorWall northWall = walls[4];

            //buscar colisiones y particionar
            wallSegment = new Point(bounds.X, bounds.X + bounds.Width);
            findIntersectingNorthWall(rooms, out intersectingLines, out intersectingRooms);
            finalWallSegments = fragmentWall(eastWall, wallSegment, intersectingLines, intersectingRooms);

            //Crear una una pared 3D por cada segmento final que quedó
            northWall.WallSegments.Clear();
            foreach (Point seg in finalWallSegments)
            {
                TgcPlaneWall wall3d = new TgcPlaneWall(
                    new Vector3(seg.X * sceneScale.X, floorLevel * sceneScale.Y, bounds.Y * sceneScale.Z),
                    new Vector3((seg.Y - seg.X) * sceneScale.X, height * sceneScale.Y, 0),
                    TgcPlaneWall.Orientations.XYplane,
                    northWall.Texture, northWall.UTile, northWall.VTile
                    );
                northWall.WallSegments.Add(wall3d);
            }
            //Crear paredes para las diferencias de alturas con los otros Rooms
            createNorthWallSegmentsForHeightDiff(sceneScale, intersectingLines, intersectingRooms, northWall);


            //south wall
            RoomsEditorWall southWall = walls[5];

            //buscar colisiones y particionar
            wallSegment = new Point(bounds.X, bounds.X + bounds.Width);
            findIntersectingSouthWall(rooms, out intersectingLines, out intersectingRooms);
            finalWallSegments = fragmentWall(eastWall, wallSegment, intersectingLines, intersectingRooms);

            //Crear una una pared 3D por cada segmento final que quedó
            southWall.WallSegments.Clear();
            foreach (Point seg in finalWallSegments)
            {
                TgcPlaneWall wall3d = new TgcPlaneWall(
                    new Vector3(seg.X * sceneScale.X, floorLevel * sceneScale.Y, (bounds.Y + bounds.Height) * sceneScale.Z),
                    new Vector3((seg.Y - seg.X) * sceneScale.X, height * sceneScale.Y, 0),
                    TgcPlaneWall.Orientations.XYplane,
                    southWall.Texture, southWall.UTile, southWall.VTile
                    );
                southWall.WallSegments.Add(wall3d);
            }
            //Crear paredes para las diferencias de alturas con los otros Rooms
            createSouthWallSegmentsForHeightDiff(sceneScale, intersectingLines, intersectingRooms, southWall);
        }
示例#8
0
        /// <summary>
        /// Crear paredes 3D para las diferencias de altura entre la pared South de este Room y el resto
        /// de los Rooms contra los que colisiona
        /// </summary>
        private void createSouthWallSegmentsForHeightDiff(Vector3 sceneScale, List <Point> intersectingLines, List <RoomsEditorRoom> intersectingRooms, RoomsEditorWall wall)
        {
            Rectangle bounds   = roomPanel.Label.Bounds;
            Point     wallSide = new Point(roomPanel.Label.Location.X, roomPanel.Label.Location.X + roomPanel.Label.Width);

            Point[] supDiffSegments;
            Point[] infDiffSegments;
            findSegmentsForHeightDiff(intersectingRooms, out supDiffSegments, out infDiffSegments);
            for (int i = 0; i < intersectingRooms.Count; i++)
            {
                Point fullIntersecLine = intersectingLines[i];
                Point intersecLine     = intersectLineSegments(fullIntersecLine, wallSide);

                //Fragmento superior
                Point supSeg = supDiffSegments[i];
                if (supSeg.X != 0 || supSeg.Y != 0)
                {
                    TgcPlaneWall wall3d = new TgcPlaneWall(
                        new Vector3(intersecLine.X * sceneScale.X, supSeg.X * sceneScale.Y, (bounds.Y + bounds.Height) * sceneScale.Z),
                        new Vector3((intersecLine.Y - intersecLine.X) * sceneScale.X, (supSeg.Y - supSeg.X) * sceneScale.Y, 0),
                        TgcPlaneWall.Orientations.XYplane,
                        wall.Texture, wall.UTile, wall.VTile
                        );
                    wall.WallSegments.Add(wall3d);
                }

                //Fragmento inferior
                Point infSeg = infDiffSegments[i];
                if (infSeg.X != 0 || infSeg.Y != 0)
                {
                    TgcPlaneWall wall3d = new TgcPlaneWall(
                        new Vector3(intersecLine.X * sceneScale.X, infSeg.X * sceneScale.Y, (bounds.Y + bounds.Height) * sceneScale.Z),
                        new Vector3((intersecLine.Y - intersecLine.X) * sceneScale.X, (infSeg.Y - infSeg.X) * sceneScale.Y, 0),
                        TgcPlaneWall.Orientations.XYplane,
                        wall.Texture, wall.UTile, wall.VTile
                        );
                    wall.WallSegments.Add(wall3d);
                }
            }
        }
示例#9
0
        /// <summary>
        /// Carga un archivo XML con los datos de una mapa guardado anteriormente
        /// </summary>
        private void openMap(string filePath)
        {
            try
            {
                FileInfo fInfo       = new FileInfo(filePath);
                string   directory   = fInfo.DirectoryName;
                string   texturesDir = directory + "\\" + DEFAULT_TEXTURES_DIR;

                XmlDocument dom       = new XmlDocument();
                string      xmlString = File.ReadAllText(filePath);
                dom.LoadXml(xmlString);
                XmlElement root = dom.DocumentElement;

                //mapSettings
                XmlNode mapSettingsNode = root.GetElementsByTagName("mapSettings")[0];
                Size    mapSize         = new Size();
                mapSize.Width  = TgcParserUtils.parseInt(mapSettingsNode.Attributes["width"].InnerText);
                mapSize.Height = TgcParserUtils.parseInt(mapSettingsNode.Attributes["height"].InnerText);

                Vector3 mapScale = new Vector3();
                mapScale.X = TgcParserUtils.parseFloat(mapSettingsNode.Attributes["scaleX"].InnerText);
                mapScale.Y = TgcParserUtils.parseFloat(mapSettingsNode.Attributes["scaleY"].InnerText);
                mapScale.Z = TgcParserUtils.parseFloat(mapSettingsNode.Attributes["scaleZ"].InnerText);

                mapView.setMapSettings(mapSize, mapScale);


                //rooms
                XmlNode roomsNode = root.GetElementsByTagName("rooms")[0];
                mapView.resetRooms(roomsNode.ChildNodes.Count * 2);
                foreach (XmlNode roomNode in roomsNode.ChildNodes)
                {
                    string roomName = roomNode.Attributes["name"].InnerText;
                    Point  pos      = new Point();
                    pos.X = TgcParserUtils.parseInt(roomNode.Attributes["x"].InnerText);
                    pos.Y = TgcParserUtils.parseInt(roomNode.Attributes["y"].InnerText);
                    Size size = new Size();
                    size.Width  = TgcParserUtils.parseInt(roomNode.Attributes["width"].InnerText);
                    size.Height = TgcParserUtils.parseInt(roomNode.Attributes["length"].InnerText);
                    int roomHeight     = TgcParserUtils.parseInt(roomNode.Attributes["height"].InnerText);
                    int roomFloorLevel = TgcParserUtils.parseInt(roomNode.Attributes["floorLevel"].InnerText);

                    RoomsEditorRoom room = mapView.createRoom(roomName, pos, size);
                    room.Height     = roomHeight;
                    room.FloorLevel = roomFloorLevel;

                    //walls
                    int wIdx = 0;
                    foreach (XmlNode wallNode in roomNode.ChildNodes)
                    {
                        string wallName     = wallNode.Attributes["name"].InnerText;
                        string textureName  = wallNode.Attributes["textureName"].InnerText;
                        bool   autoAdjustUv = bool.Parse(wallNode.Attributes["autoAdjustUv"].InnerText);
                        float  uTile        = TgcParserUtils.parseFloat(wallNode.Attributes["uTile"].InnerText);
                        float  vTile        = TgcParserUtils.parseFloat(wallNode.Attributes["vTile"].InnerText);

                        RoomsEditorWall wall = room.Walls[wIdx++];
                        if (wall.Texture != null)
                        {
                            wall.Texture.dispose();
                        }
                        wall.Texture      = TgcTexture.createTexture(GuiController.Instance.D3dDevice, texturesDir + "\\" + textureName);
                        wall.AutoAdjustUv = autoAdjustUv;
                        wall.UTile        = uTile;
                        wall.VTile        = vTile;
                    }
                }

                //Crear escenario 3D
                mapView.update3dMap();


                MessageBox.Show(this, "Map openned OK", "Open Map", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                GuiController.Instance.Logger.logError("Cannot open RoomsEditor Map file", ex);
            }
        }