Пример #1
0
        public static bool PointOBBcolliding(MthLib.Vector3 point, MthLib.Matrix3 obb)
        {
            //Find nessesary values
            MthLib.Vector3 diff    = point - new MthLib.Vector3(obb.m3, obb.m6, 0);
            MthLib.Vector3 xExtent = new MthLib.Vector3(obb.m1, obb.m4, 0);
            MthLib.Vector3 yExtent = new MthLib.Vector3(obb.m2, obb.m5, 0);
            //Check if the point is within the extents
            bool insideX = Math.Abs(diff.Dot(xExtent)) > xExtent.Magnitude();
            bool insideY = Math.Abs(diff.Dot(yExtent)) > yExtent.Magnitude();

            //If it is within both, it is inside the OBB
            return(insideX && insideY);
        }
Пример #2
0
        private static bool IsOverlapping(MthLib.Vector3 normal, Rect rect1, Rect rect2)
        {
            //Project the rect's corners onto the normal
            float dot1 = normal.Dot(rect1.FL);
            float dot2 = normal.Dot(rect1.FR);
            float dot3 = normal.Dot(rect1.BL);
            float dot4 = normal.Dot(rect1.BR);
            //Find the furthest points
            float min1 = Math.Min(dot1, Math.Min(dot2, Math.Min(dot3, dot4)));
            float max1 = Math.Max(dot1, Math.Max(dot2, Math.Max(dot3, dot4)));

            //Repeat for the second rect
            dot1 = normal.Dot(rect2.FL);
            dot2 = normal.Dot(rect2.FR);
            dot3 = normal.Dot(rect2.BL);
            dot4 = normal.Dot(rect2.BR);
            float min2 = Math.Min(dot1, Math.Min(dot2, Math.Min(dot3, dot4)));
            float max2 = Math.Max(dot1, Math.Max(dot2, Math.Max(dot3, dot4)));

            //Are the projections overlapping?
            return(min1 <= max2 && min2 <= max1);
        }