public void OnContactMoved(IntPtr windowHandle, Multitouch.Contracts.IContact contact) { var w = (from win in windowToBody.Keys where win.Contacts.Contains(contact.Id) select win).SingleOrDefault(); WindowContact winContact = null; if (w != null) { if (w.Contacts.TryGetValue(contact.Id, out winContact)) winContact.Update(contact); } Window window = GetWindow(windowHandle); if (window != null) { FixedHingeJoint joint; if (contactJoints.TryGetValue(contact.Id, out joint)) { joint.Anchor = new Vector2D(contact.X, contact.Y); // scale Body body = joint.Bodies.First(); WindowContacts contacts = window.Contacts; double previousDistance = 0; double currentDistance = 0; int divisor = 0; RECT windowRect = window.Rectangle; System.Windows.Point center = new System.Windows.Point(windowRect.Width / 2.0, windowRect.Height / 2.0); WindowContact[] contactsArray = contacts.ToArray(); for (int i = 0; i < contactsArray.Length; i++) { for (int j = i + 1; j < contactsArray.Length; j++) { Vector vector = NativeMethods.ScreenToClient(window, contactsArray[j].Position.ToPoint()).ToPoint() - NativeMethods.ScreenToClient(window, contactsArray[i].Position.ToPoint()).ToPoint(); currentDistance += vector.Length; center += vector; Vector previousVector = NativeMethods.ScreenToClient(window, contactsArray[j].PreviousPosition.ToPoint()).ToPoint() - NativeMethods.ScreenToClient(window, contactsArray[i].PreviousPosition.ToPoint()).ToPoint(); previousDistance += previousVector.Length; divisor++; } } if (divisor == 0) divisor = 1; previousDistance /= divisor; currentDistance /= divisor; center.X /= divisor; center.Y /= divisor; double delta = currentDistance / previousDistance; if (double.IsNaN(delta)) delta = 1; window.Scale *= delta; window.ScaleCenter = center; body.Transformation *= Matrix2x3.FromScale(new Vector2D(delta, delta)); } } else if (w != null && winContact != null) w.Contacts.Remove(contact.Id); }
public void OnContactRemoved(IntPtr windowHandle, Multitouch.Contracts.IContact contact) { Window window = GetWindow(windowHandle); if (window != null) { WindowContact winContact; if(window.Contacts.TryGetValue(contact.Id, out winContact)) winContact.Update(contact); window.Contacts.Remove(contact.Id); FixedHingeJoint joint; if (contactJoints.TryGetValue(contact.Id, out joint)) { joint.Lifetime.IsExpired = true; contactJoints.Remove(contact.Id); } } }
public void Frame(Multitouch.Service.Tests.Services.FrameData data) { parent.frameCounter++; }
public void OnNewContact(IntPtr windowHandle, Multitouch.Contracts.IContact contact) { Window window = GetWindow(windowHandle); if (window != null) { window.Contacts.Add(new WindowContact(contact)); Body body; if (windowToBody.TryGetValue(window, out body)) { NativeMethods.POINT point = new NativeMethods.POINT((int)contact.X, (int)contact.Y); Vector2D contactPoint = point.ToVector2D(); if (body.Shape.CanGetIntersection) { Vector2D temp = body.Matrices.ToBody * contactPoint; IntersectionInfo intersectionInfo; if (body.Shape.TryGetIntersection(temp, out intersectionInfo)) { FixedHingeJoint joint = new FixedHingeJoint(body, contactPoint, new Lifespan()); engine.AddJoint(joint); contactJoints[contact.Id] = joint; } } } } }
private void cancelButton_ContactRemoved(object sender, Multitouch.Framework.WPF.Input.ContactEventArgs e) { if (CancelButtonClick != null) { CancelButtonClick(this, EventArgs.Empty); } }