/// <summary>
        /// Checks if a circle overlaps with this body.
        /// Begins with AABB checks.
        /// </summary>
        internal bool QueryCircle(
            TSVector2 origin,
            FP radius,
            int ticksBehind,
            bool bypassAABB = false)
        {
            HistoryRecord record = this.GetState(ticksBehind);

            // AABB check done in world space (because it keeps changing)
            if (bypassAABB == false)
            {
                if (record.aabb.QueryCircleApprox(origin, radius) == false)
                {
                    return(false);
                }
            }

            // Actual query on shapes done in body space
            TSVector2 bodySpaceOrigin = record.WorldToBodyPoint(origin);

            for (int i = 0; i < this.shapeCount; i++)
            {
                if (this.shapes[i].QueryCircle(bodySpaceOrigin, radius))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Checks if a point is contained in this body.
        /// Begins with AABB checks unless bypassed.
        /// </summary>
        internal bool QueryPoint(
            Vector2 point,
            int ticksBehind,
            bool bypassAABB = false)
        {
            HistoryRecord record = this.GetState(ticksBehind);

            // AABB check done in world space (because it keeps changing)
            if (bypassAABB == false)
            {
                if (record.aabb.QueryPoint(point) == false)
                {
                    return(false);
                }
            }

            // Actual query on shapes done in body space
            Vector2 bodySpacePoint = record.WorldToBodyPoint(point);

            for (int i = 0; i < this.shapeCount; i++)
            {
                if (this.shapes[i].QueryPoint(bodySpacePoint))
                {
                    return(true);
                }
            }
            return(false);
        }