public MapCircle CreateColoredCircle(Brush fill, Brush stroke, Brush overlay) { var content = new MapCircle(); var frame = new Ellipse { Width = 28, Height = 28, Fill = new SolidColorBrush(Colors.Transparent) }; var ellipse = new Ellipse { Fill = fill, Stroke = stroke, StrokeThickness = 3, Width = 22, Height = 22 }; content.PointerEntered += (sender, args) => frame.Fill = overlay; content.PointerExited += (sender, args) => frame.Fill = new SolidColorBrush(Colors.Transparent); content.PointerCanceled += (sender, args) => frame.Fill = new SolidColorBrush(Colors.Transparent); content.Children.Add(frame); content.Children.Add(ellipse); return(content); }
void AddCircles() { var circle1 = new MapCircle ( MapPoint.MapPointWithGeoCoord(37.537094, 127.005470), // center 500, // radius Color.Argb(128, 255, 0, 0), // strokeColor Color.Argb(128, 0, 255, 0) // fillColor ); circle1.Tag = 1234; mMapView.AddCircle(circle1); var circle2 = new MapCircle ( MapPoint.MapPointWithGeoCoord(37.551094, 127.019470), // center 1000, // radius Color.Argb(128, 255, 0, 0), // strokeColor Color.Argb(128, 255, 255, 0) // fillColor ); circle2.Tag = 5678; mMapView.AddCircle(circle2); // 지도뷰의 중심좌표와 줌레벨을 Circle이 모두 나오도록 조정. MapPointBounds[] mapPointBoundsArray = { circle1.Bound, circle2.Bound }; MapPointBounds mapPointBounds = new MapPointBounds(mapPointBoundsArray); int padding = 50; // px mMapView.MoveCamera(CameraUpdateFactory.NewMapPointBounds(mapPointBounds, padding)); }
public void CircleRayCasting_ShouldReturnNull_WhenInOppositeDirection() { // arrange MapCircle circle = new MapCircle(1, 0, 1); Ray ray = new Ray(-3, 0, -1, 0); // act Trace trace = RayCast.CheckBulletTrace(ray, circle); // assert Assert.IsNull(trace); }
public void CircleRayCasting_ShouldReturnHitPosition_2() { // arrange MapCircle circle = new MapCircle(10, 10, 1); Ray ray = new Ray(20, 10, -1, 0); // act Trace trace = RayCast.CheckBulletTrace(ray, circle); // assert Assert.IsNotNull(trace); Assert.AreEqual(trace.Position, new Vector2(11, 10)); }
public LuaMapCircle AddCircle(LuaPoint geoLoc, double radius, LuaColor strokeColor, LuaColor fillColor) { Map map = ((Map)view); MapCircle mc = new MapCircle(); mc.setRadius(radius); mc.setStrokeColor(strokeColor.GetColorObject()); mc.setFillColor(fillColor.GetColorObject()); mc.setCenter(geoLoc.ToPoint()); LuaMapCircle lmc = new LuaMapCircle(mc); return(lmc); }
protected override void OnElementChanged(ElementChangedEventArgs <Map> e) { base.OnElementChanged(e); if (e.OldElement != null) { } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; circle = formsMap.circle; Control.GetMapAsync(this); } }
public void CircleRayCasting_ShouldReturnHitPosition_1() { // arrange MapCircle circle = new MapCircle(10, 10, 1); Ray ray = new Ray(0, 0, 1, 1); // act Trace trace = RayCast.CheckBulletTrace(ray, circle); // assert Assert.IsNotNull(trace); var c = Math.Sqrt(2) / 2; Vector2 expectedPosition = circle.Position - new Vector2(c, c); Assert.AreEqual(expectedPosition.X, trace.Position.X, 1e-6); Assert.AreEqual(expectedPosition.Y, trace.Position.Y, 1e-6); }
public static Trace CheckBulletTrace(Ray ray, MapCircle circle) { Vector2 h = Vector2.Subtract(circle.Position, ray.Origin); var lf = Vector2.Dot(ray.Direction, h); var s = (circle.RadiusSquared) - Vector2.Dot(h, h) + (lf * lf); // s=r^2-h^2+lf^2 if (s < 0.0 || lf < 0.0) { return(null); // no intersection points ? } s = (float)Math.Sqrt(s); // s=sqrt(r^2-h^2+lf^2) s = (lf < s && lf + s >= 0) ? -s : s; // S1 behind A ? AND S2 before A ? -> swap S1 <-> S2 Vector2 position = ray.Origin + Vector2.Multiply(ray.Direction, lf - s); Vector2 normal = Vector2.Normalize(circle.Position - position); return(new Trace(position, ray.Origin, circle, normal)); }
public static bool CheckIntersection(MapRect b, MapCircle s) { var x = Math.Abs(s.Position.X - b.Position.X); var y = Math.Abs(s.Position.Y - b.Position.Y); if (x > b.Width / 2 + s.Radius || y > b.Height / 2 + s.Radius) { return(false); } if (x <= b.Width / 2 || y <= b.Height / 2) { return(true); } var cornerDistance_sq = Math.Pow(x - b.Width / 2, 2) + Math.Pow(y - b.Height / 2, 2); return(cornerDistance_sq <= s.RadiusSquared); }
protected override void OnElementChanged(ElementChangedEventArgs <Map> e) { try { base.OnElementChanged(e); if (e.OldElement != null) { } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; circle = formsMap.Circle; Control.GetMapAsync(this); } } catch (Exception ex) { throw ex; } }
public MapObject CheckAnyIntersectionWithWorld(MapCircle s) { // Check intersection with all map objects foreach (MapObject obj in _mapState.MapObjects) { bool intersects = false; if (obj is MapRect) { intersects = Intersection.CheckIntersection((MapRect)obj, s); } else if (obj is MapCircle) { intersects = Intersection.CheckIntersection((MapCircle)obj, s); } if (intersects) { return(obj); } } return(null); }
public void ShouldNotAllowPassingThroughWalls() { // Arrange var r = _player.Radius; var mapRect = new MapRect(0, r * 2, 2, 2); _mapState.MapObjects.Add(mapRect); var config = new Config(); // Act _player.Keys.Add(KeyEnum.Down); for (int i = 1; i <= 200; i++) { _gameEngine.PhysicsEngine.ApplyPhysics(); var playerObject = new MapCircle(_player.Position, _player.Radius); Assert.IsFalse(Intersection.CheckIntersection(playerObject, mapRect)); } // Assert Assert.AreNotEqual(_player.Position.Y, 0); Assert.AreEqual(_player.Position.Y, mapRect.Position.Y - (mapRect.Height / 2) - _player.Radius, config.IntersectionInterval); }
private void mapViewer_MouseDown(object sender, MouseEventArgs e) { int x = mapViewer.ControlToMapX(e.X); int y = mapViewer.ControlToMapY(e.Y); if (m_SettingPoint) { xNumericUpDown.Value = x; yNumericUpDown.Value = y; zNumericUpDown.Value = mapViewer.GetMapHeight(new Point(x, y)); mapViewer.RemoveAllDrawObjects(); MapCircle circle = new MapCircle(3, new Point(x, y), mapViewer.Map, Color.White); MapCross cross = new MapCross(5, Color.White, new Point(x, y), mapViewer.Map); mapViewer.AddDrawObject(circle); mapViewer.AddDrawObject(cross); // Make color of button normal //ButtonSet.BackColor = SystemColors.Control; // Make location defined //((Loc)TreeCat.SelectedNode.Tag).IsDefined = true; //((Loc)TreeCat.SelectedNode.Tag).X = x; //((Loc)TreeCat.SelectedNode.Tag).Y = y; //((Loc)TreeCat.SelectedNode.Tag).Z = Map.GetMapHeight( new Point( x,y ) ); // End setting action m_SettingPoint = false; //IsModified = true; return; } mapViewer.Center = new Point(x, y); }
public Vector2 CalculatePossibleMovementVector(Player player, Vector2 speedvector, out double spareLength) { spareLength = 0; if (speedvector.IsDegenerated()) { return(Vector2.ZERO_VECTOR); } // Variables used to calculate speed vector var offset = 0d; var speedVectorLength = speedvector.Length(); var speedVectorNormalized = speedvector.Normalize(); var currentPrecision = speedVectorLength / 2d; do { // Create moved sphere var checkPosition = player.Position + (speedVectorNormalized * (offset + currentPrecision)); // Check for intersection var validationObject = new MapCircle(checkPosition, player.Radius); var intersectionObject = CheckAnyIntersectionWithWorld(validationObject); // Update new position and offset if (intersectionObject == null) // No object found, increase offset { offset += currentPrecision; } currentPrecision /= 2.0; } // Do this as long as we reach desired precision while (currentPrecision * 2 >= _config.IntersectionInterval); spareLength = speedVectorLength - offset; return(speedVectorNormalized * offset); }
public static bool CheckIntersection(MapCircle s1, MapCircle s2) { return(DistanceSquared(s1.Position, s2.Position) <= Math.Pow(s1.Radius + s2.Radius, 2)); }
public static bool CheckIntersection(MapCircle s, MapRect b) { return(CheckIntersection(b, s)); }
/** * (Ignore) */ public LuaMapCircle(MapCircle circle) { this.circle = circle; }
private void mapViewer_MouseDown(object sender, MouseEventArgs e) { int x = mapViewer.ControlToMapX(e.X); int y = mapViewer.ControlToMapY(e.Y); if ( m_SettingPoint ) { xNumericUpDown.Value = x; yNumericUpDown.Value = y; zNumericUpDown.Value = mapViewer.GetMapHeight(new Point(x, y)); mapViewer.RemoveAllDrawObjects(); MapCircle circle = new MapCircle( 3, new Point( x, y ), mapViewer.Map, Color.White ); MapCross cross = new MapCross( 5, Color.White, new Point( x, y ), mapViewer.Map ); mapViewer.AddDrawObject(circle); mapViewer.AddDrawObject(cross); // Make color of button normal //ButtonSet.BackColor = SystemColors.Control; // Make location defined //((Loc)TreeCat.SelectedNode.Tag).IsDefined = true; //((Loc)TreeCat.SelectedNode.Tag).X = x; //((Loc)TreeCat.SelectedNode.Tag).Y = y; //((Loc)TreeCat.SelectedNode.Tag).Z = Map.GetMapHeight( new Point( x,y ) ); // End setting action m_SettingPoint = false; //IsModified = true; return; } mapViewer.Center = new Point(x, y); }
private void Map_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int x = Map.ControlToMapX( e.X ); int y = Map.ControlToMapY( e.Y ); if ( SettingPoint ) { // Get a new point InX.Text = x.ToString(); InY.Text = y.ToString(); InZ.Text = Map.GetMapHeight( new Point( x, y ) ).ToString(); Map.RemoveAllDrawObjects(); MapCircle circle = new MapCircle( 3, new Point( x, y ), Map.Map, Color.White ); MapCross cross = new MapCross( 5, Color.White, new Point( x, y ), Map.Map ); Map.AddDrawObject( circle ); Map.AddDrawObject( cross ); // Make color of button normal ButtonSet.BackColor = SystemColors.Control; // Make location defined ((Loc)TreeCat.SelectedNode.Tag).IsDefined = true; ((Loc)TreeCat.SelectedNode.Tag).X = x; ((Loc)TreeCat.SelectedNode.Tag).Y = y; ((Loc)TreeCat.SelectedNode.Tag).Z = Map.GetMapHeight( new Point( x,y ) ); // End setting action SettingPoint = false; IsModified = true; return; } Map.Center = new Point( x, y ); }