예제 #1
0
            public void AddColliderKeys(ColliderKey *keys, int count)
            {
                var colliderKeys = new ColliderKeyPair {
                    ColliderKeyA = m_ConvexColliderKey, ColliderKeyB = m_ConvexColliderKey
                };
                CollisionFilter filter = m_ConvexColliderA->Filter;

                // Collide the convex A with all overlapping leaves of B
                switch (m_CompositeColliderB->Type)
                {
                // Special case meshes (since we know all polygons will be built on the fly)
                case ColliderType.Mesh:
                {
                    Mesh *mesh           = &((MeshCollider *)m_CompositeColliderB)->Mesh;
                    uint  numMeshKeyBits = mesh->NumColliderKeyBits;
                    var   polygon        = new PolygonCollider();
                    polygon.InitEmpty();
                    for (int i = 0; i < count; i++)
                    {
                        ColliderKey compositeKey = m_CompositeColliderKeyPath.GetLeafKey(keys[i]);
                        uint        meshKey      = compositeKey.Value >> (32 - (int)numMeshKeyBits);
                        if (mesh->GetPolygon(meshKey, filter, ref polygon))
                        {
                            if (m_Flipped)
                            {
                                colliderKeys.ColliderKeyA = compositeKey;
                            }
                            else
                            {
                                colliderKeys.ColliderKeyB = compositeKey;
                            }

                            switch (m_ConvexColliderA->CollisionType)
                            {
                            case CollisionType.Convex:
                                ConvexConvex(
                                    m_Context, colliderKeys, m_ConvexColliderA, (Collider *)&polygon,
                                    m_WorldFromA, m_WorldFromB, m_CollisionTolerance, m_Flipped);
                                break;

                            case CollisionType.Terrain:
                                TerrainConvex(
                                    m_Context, colliderKeys, m_ConvexColliderA, (Collider *)&polygon,
                                    m_WorldFromA, m_WorldFromB, m_CollisionTolerance, m_Flipped);
                                break;

                            default:         // GetLeaf() may not return a composite collider
                                throw new NotImplementedException();
                            }
                        }
                    }
                }
                break;

                // General case for all other composites (compounds, compounds of meshes, etc)
                default:
                {
                    for (int i = 0; i < count; i++)
                    {
                        ColliderKey compositeKey = m_CompositeColliderKeyPath.GetLeafKey(keys[i]);
                        m_CompositeColliderB->GetLeaf(compositeKey, out ChildCollider leaf);
                        if (CollisionFilter.IsCollisionEnabled(filter, leaf.Collider->Filter))      // TODO: shouldn't be needed if/when filtering is done fully by the BVH query
                        {
                            if (m_Flipped)
                            {
                                colliderKeys.ColliderKeyA = compositeKey;
                            }
                            else
                            {
                                colliderKeys.ColliderKeyB = compositeKey;
                            }

                            MTransform worldFromLeafB = Mul(m_WorldFromB, new MTransform(leaf.TransformFromChild));
                            switch (leaf.Collider->CollisionType)
                            {
                            case CollisionType.Convex:
                                ConvexConvex(
                                    m_Context, colliderKeys, m_ConvexColliderA, leaf.Collider,
                                    m_WorldFromA, worldFromLeafB, m_CollisionTolerance, m_Flipped);
                                break;

                            case CollisionType.Terrain:
                                ConvexTerrain(
                                    m_Context, colliderKeys, m_ConvexColliderA, leaf.Collider,
                                    m_WorldFromA, worldFromLeafB, m_CollisionTolerance, m_Flipped);
                                break;

                            default:         // GetLeaf() may not return a composite collider
                                throw new NotImplementedException();
                            }
                        }
                    }
                }
                break;
                }
            }
예제 #2
0
 public unsafe void AddColliderKeys(ColliderKey *keys, int count)
 {
     throw new NotSupportedException();
 }
예제 #3
0
 public unsafe void AddColliderKeys(ColliderKey *keys, int count) => SafetyChecks.ThrowNotSupportedException();