private static void AttachActionToCollider(ColliderViewModel vm, IPneumaticColliderExtensionProvider link) { var s = Math.Sign(link.OnPos - link.OffPos); var max = Math.Abs(link.OnPos - link.OffPos); var direction = GetDirectionVector(link.Direction) * s; link.EvaluateCollision = (e) => { double intersectValue = link.OnPos; bool state = link.Value; //var t = vm.CheckPanelIntersection(state, direction); var t = vm.CheckPanelIntersectionAsync(state, direction).Result; if (t.Item1 && (t.Item2 < max)) { intersectValue = t.Item2; link.HasCollision = true; link.CollisionOnPos = intersectValue * s; vm.Collided = true; } else { link.HasCollision = false; vm.Collided = false; } }; link.OnMovementCompleted = (e) => { if (e.Value) { vm.EvaluateOnState(); } }; link.OnMovementStarting = (e) => { if (!e.Value) { vm.EvaluateOffState(); } }; }
private static void EvaluateLinkDataByCollision(IPneumaticColliderExtensionProvider link, bool b, ref double onPos, double offPos, ref double tOn, ref double tOff) { if (b && link.EvaluateCollision != null) { link.EvaluateCollision(link); if (link.HasCollision) { var d1 = onPos - offPos; var d2 = link.CollisionOnPos - offPos; onPos = link.CollisionOnPos; tOn *= d2 / d1; } } else if (!b && link.HasCollision && (link is IPneumaticPresserExtensionProvider ppp)) { var d1 = onPos - offPos; var d2 = ppp.Pos - offPos; tOff *= d2 / d1; } }