/* This implentation is wrong * /// <summary> * /// Determines if there is an intersection between the current object and a * /// triangle. * /// </summary> * /// <param name="vertex1">The first vertex of the triangle to test.</param> * /// <param name="vertex2">The second vertex of the triagnle to test.</param> * /// <param name="vertex3">The third vertex of the triangle to test.</param> * /// <returns>Whether the two objects intersected.</returns> * public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) * { * return Collision.BoxIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); * } */ /// <summary> /// Determines if there is an intersection between the current object and a /// <see cref="BoundingBox"/>. /// </summary> /// <param name="box">The box to test.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref BoundingBox box) { return(Collision.BoxIntersectsBox(ref this, ref box)); }
public void GjkBatteryTest() { Gjk gjk = new Gjk(); const int iterations = 10000; //Point to point test for (int i = 0; i < iterations; ++i) { gjk.Reset(); Vector3 point1 = Utilities.GenerateVector3(); Vector3 point2 = Utilities.GenerateVector3(); float expected = Vector3.Distance(point1, point2); float actual = gjk.GetMinimumDistance(v => { return(point1 - point2); }); Utilities.AreEqual(expected, actual); } //Sphere to sphere test for (int i = 0; i < iterations; ++i) { gjk.Reset(); BoundingSphere shape1 = new BoundingSphere(Utilities.GenerateVector3(), Utilities.GenerateFloat()); BoundingSphere shape2 = new BoundingSphere(Utilities.GenerateVector3(), Utilities.GenerateFloat()); float expected = Collision.DistanceSphereSphere(ref shape1, ref shape2); if (Collision.SphereIntersectsSphere(ref shape1, ref shape2)) { i--; continue; } float actual = gjk.GetMinimumDistance(v => { Vector3 a = shape1.SupportMapping(v); Vector3 b = shape2.SupportMapping(-v); return(a - b); }); Utilities.AreEqual(expected, actual); } //Box to box test for (int i = 0; i < iterations; ++i) { gjk.Reset(); BoundingBox shape1 = new BoundingBox(Utilities.GenerateVector3(), Utilities.GenerateVector3()); BoundingBox shape2 = new BoundingBox(Utilities.GenerateVector3(), Utilities.GenerateVector3()); float expected = Collision.DistanceBoxBox(ref shape1, ref shape2); if (Collision.BoxIntersectsBox(ref shape1, ref shape2)) { i--; continue; } float actual = gjk.GetMinimumDistance(v => { Vector3 a = shape1.SupportMapping(v); Vector3 b = shape2.SupportMapping(-v); return(a - b); }); Utilities.AreEqual(expected, actual); } }