Example #1
0
        public bool checkOOBB(OOBB box)
        {
            // super maths here
            bool[] pointInside = new bool[4];

            for(int i = 0; i < 4; i++) // Loop through two perpendicular sides of the box
            {
                // Get normalised direction vector for box side
                Vector2 ABdir = box.corners[(i + 1) % 4] - box.corners[i];
                ABdir.Normalize();

                // Get perpendicular direction vector
                Vector2 PerpAB = new Vector2(ABdir.Y, ABdir.X * -1);

                // get the two points on the circle that intersect the perpendicular direction vector
                Vector2 circlePoint = centre + (radius * PerpAB);
                Vector2 otherCirclePoint = centre + (radius * (-1 * PerpAB));

                // See if either of those points is inisde the box
                pointInside[i] = box.pointInBox(circlePoint) || box.pointInBox(otherCirclePoint);
            }

            // If any of the circle points are inside the box
            if (pointInside[0] || pointInside[1] || pointInside[2] || pointInside[3])
            {
                return true;
            }
            else
            {
                foreach(Vector2 corner in box.corners)
                {
                    if(checkPoint(corner))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Example #2
0
        /// <summary>
        /// Does this box intesect another box?
        /// </summary>
        /// <param name="object2"></param>
        /// <returns></returns>
        public bool intersects(OOBB object2)
        {
            bool[] leftOfFace = new bool[4];

            for (int p = 0; p < 4; p++) // for each corner of object 2
            {
                if(pointInBox(object2.corners[p]))
                {
                    return true;
                }
            }

            for (int p = 0; p < 4; p++) // for each corner in object 1
            {
                if(object2.pointInBox(corners[p]))
                {
                    return true;
                }
            }

            return false;
        }
Example #3
0
        public Vector3 wallCollide(OOBB box)
        {
            bool[] pointInside = new bool[2];

            for (int i = 0; i < 2; i++) // Loop through two perpendicular sides of the box
            {
                // Get normalised direction vector for box side
                Vector2 ABdir = box.corners[(i + 1) % 4] - box.corners[i];
                ABdir.Normalize();

                // Get perpendicular direction vector
                Vector2 PerpAB = new Vector2(ABdir.Y, ABdir.X * -1);

                // get the two points on the circle that intersect the perpendicular direction vector
                Vector2 circlePoint = centre + (radius * PerpAB);
                Vector2 otherCirclePoint = centre + (radius * (-1 * PerpAB));

                // See if either of those points is inisde the box
                pointInside[i] = box.pointInBox(circlePoint) || box.pointInBox(otherCirclePoint);
            }

            // If any of the circle points are inside the box
            if (pointInside[0] || pointInside[1])
            {
                return box.wallNormal;
            }
            else
            {
                for (int i = 0; i < 4; i++) // foreach Vector2 corner in other.corners
                {
                    if (checkPoint(box.corners[i]))
                    {
                        // corner is inside circle
                        return box.wallNormal;
                    }
                }
            }

            return Vector3.Zero;
        }