private void OnContactMove(ScatterRectangle rectangle, FingerEventArgs e) { int index = (int)rectangle.Category; if (!_elementsContacts[index].ContainsKey(e.FingerID)) return; Point position = rectangle.TranslatePoint(e.Position, _canvas); _elementsContacts[index][e.FingerID].UpdatePosition(position); FixedHingeJoint joint; if (_contactJoints.TryGetValue(e.FingerID, out joint)) { // move joint.Anchor = new Vector2D((Scalar)position.X, (Scalar)position.Y); } }
private void OnNewContact(ScatterRectangle rectangle, FingerEventArgs e) { int index = (int)rectangle.Category; //not a new contact if (_elementsContacts[index].ContainsKey(e.FingerID)) return; //e.Position stands the whole table, get the relative position of Target, i.e. Design Window here Point position = rectangle.TranslatePoint(e.Position, _canvas); Vector2D contactPoint = new Vector2D((Scalar)position.X, (Scalar)position.Y); _fingers.Add(position); Body body = _bodies[index]; if (body.Shape.CanGetIntersection) { FixedHingeJoint joint = PhysicsHelper.FixedHingeJointFactory(body, contactPoint, new Lifespan()); _engine.AddJoint(joint); _contactJoints[e.FingerID] = joint; _contactBody[e.FingerID] = body; _elementsContacts[index].Add(e.FingerID, new Contact(e.FingerID, position)); } rectangle.CaptureFinger(e.FingerID); }
private ScatterRectangle HitTest(ScatterRectangle rectangle, FingerEventArgs args) { Point global = rectangle.TranslatePoint(args.Position, _canvas), temp; ScatterRectangle curr; BitmapImage bi; byte[] pixel = new byte[4]; for (int i = 0; i < _canvas.Pieces.Length; ++i) { curr = _canvas.Pieces[i]; temp = _canvas.TranslatePoint(global, curr); if (temp.X > curr.Width || temp.X < 0 || temp.Y > curr.Height || temp.Y < 0) continue; bi = (curr.Background as ImageBrush).ImageSource as BitmapImage; bi.CopyPixels(new System.Windows.Int32Rect((int) (temp.X / curr.Width * bi.PixelWidth), (int) (temp.Y / curr.Height * bi.PixelHeight), 1, 1), pixel, bi.PixelWidth * 4, 0); if (pixel[3] != 0) return curr; } return null; }