/// <seealso cref="Silver.Weight.Raw.Collide.Collider.Collide(Silver.Weight.Raw.Contact[], Silver.Weight.Raw.Body, Silver.Weight.Raw.Body)"> /// </seealso> public virtual int Collide(Contact[] contacts, Body bodyA, Body bodyB) { float x1 = bodyA.GetPosition().X; float y1 = bodyA.GetPosition().Y; float x2 = bodyB.GetPosition().X; float y2 = bodyB.GetPosition().Y; bool touches = bodyA.Shape.Bounds.Touches(x1, y1, bodyB.Shape.Bounds, x2, y2); if (!touches) { return 0; } Circle circleA = (Circle) bodyA.Shape; Circle circleB = (Circle) bodyB.Shape; touches = circleA.Touches(x1, y1, circleB, x2, y2); if (!touches) { return 0; } Vector2f normal = MathUtil.Sub(bodyB.GetPosition(), bodyA.GetPosition()); float sep = (circleA.Radius + circleB.Radius) - normal.Length(); normal.Normalise(); Vector2f pt = MathUtil.Scale(normal, circleA.Radius); pt.Add(bodyA.GetPosition()); contacts[0].Separation = - sep; contacts[0].Position = pt; contacts[0].Normal = normal; FeaturePair fp = new FeaturePair(); contacts[0].Feature = fp; return 1; }
/// <summary> Set the contents of this pair from another /// /// </summary> /// <param name="other">The other pair to populate this pair from /// </param> public virtual void SetFromOther(FeaturePair other) { inEdge1 = other.inEdge1; inEdge2 = other.inEdge2; outEdge1 = other.outEdge1; outEdge2 = other.outEdge2; }