void OnGotContactCapture(object sender, ContactEventArgs e) { FrameworkElement element = (FrameworkElement)e.Source; FrameworkElement container = ItemsControl.ContainerFromElement(null, element) as FrameworkElement; if (container != null) { element = container; } Body body; if (elementToBody.TryGetValue(element, out body)) { Point position = e.GetPosition(this); Vector2D contactPoint = position.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()); joint.Softness = 0.3; engine.AddJoint(joint); contactJoints[e.Contact.Id] = joint; } } } SetZTop(element); }
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; } } } } }
public static DisposeCallback RegisterMousePicking(DemoOpenInfo info, MouseButton button) { FixedHingeJoint joint = null; EventHandler <ViewportMouseButtonEventArgs> mouseDown = delegate(object sender, ViewportMouseButtonEventArgs e) { if (e.Button == button) { IntersectionInfo temp; Body body = null; foreach (Body b in info.Scene.Engine.Bodies) { Vector2D bodyVertex = b.Matrices.ToBody * e.Position; if (b.Shape.CanGetIntersection && !b.IsBroadPhaseOnly && !b.IgnoresPhysicsLogics && b.Shape.TryGetIntersection(bodyVertex, out temp)) { body = b; break; } } if (body != null) { joint = new FixedHingeJoint(body, e.Position, new Lifespan()); info.Scene.Engine.AddJoint(joint); } } }; EventHandler <ViewportMouseMotionEventArgs> mouseMotion = delegate(object sender, ViewportMouseMotionEventArgs e) { if (joint != null) { joint.Anchor = e.Position; } }; EventHandler <ViewportMouseButtonEventArgs> mouseUp = delegate(object sender, ViewportMouseButtonEventArgs e) { if (e.Button == button) { if (joint != null) { joint.Lifetime.IsExpired = true; joint = null; } } }; info.Viewport.MouseDown += mouseDown; info.Viewport.MouseUp += mouseUp; info.Viewport.MouseMotion += mouseMotion; return(delegate() { info.Viewport.MouseDown -= mouseDown; info.Viewport.MouseUp -= mouseUp; info.Viewport.MouseMotion -= mouseMotion; }); }
void OnContactRemoved(object sender, ContactEventArgs e) { if (e.Contact.Id == firstContactId) { scrollJoint.Lifetime.IsExpired = true; scrollJoint = null; firstContactId = null; } }
void OnNewContact(object sender, NewContactEventArgs e) { if (!firstContactId.HasValue) { firstContactId = e.Contact.Id; startPoint = e.GetPosition(this); startOffset.X = HorizontalOffset; startOffset.Y = VerticalOffset; Vector2D contactPoint = startPoint.ToVector2D(); scrollJoint = new FixedHingeJoint(Body, contactPoint, new Lifespan()); engine.AddJoint(scrollJoint); } }