Example #1
0
		private Obstacle GetClosestObstacle (List<Obstacle> obstacles, Vector2 start) {
			Obstacle closestObst = new Obstacle(Bounds);
			Obstacle closestEdge = GetClosestEdge(start);
			double closest = 30000;
			double distEdge = Vector2.Distance(start, closestEdge.Position);

			foreach (Obstacle o in obstacles) {
				double dist = Vector2.Distance(start, o.Position);
				if (dist < closest) {
					closest = dist;
					closestObst = o;
				}
			}

			if (distEdge < closest) {
				closestObst = closestEdge;
			}

			return closestObst;
		}
Example #2
0
		private Obstacle GetClosestEdge (Vector2 start) {
			Obstacle edgeObst = new Obstacle(Bounds);
			float closest = 30000;

			for (int i = 0; i < 4; ++i) {
				Vector2 projection = ProjectionOnEdge(start, _edges[i, 0], _edges[i, 1], _edgeLengths[i]);
				float dist = Vector2.Distance(start, projection);
				if (dist < closest) {
					closest = dist;
					edgeObst.Position = projection;
				}
			}

			return edgeObst;
		}
Example #3
0
        private void ProcessInput()
        {
            if ((Mouse.GetState().LeftButton == ButtonState.Pressed) && (Ticks % 10 == 0)) {
                Vector2 mouse = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                Obstacle obstacle = new Obstacle(Bounds);
                obstacle.Position = Vector2.Transform(mouse, Camera.InverseTransform);
                if (Bounds.Contains(Origin(obstacle.Position))) {
                    Obstacles.Add(obstacle);
                }
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed) {
                Vector2 mouse = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                mouse = Vector2.Transform(mouse, Camera.InverseTransform);
                if (Bounds.Contains(Origin(mouse))) {
                    Obstacles.Clear();
                }
            }
        }