Exemplo n.º 1
0
        // Returns an AABB containing the CSO in A-space
        private static unsafe Aabb GetSupportingAabb(
            float3 *verticesA, int numVerticesA, float3 *verticesB, int numVerticesB, MTransform aFromB)
        {
            Aabb aabbA = new Aabb {
                Min = verticesA[0], Max = verticesA[0]
            };

            for (int i = 1; i < numVerticesA; i++)
            {
                aabbA.Min = math.min(aabbA.Min, verticesA[i]);
                aabbA.Max = math.max(aabbA.Max, verticesA[i]);
            }

            Aabb aabbB = new Aabb {
                Min = verticesB[0], Max = verticesB[0]
            };

            for (int i = 1; i < numVerticesB; i++)
            {
                aabbB.Min = math.min(aabbB.Min, verticesB[i]);
                aabbB.Max = math.max(aabbB.Max, verticesB[i]);
            }

            Aabb aabbBinA = Math.TransformAabb(aFromB, aabbB);

            return(new Aabb {
                Min = aabbA.Min - aabbBinA.Max, Max = aabbA.Max - aabbBinA.Min
            });
        }
Exemplo n.º 2
0
        // BoxBox() helper
        private static bool PointPlanes(MTransform aFromB, float3 halfExtA, float3 halfExtB, float maxDistance, ref float3 normalOut, ref float distanceOut)
        {
            // Calculate the AABB of box B in A-space
            Aabb aabbBinA;
            {
                Aabb aabbBinB = new Aabb {
                    Min = -halfExtB, Max = halfExtB
                };
                aabbBinA = Math.TransformAabb(aFromB, aabbBinB);
            }

            // Check for a miss
            float3 toleranceHalfExt = halfExtA + maxDistance;
            bool3  miss             = (aabbBinA.Min > toleranceHalfExt) | (-toleranceHalfExt > aabbBinA.Max);

            if (math.any(miss))
            {
                return(false);
            }

            // Return the normal with minimum separating distance
            float3 diff0     = aabbBinA.Min - halfExtA;  // positive normal
            float3 diff1     = -aabbBinA.Max - halfExtA; // negative normal
            bool3  greater01 = diff0 > diff1;
            float3 max01     = math.select(diff1, diff0, greater01);

            distanceOut = math.cmax(max01);

            int axis = IndexOfMaxComponent(max01);

            if (axis == 0)
            {
                normalOut = new float3(1.0f, 0.0f, 0.0f);
            }
            else if (axis == 1)
            {
                normalOut = new float3(0.0f, 1.0f, 0.0f);
            }
            else
            {
                normalOut = new float3(0.0f, 0.0f, 1.0f);
            }
            normalOut = math.select(normalOut, -normalOut, greater01);

            return(true);
        }
Exemplo n.º 3
0
 public Aabb CalculateAabb(RigidTransform transform)
 {
     return(Math.TransformAabb(transform, Terrain.Aabb));
 }