コード例 #1
0
        public static bool NativeHullHullContact(ref NativeManifold result, RigidTransform transform1, NativeHull hull1, RigidTransform transform2, NativeHull hull2)
        {
            FaceQueryResult faceQuery1;

            HullCollision.QueryFaceDistance(out faceQuery1, transform1, hull1, transform2, hull2);
            if (faceQuery1.Distance > 0)
            {
                return(false);
            }

            FaceQueryResult faceQuery2;

            HullCollision.QueryFaceDistance(out faceQuery2, transform2, hull2, transform1, hull1);
            if (faceQuery2.Distance > 0)
            {
                return(false);
            }

            HullCollision.QueryEdgeDistance(out EdgeQueryResult edgeQuery, transform1, hull1, transform2, hull2);
            if (edgeQuery.Distance > 0)
            {
                return(false);
            }

            float kRelEdgeTolerance = 0.90f; //90%
            float kRelFaceTolerance = 0.95f; //95%
            float kAbsTolerance     = 0.5f * 0.005f;

            // Favor face contacts over edge contacts.
            float maxFaceSeparation = math.max(faceQuery1.Distance, faceQuery2.Distance);

            if (edgeQuery.Distance > kRelEdgeTolerance * maxFaceSeparation + kAbsTolerance)
            {
                CreateEdgeContact(ref result, edgeQuery, transform1, hull1, transform2, hull2);
            }
            else
            {
                // Favor first hull face to avoid face flip-flops.
                if (faceQuery2.Distance > kRelFaceTolerance * faceQuery1.Distance + kAbsTolerance)
                {
                    // 2 = reference, 1 = incident.
                    CreateFaceContact(ref result, faceQuery2, transform2, hull2, transform1, hull1, true);
                }
                else
                {
                    // 1 = reference, 2 = incident.
                    CreateFaceContact(ref result, faceQuery1, transform1, hull1, transform2, hull2, false);
                }
            }

            return(true);
        }
コード例 #2
0
            public bool Execute(NativeArray <BatchCollisionInput> hulls, NativeList <BatchCollisionResult> results)
            {
                var isCollision = false;

                for (int i = 0; i < hulls.Length; ++i)
                {
                    for (int j = i + 1; j < hulls.Length; j++)
                    {
                        var a = hulls[i];
                        var b = hulls[j];

                        if (HullCollision.IsColliding(a.Transform, a.Hull, b.Transform, b.Hull))
                        {
                            isCollision = true;
                            results.Add(new BatchCollisionResult
                            {
                                A = a,
                                B = b,
                            });
                        }
                    }
                }
                return(isCollision);
            }
コード例 #3
0
 public float3 Execute(RigidTransform t1, NativeHull hull1, float3 point)
 {
     return(HullCollision.ClosestPoint(t1, hull1, point));
 }
コード例 #4
0
 public bool Execute(RigidTransform t1, NativeHull hull1, float3 point)
 {
     return(HullCollision.Contains(t1, hull1, point));
 }
コード例 #5
0
 public bool Execute(RigidTransform t1, NativeHull hull1, RigidTransform t2, NativeHull hull2)
 {
     return(HullCollision.IsColliding(t1, hull1, t2, hull2));
 }