void ApplyCollision(Collision collision) { model.player.CopyFrom(copyCircle); Vector c = model.player.center; Vector d; if (Collision.Type.Corner == collision.type) { d = Geom.GetNearestPoint(collision.line, model.player.center); } else { d = Geom.GetCrossPosition(c, collision.line); } /* view.SetDebugNormal(new Line(d, new Vector(c))); */ Vector normal = Geom.Normalize(Geom.Sub(c, d)); float dv = -2.0f * Geom.Dot(model.player.velocity, normal); Vector normalDV = Geom.Mul(normal, dv); Vector reflected = Geom.Sum(normalDV, model.player.velocity); model.player.velocity.y = reflected.y * FADE_Y_INDEX; model.player.velocity.x = reflected.x * FADE_X_INDEX; }
public static bool IntersectCircleLineRectangles(Circle circle, Line line) { if (Geom.InRectangle(circle.GetRect(), line.a, line.b)) { Vector d = Geom.GetCrossPosition(circle.center, line); if (Geom.PointOnLine(d, line)) { return(true); } } return(false); }