public override void Execute(object parameter) { foreach (VisualCornerManipulator manipulator in _context.CornerManipulators) { _context.MapEntities.Remove(manipulator); } _context.CornerManipulators.Clear(); if (_context.LastSelected is VisualPolygonalBuilding) { VisualPolygonalBuilding polygon = (VisualPolygonalBuilding)_context.LastSelected; for (int i = 0; i < polygon.Corners.Count; i++) { VisualCornerManipulator manipulator = new VisualCornerManipulator(polygon.SourceEntity, polygon, i); _context.CornerManipulators.Add(manipulator); _context.MapEntities.Add(manipulator); } _context.CurrentlyManipulatedObject = _context.LastSelected; } else if (_context.LastSelected is WallElement) { WallElement wall = (WallElement)_context.LastSelected; for (int i = 0; i < 2; i++) { VisualCornerManipulator manipulator = new VisualCornerManipulator(wall.SourceEntity, wall, i); _context.CornerManipulators.Add(manipulator); _context.MapEntities.Add(manipulator); } _context.CurrentlyManipulatedObject = _context.LastSelected; } }
public UnitSizeTile(int type, Point pos, Logic model) { _model = model; this.Position = pos; if (type == 2) { Content[0] = new WallElement(pos, _model); Content[0].State.Anim.Frames[0] = new Rectangle(0, 0, 20, 20); Content[1] = new WallElement(new Point(pos.X + ElementSizeTile.ElementSize, pos.Y), _model); Content[1].State.Anim.Frames[0] = new Rectangle(20, 0, 20, 20); Content[2] = new WallElement(new Point(pos.X, pos.Y + ElementSizeTile.ElementSize), _model); Content[2].State.Anim.Frames[0] = new Rectangle(0, 20, 20, 20); Content[3] = new WallElement(new Point(pos.X + ElementSizeTile.ElementSize, pos.Y + ElementSizeTile.ElementSize), _model); Content[3].State.Anim.Frames[0] = new Rectangle(20, 20, 20, 20); } if (type == 1) { Content[0] = new IronElement(pos, _model); Content[1] = new IronElement(new Point(pos.X + ElementSizeTile.ElementSize, pos.Y), _model); Content[2] = new IronElement(new Point(pos.X, pos.Y + ElementSizeTile.ElementSize), _model); Content[3] = new IronElement(new Point(pos.X + ElementSizeTile.ElementSize, pos.Y + ElementSizeTile.ElementSize), _model); } if (type == 0) { } }
private void InitiatePolygonalBuilding() { if (CurrentPolygonWall == null) { // save mouse start position GlobalManagement.Instance.BuildingStartLocation = MousePosition.PxToMeter(); NewPolygonalBuildingWalls = new List <WallElement>(); } // create wall of building CurrentPolygonWall = new WallElement(new Wall() { Name = Constants.DefaultWallName }); Point meterPosition = MousePosition.PxToMeter(); CurrentPolygonWall.X1 = meterPosition.X; CurrentPolygonWall.Y1 = meterPosition.Y; CurrentPolygonWall.X2 = meterPosition.X; CurrentPolygonWall.Y2 = meterPosition.Y; NewPolygonalBuildingWalls.Add(CurrentPolygonWall); // add wall to map MapEntities.Add(CurrentPolygonWall); }
public void UpdateFloorToDimensions(VisualFloor floor) { // remove old walls ((IFloorEntity)floor.SourceEntity).Walls.RemoveAll(wall => wall.IsOuterWall); var toRemove = floor.MapEntities.Where(item => item is WallElement && ((WallElement)item).IsOuterWall).ToList(); if (toRemove != null) { for (int j = 0; j < toRemove.Count; j++) { foreach (VisualDoor door in ((WallElement)toRemove[j]).Doors) { floor.MapEntities.Remove(door); } floor.MapEntities.Remove(toRemove[j]); } } // update dimensions of map SetBoundingDimensions(); int i = 0; bool finished = false; Point offset = new Point(MapWidth / 2, MapHeight / 2); while (!finished) { Wall wall = new Wall() { Id = 0, Thickness = Constants.DefaultOutsideWallThickness, Name = Constants.DefaultOuterWallName, IsOuterWall = true }; WallElement visualWall = new WallElement(wall); visualWall.X1 = Corners[i].X + offset.X; visualWall.Y1 = Corners[i].Y + offset.Y; if (i == Corners.Count - 1) { visualWall.X2 = Corners[0].X + offset.X; visualWall.Y2 = Corners[0].Y + offset.Y; finished = true; } else { visualWall.X2 = Corners[i + 1].X + offset.X; visualWall.Y2 = Corners[i + 1].Y + offset.Y; i++; } floor.MapEntities.Add(visualWall); } }
private static void AddToSelection(WallElement newSelectedElement, bool asActiveObject) { var oldSelection = Selection.objects; var newSelection = new UnityEngine.Object[oldSelection.Length + 1]; oldSelection.CopyTo(newSelection, 0); newSelection[newSelection.Length - 1] = newSelectedElement.gameObject; Selection.objects = newSelection; if (asActiveObject) { Selection.activeGameObject = newSelectedElement.gameObject; } }
public bool CollidesWithWallElement(WallElement wall) { return(CollidesWithPolygon(wall.CornerPoints)); }
public static Vector2 RepelWhenClose(Copter thisCopter, WallElement wall, float repulsionMagnitude, float repulsionRadius) { CollisionResult cr = thisCopter.PolygonCircleCollision(wall.CornerPoints); return(RepelWhenClose(thisCopter, cr.CollisionPointOtherObject, repulsionMagnitude, repulsionRadius)); }
public WallElement InstsharpMedia2WallElement(InstaSharp.Models.Media post, double latitude, double longitude) { var wall = new WallElement { CreatedTime = post.CreatedTime.ToLocalTime(), FullName = post.User.FullName, Id = post.Id, Location = (post.Location != null ? post.Location.Name : null), LocationId = (post.Location != null ? post.Location.Id : 0), Longitude = (post.Location != null ? post.Location.Longitude : 0), Latitude = (post.Location != null ? post.Location.Latitude : 0), ProfilePictureUrl = post.User.ProfilePicture, Distance = 0, StandardResolutionUrl = post.Images.StandardResolution.Url, PhotoHeight = post.Images.StandardResolution.Height, PhotoWidth = post.Images.StandardResolution.Width, LowResoltionUrl = post.Images.LowResolution.Url, ThumbnailUrl = post.Images.Thumbnail.Url, Username = post.User.Username, VideoUrl = (post.Videos != null ? post.Videos.StandardResolution.Url : ""), VideoHeight = (post.Videos != null ? post.Videos.StandardResolution.Height : 0), VideoWidth = (post.Videos != null ? post.Videos.StandardResolution.Width : 0) }; var distance = (post.Location != null && latitude !=0 ? CalculateDistance(latitude, post.Location.Latitude, longitude, post.Location.Longitude) : 0); if (distance > 0) { wall.Distance = distance; wall.Bearing = (post.Location != null && latitude != 0 ? CalculateBearing(latitude, post.Location.Latitude, longitude, post.Location.Longitude) : 0); if (wall.Bearing >= 337.5 || wall.Bearing <= 22.5) wall.Direction = "N"; else if (wall.Bearing > 22.5 && wall.Bearing < 67.5) wall.Direction = "NE"; else if (wall.Bearing >= 67.5 && wall.Bearing <= 112.5) wall.Direction = "E"; else if (wall.Bearing > 112.5 && wall.Bearing < 157.5) wall.Direction = "SE"; else if (wall.Bearing >= 157.5 && wall.Bearing <= 202.5) wall.Direction = "S"; else if (wall.Bearing > 202.5 && wall.Bearing < 247.5) wall.Direction = "SW"; else if (wall.Bearing >= 247.5 && wall.Bearing <= 292.5) wall.Direction = "W"; else if (wall.Bearing > 292.5 && wall.Bearing < 337.5) wall.Direction = "NE"; } return wall; }
/// <summary> /// Event raised on mouse move in the ZoomAndPanControl. /// </summary> private void zoomAndPanControl_MouseMove(object sender, MouseEventArgs e) { if (mouseHandlingMode == MouseHandlingMode.Panning) { // // The user is left-dragging the mouse. // Pan the viewport by the appropriate amount. // Point curContentMousePoint = e.GetPosition(content); Vector dragOffset = curContentMousePoint - origContentMouseDownPoint; zoomAndPanControl.ContentOffsetX -= dragOffset.X; zoomAndPanControl.ContentOffsetY -= dragOffset.Y; e.Handled = true; } else if (mouseHandlingMode == MouseHandlingMode.Zooming) { Point curZoomAndPanControlMousePoint = e.GetPosition(zoomAndPanControl); Vector dragOffset = curZoomAndPanControlMousePoint - origZoomAndPanControlMouseDownPoint; double dragThreshold = 10; if (mouseButtonDown == MouseButton.Left && (Math.Abs(dragOffset.X) > dragThreshold || Math.Abs(dragOffset.Y) > dragThreshold)) { // // When Shift + left-down zooming mode and the user drags beyond the drag threshold, // initiate drag zooming mode where the user can drag out a rectangle to select the area // to zoom in on. // mouseHandlingMode = MouseHandlingMode.DragZooming; Point curContentMousePoint = e.GetPosition(content); InitDragZoomRect(origContentMouseDownPoint, curContentMousePoint); } e.Handled = true; } else if (mouseHandlingMode == MouseHandlingMode.DragZooming) { // // When in drag zooming mode continously update the position of the rectangle // that the user is dragging out. // Point curContentMousePoint = e.GetPosition(content); SetDragZoomRect(origContentMouseDownPoint, curContentMousePoint); e.Handled = true; } else if (mouseHandlingMode == MouseHandlingMode.DragObject) { // // Update position of transformation gizmo on overlay canvas to drag an object around // Point canvasPoint = FromZoomControlToCanvasCoordinates(e.GetPosition(content)); if (_vm.GizmoDragX) { _vm.GizmoX = Utils.PxToMeter(canvasPoint.X - (Gizmo.X + Gizmo.Width / 2)); } if (_vm.GizmoDragY) { _vm.GizmoY = Utils.PxToMeter(canvasPoint.Y - (Gizmo.Y + Gizmo.Height / 2)); } e.Handled = true; } else if (mouseHandlingMode == MouseHandlingMode.CreateRectangle && GlobalManagement.Instance.NewRectangleBuilding != null) { // Update rectangle that is being created Point point = e.GetPosition(content).PxToMeter(); Point start = GlobalManagement.Instance.BuildingStartLocation; GlobalManagement.Instance.NewRectangleBuilding.C = point.Sub(start); // update building in map _vm.MapEntities.Remove(GlobalManagement.Instance.NewRectangleBuilding); _vm.MapEntities.Add(GlobalManagement.Instance.NewRectangleBuilding); } else if (mouseHandlingMode == MouseHandlingMode.CreatePolygon && ((DataModel)_vm).CurrentPolygonWall != null) { // Update polygon wall which is currently being placed Point point = e.GetPosition(content).PxToMeter(); ((DataModel)_vm).CurrentPolygonWall.X2 = point.X; ((DataModel)_vm).CurrentPolygonWall.Y2 = point.Y; } else if (mouseHandlingMode == MouseHandlingMode.CreateWallAttachable && _vm.CurrentWallAttachable != null) { if (!zoomAndPanControl.IsMouseCaptured) { zoomAndPanControl.CaptureMouse(); } Point point = e.GetPosition(content).PxToMeter(); Point cursorCenteredPoint = point.Sub(new Point(Constants.DefaultDoorWidth / 2, Constants.DefaultOutsideWallThickness / 2).Rotate(_vm.CurrentWallAttachable.Orientation)); _vm.CurrentWallAttachable.X = cursorCenteredPoint.X; _vm.CurrentWallAttachable.Y = cursorCenteredPoint.Y; bool wallFound = false; // check if walls are in proximity foreach (IVisualElement mapEntity in _vm.MapEntities) { if (mapEntity is WallElement) { WallElement wall = (WallElement)mapEntity; if (wall.Contains(point)) { wallFound = true; _vm.CurrentWallAttachable.Orientation = wall.Orientation; cursorCenteredPoint = point.Sub(new Point(Constants.DefaultDoorWidth / 2, Constants.DefaultOutsideWallThickness / 2).Rotate(_vm.CurrentWallAttachable.Orientation)); Point pointOnWall = wall.ClosestPointOnWall(cursorCenteredPoint); _vm.CurrentWallAttachable.X = pointOnWall.X; _vm.CurrentWallAttachable.Y = pointOnWall.Y; _vm.CurrentWallAttachable.AttachedWall = wall; break; } } } if (!wallFound) { _vm.CurrentWallAttachable.AttachedWall = null; } } else if (mouseHandlingMode == MouseHandlingMode.CreateWall && _vm.CurrentWall != null) { Point point = e.GetPosition(content).PxToMeter(); _vm.CurrentWall.X2 = point.X; _vm.CurrentWall.Y2 = point.Y; } _vm.MousePosition = e.GetPosition(content); GlobalManagement.Instance.CanvasPosition = FromZoomControlToCanvasCoordinates(_vm.MousePosition); }