Exemplo n.º 1
0
        public static bool DistanceBetween(BoxCollider box,
                                           RigidTransform boxTransform,
                                           SphereCollider sphere,
                                           RigidTransform sphereTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            var            boxWorldToLocal        = math.inverse(boxTransform);
            float3         sphereCenterInBoxSpace = math.transform(boxWorldToLocal, sphere.center + sphereTransform.pos);
            SphereCollider sphereInBoxSpace       = new SphereCollider(sphereCenterInBoxSpace, sphere.radius);
            bool           hit = DistanceQueries.DistanceBetween(box,
                                                                 sphereInBoxSpace,
                                                                 maxDistance,
                                                                 out DistanceQueries.ColliderDistanceResultInternal localResult);

            result = new ColliderDistanceResult
            {
                hitpointA = math.transform(boxTransform, localResult.hitpointA),
                hitpointB = math.transform(boxTransform, localResult.hitpointB),
                normalA   = math.rotate(boxTransform, localResult.normalA),
                normalB   = math.rotate(boxTransform, localResult.normalB),
                distance  = localResult.distance
            };
            return(hit);
        }
Exemplo n.º 2
0
        //All algorithms return a negative distance if inside the collider.
        public static bool DistanceBetween(float3 point, SphereCollider sphere, RigidTransform sphereTransform, float maxDistance, out PointDistanceResult result)
        {
            float3 pointInSphereSpace = point - sphereTransform.pos;
            bool   hit = DistanceQueries.DistanceBetween(pointInSphereSpace, sphere, maxDistance, out DistanceQueries.PointDistanceResultInternal localResult);

            result = new PointDistanceResult
            {
                hitpoint = localResult.hitpoint + sphereTransform.pos,
                distance = localResult.distance,
                normal   = localResult.normal
            };
            return(hit);
        }
Exemplo n.º 3
0
        public static bool DistanceBetween(CapsuleCollider capsuleA,
                                           RigidTransform aTransform,
                                           CapsuleCollider capsuleB,
                                           RigidTransform bTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            var             aWorldToLocal      = math.inverse(aTransform);
            var             BinASpaceTransform = math.mul(aWorldToLocal, bTransform);
            CapsuleCollider BinASpace          = new CapsuleCollider(math.transform(BinASpaceTransform, capsuleB.pointA),
                                                                     math.transform(BinASpaceTransform, capsuleB.pointB),
                                                                     capsuleB.radius);
            bool hit = DistanceQueries.DistanceBetween(capsuleA, BinASpace, maxDistance, out DistanceQueries.ColliderDistanceResultInternal localResult);

            result = BinAResultToWorld(localResult, aTransform);
            return(hit);
        }
Exemplo n.º 4
0
        public static bool DistanceBetween(BoxCollider box,
                                           RigidTransform boxTransform,
                                           CapsuleCollider capsule,
                                           RigidTransform capsuleTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            var boxWorldToLocal        = math.inverse(boxTransform);
            var capInBoxSpaceTransform = math.mul(boxWorldToLocal, capsuleTransform);
            var capsuleInBoxSpace      = new CapsuleCollider(math.transform(capInBoxSpaceTransform, capsule.pointA),
                                                             math.transform(capInBoxSpaceTransform, capsule.pointB),
                                                             capsule.radius);
            bool hit = DistanceQueries.DistanceBetween(box, capsuleInBoxSpace, maxDistance, out DistanceQueries.ColliderDistanceResultInternal localResult);

            result = BinAResultToWorld(localResult, boxTransform);
            return(hit);
        }
Exemplo n.º 5
0
        public static bool DistanceBetween(SphereCollider sphereA,
                                           RigidTransform aTransform,
                                           SphereCollider sphereB,
                                           RigidTransform bTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            SphereCollider bInASpace = new SphereCollider(sphereB.center + bTransform.pos - aTransform.pos, sphereB.radius);
            bool           hit       = DistanceQueries.DistanceBetween(sphereA, bInASpace, maxDistance, out DistanceQueries.ColliderDistanceResultInternal localResult);

            result = new ColliderDistanceResult
            {
                hitpointA = localResult.hitpointA + aTransform.pos,
                hitpointB = localResult.hitpointB + aTransform.pos,
                normalA   = localResult.normalA,
                normalB   = localResult.normalB,
                distance  = localResult.distance
            };
            return(hit);
        }
Exemplo n.º 6
0
        public static bool DistanceBetween(BoxCollider boxA,
                                           RigidTransform aTransform,
                                           BoxCollider boxB,
                                           RigidTransform bTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            var aWorldToLocal      = math.inverse(aTransform);
            var bWorldToLocal      = math.inverse(bTransform);
            var bInASpaceTransform = math.mul(aWorldToLocal, bTransform);
            var aInBSpaceTransform = math.mul(bWorldToLocal, aTransform);
            var hit = DistanceQueries.DistanceBetween(boxA,
                                                      boxB,
                                                      bInASpaceTransform,
                                                      aInBSpaceTransform,
                                                      maxDistance,
                                                      out DistanceQueries.ColliderDistanceResultInternal localResult);

            result = BinAResultToWorld(localResult, aTransform);
            return(hit);
        }