Exemple #1
0
        private void DebugBoundingBox()
        {
            FAABB2D bounds1 = col1.EvaluateBounds();
            FAABB2D bounds2 = col2.EvaluateBounds();

            Debug.Log("BB Collision: " + bounds1.IsInside(bounds2));
        }
Exemple #2
0
 public static FAABB2D Multiply(FAABB2D box, FMatrix3x3 matrix)
 {
     return(new FAABB2D()
     {
         Min = matrix * box.Min,
         Max = matrix * box.Max
     });
 }
Exemple #3
0
 public static FAABB2D Multiply(FAABB2D box, Vector2 vec)
 {
     return(new FAABB2D()
     {
         Min = new Vector2(box.Min.x * vec.x, box.Min.y * vec.y),
         Max = new Vector2(box.Max.x * vec.x, box.Max.y * vec.y)
     });
 }
Exemple #4
0
 public static FAABB2D Add(FAABB2D box, Vector2 vec)
 {
     return(new FAABB2D()
     {
         Min = box.Min + vec,
         Max = box.Max + vec
     });
 }
Exemple #5
0
        public FAABB2D EvaluateBounds()
        {
            if (AreCachedBoundsInvalid() || !Application.isPlaying)
            {
                CachedBounds = EvaluateBounds_internal();
            }


            CachedBoundsWS = CachedBounds + transform.position;

            return(CachedBoundsWS);
        }
Exemple #6
0
        public static FAABB2D Combine(FAABB2D a, FAABB2D b)
        {
            Vector2 min = a.Min;
            Vector2 max = a.Max;

            min.x = Mathf.Min(a.Min.x, b.Min.x);
            min.y = Mathf.Min(a.Min.y, b.Min.y);
            max.x = Mathf.Max(a.Max.x, b.Max.x);
            max.y = Mathf.Max(a.Max.y, b.Max.y);

            return(new FAABB2D()
            {
                Min = min,
                Max = max
            });
        }
        private void DrawBounds()
        {
            FAABB2D bounds = EvaluateBounds();

            Handles.DrawDottedLines(new Vector3[]
            {
                bounds.Min,
                new Vector2(bounds.Min.x, bounds.Max.y),

                new Vector2(bounds.Min.x, bounds.Max.y),
                bounds.Max,

                bounds.Max,
                new Vector2(bounds.Max.x, bounds.Min.y),

                new Vector2(bounds.Max.x, bounds.Min.y),
                bounds.Min
            }, BOUNDS_DASH_SIZE);
        }
Exemple #8
0
        protected override FAABB2D EvaluateBounds_internal()
        {
            if (Collider.Length == 0)
            {
                return(new FAABB2D());
            }

            Collider[0].EvaluateBounds();

            FAABB2D res = Collider[0].CachedBounds;

            for (int i = 1; i < Collider.Length; i++)
            {
                Collider[i].EvaluateBounds();

                res = FAABB2D.Combine(res, Collider[i].CachedBounds);
            }

            return(res);
        }
Exemple #9
0
 public bool IsInside(FAABB2D other)
 {
     return(Min.x >= other.Min.x && Min.y >= other.Min.y &&
            Max.x <= other.Max.x && Max.y <= other.Max.y);
 }
Exemple #10
0
 public bool Intersects(FAABB2D other)
 {
     return(Min.x <= other.Max.x && other.Min.x <= Max.x &&
            Min.y <= other.Max.y && other.Min.y <= Max.y);
 }
Exemple #11
0
        public void GatherCollisionInformation(PhysCompoundCollider other)
        {
            if (other is PhysRigidbody)
            {
                PhysRigidbody rigid = other as PhysRigidbody;

                for (int c1 = 0; c1 < Collider.Length; c1++)
                {
                    FAABB2D bounds = other.Collider[c1].CachedBoundsWS;

                    for (int c2 = 0; c2 < other.Collider.Length; c2++)
                    {
                        if (bounds.Intersects(other.Collider[c2].CachedBoundsWS))
                        {
                            CollisionContact manifold = null;
                            bool             isBodyA  = false;

                            if (Collider[c1].IsColliding(other.Collider[c2], out manifold, out isBodyA))
                            {
                                if (isBodyA)
                                {
                                    manifold.A = this;
                                    manifold.B = rigid;
                                }
                                else
                                {
                                    manifold.A = rigid;
                                    manifold.B = this;
                                }

                                RegisterCollision(manifold, isBodyA);
                                rigid.RegisterCollision(manifold, !isBodyA);
                            }
                        }
                    }
                }
            }
            else
            {
                for (int c1 = 0; c1 < Collider.Length; c1++)
                {
                    FAABB2D bounds = other.Collider[c1].CachedBoundsWS;

                    for (int c2 = 0; c2 < other.Collider.Length; c2++)
                    {
                        if (bounds.Intersects(other.Collider[c2].CachedBoundsWS))
                        {
                            CollisionContact manifold = null;
                            bool             isBodyA  = false;

                            if (Collider[c1].IsColliding(other.Collider[c2], out manifold, out isBodyA))
                            {
                                if (isBodyA)
                                {
                                    manifold.A = this;
                                    manifold.B = other;
                                }
                                else
                                {
                                    manifold.A = other;
                                    manifold.B = this;
                                }

                                RegisterCollision(manifold, isBodyA);
                            }
                        }
                    }
                }
            }
        }