public override void MouseDown(object sender, MouseEventArgs e) { base.MouseDown(sender, e); // Save the location the user clicked on as target point. targetPoint = new DirectionalPoint(e.Location, 0); paths.AsParallel().ForAll(x => x.Target = targetPoint); }
public override void MouseDown(object sender, MouseEventArgs e) { base.MouseDown(sender, e); // Distance cursor - start point. int dx = paths[0].Start.X - e.X; int dy = paths[0].Start.Y - e.Y; uint distanceStart = (uint)Math.Sqrt(dx * dx + dy * dy); // Distance cursor - target point. dx = paths[0].Target.X - e.X; dy = paths[0].Target.Y - e.Y; uint distanceTarget = (uint)Math.Sqrt(dx * dx + dy * dy); // Start moving / rotating, if the cursor is near a point. if (distanceStart <= selectionDistance || distanceTarget <= selectionDistance) { // Choose the point. Note that the start and target points // of all DubinsPath objects reference the same data. if (distanceStart < distanceTarget) { chosenPoint = paths[0].Start; } else { chosenPoint = paths[0].Target; } // Activate moving or rotating mode // dependant on the button pressed. if (e.Button == MouseButtons.Left) { moving = true; } else if (e.Button == MouseButtons.Right) { rotating = true; } } }