Example #1
0
 protected Vector2 GetPenetrationDepth(Simplex simp, SupportDelegate support2, Vector2 startDirection, Vector2 Scale1, Vector2 Scale2)
 {
     return(GetPenetrationDepth(simp, support2, startDirection, Scale1, Scale2, FlipProperties.None, Vector2.Zero));
 }
Example #2
0
 public abstract Vector2 GetCollisionDepth(Simplex simp, ColliderElement other, Vector2 thisPosition, Vector2 otherPosition, Vector2 Scale1, Vector2 Scale2);
Example #3
0
 public abstract Vector2 GetCollisionDepth(Simplex simp, ColliderElement other, Vector2 thisPosition, Vector2 otherPosition, Vector2 Scale1, Vector2 Scale2, FlipProperties flipType, Vector2 flipPoint);
Example #4
0
        /// <summary>
        /// Returns a simplex and a boolean representing whether or not two objects collide
        /// </summary>
        /// <param name="startDirection">The starting direction for GJK</param>
        /// <param name="support2">The support function for the other shape</param>
        protected Tuple <bool, Simplex> IsColliding(Vector2 startDirection, SupportDelegate support2, Vector2 Scale1, Vector2 Scale2, FlipProperties flipType, Vector2 flipPoint)
        {
            //The flip options will only have to do with the second object, not the first. It shouldn't matter which one, but it should still be noted in case of confusion later on.
            //If necessary, I can extend this the same way I did originally to include a way to flip

            //So for the flipping procedure, we need to get the support of the flipped direction, and then flip the output of the support function.
            Simplex simplex   = new Simplex();
            Vector2 direction = startDirection;

            simplex.add(Scale1 * Support(direction) - Scale2 * FlippedSupport(support2, -direction, flipPoint, flipType) + startDirection);

            direction = -direction;

            while (true)
            {
                simplex.add(Scale1 * Support(direction) - Scale2 * FlippedSupport(support2, -direction, flipPoint, flipType) + startDirection);

                if (Vector2.Dot(simplex[simplex.Count - 1], direction) <= 0)
                {
                    return(new Tuple <bool, Simplex>(false, simplex));
                }
                else
                {
                    Vector2 a  = simplex[simplex.Count - 1];
                    Vector2 ao = -a;

                    if (simplex.Count == 3)
                    {
                        Vector2 b = simplex[1];
                        Vector2 c = simplex[0];

                        Vector2 ab = b - a;
                        Vector2 ac = c - a;

                        Vector2 abPerp = Simplex.TripleProduct(ac, ab, ab);
                        Vector2 acPerp = Simplex.TripleProduct(ab, ac, ac);

                        if (Vector2.Dot(abPerp, ao) > 0)
                        {
                            simplex.remove(0);
                            direction = abPerp;
                        }
                        else if (Vector2.Dot(acPerp, ao) > 0)
                        {
                            simplex.remove(1);
                            direction = acPerp;
                        }
                        else
                        {
                            return(new Tuple <bool, Simplex>(true, simplex));
                        }
                    }
                    else
                    {
                        Vector2 b      = simplex[0];
                        Vector2 ab     = b - a;
                        Vector2 bcPerp = Simplex.TripleProduct(ab, ao, ab);
                        direction = bcPerp;
                    }
                }
            }
            #endregion
        }
Example #5
0
 public override Vector2 GetCollisionDepth(Simplex simp, ColliderElement other, Vector2 thisPosition, Vector2 otherPosition, Vector2 Scale1, Vector2 Scale2, FlipProperties flipType, Vector2 flipPoint)
 {
     return(base.GetPenetrationDepth(simp, new SupportDelegate(other.Support), thisPosition - otherPosition, Scale1, Scale2, flipType, flipPoint));
 }
Example #6
0
 public override Vector2 GetCollisionDepth(Simplex simp, ColliderElement other, Vector2 thisPosition, Vector2 otherPosition, Vector2 Scale1, Vector2 Scale2)
 {
     return(base.GetPenetrationDepth(simp, new SupportDelegate(other.Support), thisPosition - otherPosition, Scale1, Scale2));
 }