public static bool BoxVsBox(BoxShape a, BoxShape b, ref CollisionResult result, bool twoD)
 {
     return(CollisionTest.TestAABB(a.Min, a.Max, b.Min, b.Max, ref result, twoD));
 }
Beispiel #2
0
 private static bool TestCollisionShapes(ICollisionShape a, ICollisionShape b, ref CollisionResult result)
 {
     result = a.TestCollision(b);
     return(result.Collides);
 }
Beispiel #3
0
        public static bool TestAABB(Vector3 min0, Vector3 max0, Vector3 min1, Vector3 max1, ref CollisionResult result, bool twod = true)
        {
            _distances[0] = max1[0] - min0[0];
            _distances[1] = max0[0] - min1[0];
            _distances[2] = max1[2] - min0[2];
            _distances[3] = max0[2] - min1[2];

            var iter = 4;

            // test y if 3d
            if (!twod)
            {
                _distances[4] = max1[1] - min0[1];
                _distances[5] = max0[1] - min1[1];
                iter          = 6;
            }

            for (var i = 0; i < iter; i++)
            {
                if (_distances[i] < 0.0f)
                {
                    return(false);
                }

                if ((i == 0) || _distances[i] < result.Penetration)
                {
                    result.Penetration = _distances[i];
                    result.Normal      = _aabbNormals[i];
                }
            }

            return(true);
        }