示例#1
0
        // Create contact points for a capsule and triangle in world space.
        public static unsafe void CapsuleTriangle(
            CapsuleCollider *capsuleA, PolygonCollider *triangleB,
            MTransform worldFromA, MTransform aFromB, float maxDistance,
            out Manifold manifold)
        {
            Assert.IsTrue(triangleB->Vertices.Length == 3);

            DistanceQueries.Result convexDistance = DistanceQueries.CapsuleTriangle(capsuleA, triangleB, aFromB);
            if (convexDistance.Distance < maxDistance)
            {
                // Build manifold
                manifold = new Manifold
                {
                    Normal = math.mul(worldFromA.Rotation, -convexDistance.NormalInA) // negate the normal because we are temporarily flipping to triangle A capsule B
                };
                MTransform worldFromB = Mul(worldFromA, aFromB);
                MTransform bFromA     = Inverse(aFromB);
                float3     normalInB  = math.mul(bFromA.Rotation, convexDistance.NormalInA);
                int        faceIndexB = triangleB->ConvexHull.GetSupportingFace(normalInB);
                if (FaceEdge(ref triangleB->ConvexHull, ref capsuleA->ConvexHull, faceIndexB, worldFromB, bFromA, -normalInB, convexDistance.Distance + capsuleA->Radius, ref manifold))
                {
                    manifold.Flip();
                }
                else
                {
                    manifold = new Manifold(convexDistance, worldFromA);
                }
            }
            else
            {
                manifold = new Manifold();
            }
        }
示例#2
0
 public unsafe bool CalculateDistance <T>(ColliderDistanceInput input, ref T collector) where T : struct, ICollector <DistanceHit>
 {
     fixed(TerrainCollider *target = &this)
     {
         return(DistanceQueries.ColliderCollider(input, (Collider *)target, ref collector));
     }
 }
示例#3
0
 // Create a contact point for a pair of spheres in world space.
 public static unsafe void SphereSphere(
     SphereCollider *sphereA, SphereCollider *sphereB,
     MTransform worldFromA, MTransform aFromB, float maxDistance,
     out Manifold manifold)
 {
     DistanceQueries.Result convexDistance = DistanceQueries.SphereSphere(sphereA, sphereB, aFromB);
     if (convexDistance.Distance < maxDistance)
     {
         manifold = new Manifold(convexDistance, worldFromA);
     }
     else
     {
         manifold = new Manifold();
     }
 }
示例#4
0
 // Create a contact point for a pair of capsules in world space.
 public static unsafe void CapsuleCapsule(
     CapsuleCollider *capsuleA, CapsuleCollider *capsuleB,
     MTransform worldFromA, MTransform aFromB, float maxDistance,
     out Manifold manifold)
 {
     // TODO: Should produce a multi-point manifold
     DistanceQueries.Result convexDistance = DistanceQueries.CapsuleCapsule(capsuleA, capsuleB, aFromB);
     if (convexDistance.Distance < maxDistance)
     {
         manifold = new Manifold(convexDistance, worldFromA);
     }
     else
     {
         manifold = new Manifold();
     }
 }
示例#5
0
 // Create a single point manifold between a capsule and a sphere in world space.
 public static unsafe void CapsuleSphere(
     CapsuleCollider *capsuleA, SphereCollider *sphereB,
     MTransform worldFromA, MTransform aFromB, float maxDistance,
     out Manifold manifold)
 {
     DistanceQueries.Result convexDistance = DistanceQueries.CapsuleSphere(
         capsuleA->Vertex0, capsuleA->Vertex1, capsuleA->Radius, sphereB->Center, sphereB->Radius, aFromB);
     if (convexDistance.Distance < maxDistance)
     {
         manifold = new Manifold(convexDistance, worldFromA);
     }
     else
     {
         manifold = new Manifold();
     }
 }
示例#6
0
        // Create a single point manifold between a triangle and sphere in world space.
        public static unsafe void TriangleSphere(
            PolygonCollider *triangleA, SphereCollider *sphereB,
            MTransform worldFromA, MTransform aFromB, float maxDistance,
            out Manifold manifold)
        {
            Assert.IsTrue(triangleA->Vertices.Length == 3);

            DistanceQueries.Result convexDistance = DistanceQueries.TriangleSphere(
                triangleA->Vertices[0], triangleA->Vertices[1], triangleA->Vertices[2], triangleA->Planes[0].Normal,
                sphereB->Center, sphereB->Radius, aFromB);
            if (convexDistance.Distance < maxDistance)
            {
                manifold = new Manifold(convexDistance, worldFromA);
            }
            else
            {
                manifold = new Manifold();
            }
        }