コード例 #1
0
        public static unsafe void AabbCollider <T>(OverlapAabbInput input, [NoAlias] Collider *collider, [NoAlias] ref T collector)
            where T : struct, IOverlapCollector
        {
            if (!CollisionFilter.IsCollisionEnabled(input.Filter, collider->Filter))
            {
                return;
            }

            switch (collider->Type)
            {
            case ColliderType.Mesh:
                AabbMesh(input, (MeshCollider *)collider, ref collector);
                break;

            case ColliderType.Compound:
                AabbCompound(input, (CompoundCollider *)collider, ref collector);
                break;

            case ColliderType.Terrain:
                AabbTerrain(input, (TerrainCollider *)collider, ref collector);
                break;

            default:
                SafetyChecks.ThrowNotImplementedException();
                return;
            }
        }
コード例 #2
0
        private unsafe void UpdateCachedBoundingRadius()
        {
            m_BoundingRadius = 0;
            float3 center = BoundingVolumeHierarchy.Domain.Center;

            for (int i = 0; i < NumChildren; i++)
            {
                ref Child child = ref Children[i];

                float3 childFromCenter = math.transform(math.inverse(child.CompoundFromChild), center);
                float  radius          = 0;

                switch (child.Collider->Type)
                {
                case ColliderType.Sphere:
                case ColliderType.Box:
                case ColliderType.Capsule:
                case ColliderType.Quad:
                case ColliderType.Triangle:
                case ColliderType.Cylinder:
                case ColliderType.Convex:
                    radius = ((ConvexCollider *)child.Collider)->CalculateBoundingRadius(childFromCenter);
                    break;

                case ColliderType.Compound:
                    radius = ((CompoundCollider *)child.Collider)->CalculateBoundingRadius(childFromCenter);
                    break;

                case ColliderType.Mesh:
                    radius = ((MeshCollider *)child.Collider)->CalculateBoundingRadius(childFromCenter);
                    break;

                case ColliderType.Terrain:
                    Aabb terrainAabb = ((TerrainCollider *)child.Collider)->CalculateAabb();
                    radius = math.length(math.max(math.abs(terrainAabb.Max - childFromCenter), math.abs(terrainAabb.Min - childFromCenter)));
                    break;

                default:
                    SafetyChecks.ThrowNotImplementedException();
                    break;
                }
                m_BoundingRadius = math.max(m_BoundingRadius, radius);
            }