public void Paint(PaintEventArgs e) { for (int i = 0; i < Spheres.Count - 1; i++) { for (int j = i + 1; j < Spheres.Count; j++) { Sphere3d s1 = Spheres[i]; Sphere3d s2 = Spheres[j]; float? t = CollisionSystem.CalculateCollision(s1, s2); if (t.HasValue && t.Value != 0) { s1.Move(t.Value, ref c1); //collp.X = s1.Direction.X * t.Value + s1.Position.X; //collp.Y = s1.Direction.Y * t.Value + s1.Position.Y; e.Graphics.DrawCircle(Pens.Red, c1.Position.X, c1.Position.Y, s1.Radius); s2.Move(t.Value, ref c2); //collp.X = s2.Direction.X * t.Value + s2.Position.X; //collp.Y = s2.Direction.Y * t.Value + s2.Position.Y; e.Graphics.DrawCircle(Pens.Red, c2.Position.X, c2.Position.Y, s2.Radius); e.Graphics.DrawLine(CollisionCirecleCentersPen, c1.Position.X, c1.Position.Y, c2.Position.X, c2.Position.Y); CollisionSystem.CalculateReaction(0, c1, c2); float tx = c1.Position.X + c1.Direction.X; float ty = c1.Position.Y + c1.Direction.Y; e.Graphics.DrawLine(Pens.Black, c1.Position.X, c1.Position.Y, tx, ty); } } } }
private void RecalculateCollisionMatrix() { for (int i = 0; i < Objects.Count - 1; i++) { for (int j = i + 1; j < Objects.Count; j++) { collisionMatrix[i, j] = CollisionSystem.CalculateCollision(Objects[i], Objects[j]); } } }
public void RecalculateCollisions(int sphereIndex) { for (int i = 0; i < Objects.Count; i++) { if (i != sphereIndex) { int a = Math.Min(i, sphereIndex); int b = Math.Max(i, sphereIndex); collisionMatrix[a, b] = CollisionSystem.CalculateCollision(Objects[a], Objects[b]); } } }