/// <summary> /// Generar escenario 3D en base a la información del mapa /// </summary> public void update3dMap() { //chequear superposicion de rooms StringBuilder sb = new StringBuilder("There are collisions between the following Rooms: "); int totalCol = 0; foreach (RoomsEditorRoom room in rooms) { RoomsEditorRoom collRoom = testRoomPanelCollision(room, room.RoomPanel.Label.Bounds); if (collRoom != null) { sb.AppendLine(room.Name + " and " + collRoom.Name + "\n"); totalCol++; } } if (totalCol > 0) { MessageBox.Show(this, sb.ToString(), "Collisions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Escala del mapa mapScale = new Vector3((float)numericUpDownMapScaleX.Value, (float)numericUpDownMapScaleY.Value, (float)numericUpDownMapScaleZ.Value); //Construir rooms en 3D foreach (RoomsEditorRoom room in rooms) { room.buildWalls(rooms, mapScale); } }
/// <summary> /// Carga todos los valores en base a la información del Room /// </summary> public void fillRoomData(RoomsEditorRoom room) { updateUiData(mapView.selectedRoom.Walls[0], roofImage, roofAutoUv, roofUTile, roofVTile); updateUiData(mapView.selectedRoom.Walls[1], floorImage, floorAutoUv, floorUTile, floorVTile); updateUiData(mapView.selectedRoom.Walls[2], eastWallImage, eastWallAutoUv, eastWallUTile, eastWallVTile); updateUiData(mapView.selectedRoom.Walls[3], westWallImage, westWallAutoUv, westWallUTile, westWallVTile); updateUiData(mapView.selectedRoom.Walls[4], northWallImage, northWallAutoUv, northWallUTile, northWallVTile); updateUiData(mapView.selectedRoom.Walls[5], southWallImage, southWallAutoUv, southWallUTile, southWallVTile); }
/// <summary> /// Crea un nuevo Room y lo agrega al panel2D /// </summary> /// <param name="name"></param> /// <param name="pos"></param> public RoomsEditorRoom createRoom(string name, Point pos, Size size) { RoomPanel rPanel = new RoomPanel(name, this, pos, size); RoomsEditorRoom room = new RoomsEditorRoom(name, rPanel); rooms.Add(room); panel2d.Controls.Add(room.RoomPanel.Label); return(room); }
public RoomsEditorWall(RoomsEditorRoom room, string name) { this.room = room; this.name = name; wallSegments = new List <TgcPlaneWall>(); intersectingRooms = new List <RoomsEditorRoom>(); //cargar valores default de la pared texture = TgcTexture.createTexture(GuiController.Instance.D3dDevice, room.RoomPanel.mapView.defaultTextureImage); autoAdjustUv = true; uTile = 1f; vTile = 1f; }
/// <summary> /// Chequea colision con otros rooms. /// Devuelve el room contra el cual colisiono o null /// </summary> internal RoomsEditorRoom testRoomPanelCollision(RoomsEditorRoom room, Rectangle testRect) { foreach (RoomsEditorRoom r in rooms) { if (r != room) { if (r.RoomPanel.Label.Bounds.IntersectsWith(testRect)) { return(r); } } } return(null); }
void label_MouseUp(object sender, MouseEventArgs e) { //Se termino de hacer drag del label, validar posicion if (mapView.currentMode == EditMode.CreateRoom) { labelDragging = false; //Si hay colision con otros labels, restaurar la posicion original Rectangle possibleR = new Rectangle(label.Location, label.Size); RoomsEditorRoom collisionRoom = mapView.testRoomPanelCollision(this.room, possibleR); if (collisionRoom != null) { label.Location = oldLocation; } } }
private void panel2d_MouseMove(object sender, MouseEventArgs e) { //Modificar tamaño cuando se esta creando un Room if (currentMode == EditMode.CreateRoom) { if (creatingRoomMouseDown) { Point mPoint = snapPointToGrid(e.X, e.Y); int diffX = mPoint.X - creatingRoomOriginalPos.X; int diffY = mPoint.Y - creatingRoomOriginalPos.Y; //dibujar rectangulo en base a las coordenadas elegidas Rectangle rect; if (diffX > 0) { if (diffY > 0) { rect = new Rectangle(creatingRoomOriginalPos.X, creatingRoomOriginalPos.Y, diffX, diffY); } else { rect = new Rectangle(creatingRoomOriginalPos.X, creatingRoomOriginalPos.Y + diffY, diffX, -diffY); } } else { if (diffY > 0) { rect = new Rectangle(mPoint.X, creatingRoomOriginalPos.Y, -diffX, diffY); } else { rect = new Rectangle(mPoint.X, mPoint.Y, -diffX, -diffY); } } //Actualizar tamaño solo si no se escapa de los limites del escenario if (validateRoomBounds(rect)) { RoomsEditorRoom lastRoom = rooms[rooms.Count - 1]; lastRoom.RoomPanel.Label.Bounds = rect; } } } }
/// <summary> /// Actualiza el Bounds del label del Room validando limites y colisiones. /// Informa si se pude hacer /// </summary> internal bool updateLabelBounds(Rectangle newR) { //Validar limites del escenario if (!mapView.validateRoomBounds(newR)) { return(false); } //Validar colision con otros Rooms RoomsEditorRoom collisionRoom = mapView.testRoomPanelCollision(this.room, newR); if (collisionRoom != null) { return(false); } label.Bounds = newR; return(true); }
/// <summary> /// Seleccionar un cuarto /// </summary> private void selectRoom(RoomsEditorRoom room) { if (selectedRoom != null) { selectedRoom.RoomPanel.setRoomSelected(false); } selectedRoom = room; selectedRoom.RoomPanel.setRoomSelected(true); groupBoxEditRoom.Enabled = true; //Cargar datos de edicion del Room textBoxRoomName.Text = selectedRoom.Name; numericUpDownRoomPosX.Value = selectedRoom.RoomPanel.Label.Location.X; numericUpDownRoomPosY.Value = selectedRoom.RoomPanel.Label.Location.Y; numericUpDownRoomWidth.Value = selectedRoom.RoomPanel.Label.Width; numericUpDownRoomLength.Value = selectedRoom.RoomPanel.Label.Height; numericUpDownRoomHeight.Value = selectedRoom.Height; numericUpDownRoomFloorLevel.Value = selectedRoom.FloorLevel; }
/// <summary> /// Busca los segmentos de pared a generar en base a diferencia de alturas de las paredes. /// Por cada intersectingRoom carga 2 segmentos en supDiffSegments y infDiffSegments (segmento superior e inferior). /// Si alguno no hace falta la posición está en null. /// </summary> private void findSegmentsForHeightDiff(List <RoomsEditorRoom> intersectingRooms, out Point[] supDiffSegments, out Point[] infDiffSegments) { supDiffSegments = new Point[intersectingRooms.Count]; infDiffSegments = new Point[intersectingRooms.Count]; Point roomHeightLine = new Point(floorLevel, floorLevel + height); for (int i = 0; i < intersectingRooms.Count; i++) { RoomsEditorRoom interRoom = intersectingRooms[i]; //si hay diferencias de alturas, truncar if (floorLevel != interRoom.floorLevel || height != interRoom.height) { Point interRoomHeightLine = new Point(interRoom.floorLevel, interRoom.floorLevel + interRoom.height); List <Point> segmentsToExtract = new List <Point>(); segmentsToExtract.Add(intersectLineSegments(interRoomHeightLine, roomHeightLine)); List <Point> finalSegments = removeSegmentsFromLine(roomHeightLine, segmentsToExtract); if (finalSegments.Count == 0) { infDiffSegments[i] = segmentsToExtract[0]; } else if (finalSegments.Count == 2) { infDiffSegments[i] = finalSegments[0]; supDiffSegments[i] = finalSegments[1]; } else { if (finalSegments[0].X == floorLevel) { infDiffSegments[i] = finalSegments[0]; } else { supDiffSegments[i] = finalSegments[0]; } } } } }
private void panel2d_MouseUp(object sender, MouseEventArgs e) { //Termina la creación de un nuevo Room if (currentMode == EditMode.CreateRoom) { creatingRoomMouseDown = false; RoomsEditorRoom lastRoom = rooms[rooms.Count - 1]; lastRoom.RoomPanel.adaptaToMiniumSize(); //Si colisiona no lo borramos RoomsEditorRoom collisionRoom = testRoomPanelCollision(lastRoom, lastRoom.RoomPanel.Label.Bounds); if (collisionRoom != null) { rooms.Remove(lastRoom); panel2d.Controls.Remove(lastRoom.RoomPanel.Label); } //Seleccionar room recien creado selectRoom(lastRoom); } }
/// <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); } }
/// <summary> /// Eliminar un room /// </summary> internal void deleteRoom(RoomsEditorRoom room) { this.rooms.Remove(room); this.panel2d.Controls.Remove(room.RoomPanel.Label); }