public unsafe void Execute(ref ModifiableBodyPair pair)
            {
                Entity entityA = pair.Entities.EntityA;
                Entity entityB = pair.Entities.EntityB;

                if (entityA != entityB)
                {
                    bool isAPassThrough = PassThroughGroup.Exists(entityA);
                    bool isBPassThrough = PassThroughGroup.Exists(entityB);

                    bool disableA = false;
                    bool disableB = false;


                    if (isAPassThrough)
                    {
                        Unity.Physics.RigidBody passThroughRigidBody = Bodies[pair.BodyIndices.BodyAIndex];
                        Unity.Physics.RigidBody colliderRigidBody    = Bodies[pair.BodyIndices.BodyBIndex];

                        disableA = PassThroughSolid(ref entityA,
                                                    ref entityB,
                                                    ref PassThroughGroup,
                                                    ref passThroughRigidBody,
                                                    ref colliderRigidBody);
                    }

                    if (isBPassThrough)
                    {
                        Unity.Physics.RigidBody passThroughRigidBody = Bodies[pair.BodyIndices.BodyBIndex];
                        Unity.Physics.RigidBody colliderRigidBody    = Bodies[pair.BodyIndices.BodyAIndex];

                        disableB = PassThroughSolid(ref entityB,
                                                    ref entityA,
                                                    ref PassThroughGroup,
                                                    ref passThroughRigidBody,
                                                    ref colliderRigidBody);
                    }


                    if (disableA || disableB)
                    {
                        pair.Disable();
                    }
                }
            }
示例#2
0
        // Write a set of contact manifolds for a pair of bodies to the given stream.
        public static unsafe void BodyBody(ref PhysicsWorld world, BodyIndexPair pair, float timeStep, ref BlockStream.Writer contactWriter)
        {
            RigidBody rigidBodyA = world.Bodies[pair.BodyAIndex];
            RigidBody rigidBodyB = world.Bodies[pair.BodyBIndex];

            Collider *colliderA = rigidBodyA.Collider;
            Collider *colliderB = rigidBodyB.Collider;

            if (colliderA == null || colliderB == null || !CollisionFilter.IsCollisionEnabled(colliderA->Filter, colliderB->Filter))
            {
                return;
            }

            // Build combined motion expansion
            MotionExpansion expansion;
            {
                MotionExpansion GetBodyExpansion(int bodyIndex, NativeSlice <MotionVelocity> mvs)
                {
                    return(bodyIndex < mvs.Length ? mvs[bodyIndex].CalculateExpansion(timeStep) : MotionExpansion.Zero);
                }

                MotionExpansion expansionA = GetBodyExpansion(pair.BodyAIndex, world.MotionVelocities);
                MotionExpansion expansionB = GetBodyExpansion(pair.BodyBIndex, world.MotionVelocities);
                expansion = new MotionExpansion
                {
                    Linear  = expansionA.Linear - expansionB.Linear,
                    Uniform = expansionA.Uniform + expansionB.Uniform + world.CollisionTolerance
                };
            }

            var context = new Context
            {
                BodyIndices     = pair,
                BodyCustomDatas = new CustomDataPair {
                    CustomDataA = rigidBodyA.CustomData, CustomDataB = rigidBodyB.CustomData
                }
            };

            var worldFromA = new MTransform(rigidBodyA.WorldFromBody);
            var worldFromB = new MTransform(rigidBodyB.WorldFromBody);

            // Dispatch to appropriate manifold generator
            switch (colliderA->CollisionType)
            {
            case CollisionType.Convex:
                switch (colliderB->CollisionType)
                {
                case CollisionType.Convex:
                    ConvexConvex(context, ColliderKeyPair.Empty, colliderA, colliderB, worldFromA, worldFromB, expansion.MaxDistance, false, ref contactWriter);
                    break;

                case CollisionType.Composite:
                    ConvexComposite(context, ColliderKey.Empty, colliderA, colliderB, worldFromA, worldFromB, expansion, false, ref contactWriter);
                    break;
                }
                break;

            case CollisionType.Composite:
                switch (colliderB->CollisionType)
                {
                case CollisionType.Convex:
                    CompositeConvex(context, colliderA, colliderB, worldFromA, worldFromB, expansion, false, ref contactWriter);
                    break;

                case CollisionType.Composite:
                    CompositeComposite(context, colliderA, colliderB, worldFromA, worldFromB, expansion, false, ref contactWriter);
                    break;
                }
                break;
            }
        }