Example #1
0
 protected override bool GenerateCollisionRes(SICollider other, out SCollisionResult selfres, out SCollisionResult otherres)
 {
     if (other.GetType().Equals(typeof(SSphereCollider)))
     {
         var minDis = (other.position - position).sqrtMagnitude;
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             //SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     else if (other.GetType().Equals(typeof(SCapsuleCollider)))
     {
         var   oth    = other as SCapsuleCollider;
         Fix64 minDis = Fix64.MaxValue;
         var   atop   = position - oth.positionA;
         var   btop   = position - oth.positionB;
         var   ti     = atop.Dot(oth.up);
         var   tj     = btop.Dot(oth.up);
         var   w      = position - oth.positionA;
         if (ti * tj < Fix64.Zero)
         {
             minDis = w.sqrtMagnitude - w.Dot(oth.up) * w.Dot(up);
         }
         else if (ti <= Fix64.Zero)
         {
             minDis = atop.sqrtMagnitude;
         }
         else if (tj >= Fix64.Zero)
         {
             minDis = btop.sqrtMagnitude;
         }
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     selfres  = new SCollisionResult();
     otherres = new SCollisionResult();
     return(false);
 }
Example #2
0
 internal override void DetectCollision(SICollider other)
 {
     if (other.GetType().Equals(typeof(SSphereCollider)))
     {
         var minDis = (other.position - position).sqrtMagnitude;
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     else if (other.GetType().Equals(typeof(SCapsuleCollider)))
     {
         var   oth    = other as SCapsuleCollider;
         Fix64 minDis = Fix64.MaxValue;
         var   atop   = position - oth.positionA;
         var   btop   = position - oth.positionB;
         var   ti     = atop.Dot(oth.up);
         var   tj     = btop.Dot(oth.up);
         var   w      = position - oth.positionA;
         if (ti * tj < Fix64.Zero)
         {
             minDis = w.sqrtMagnitude - w.Dot(oth.up) * w.Dot(up);
         }
         else if (ti <= Fix64.Zero)
         {
             minDis = atop.sqrtMagnitude;
         }
         else if (tj >= Fix64.Zero)
         {
             minDis = btop.sqrtMagnitude;
         }
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
 }
Example #3
0
        internal override void DetectCollision(SICollider other)
        {
            if (other.GetType().Equals(typeof(SSphereCollider)))
            {
                Fix64 minDis = Fix64.MaxValue;
                var   atop   = other.position - positionA;
                var   btop   = other.position - positionB;
                var   ti     = atop.Dot(up);
                var   tj     = btop.Dot(up);
                var   w      = other.position - positionA;
                if (ti * tj < Fix64.Zero)
                {
                    minDis = w.sqrtMagnitude - w.Dot(up) * w.Dot(up);
                }
                else if (ti <= Fix64.Zero)
                {
                    minDis = atop.sqrtMagnitude;
                }
                else if (tj >= Fix64.Zero)
                {
                    minDis = btop.sqrtMagnitude;
                }
                if (minDis <= (radius + other.radius) * (radius + other.radius))
                {
                    SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                }
            }
            else if (other.GetType().Equals(typeof(SCapsuleCollider)))
            {
                Fix64 deltaRange = (Fix64)1 / (Fix64)1000;
                //SDebug.Log(deltaRange);

                SCapsuleCollider oth = other as SCapsuleCollider;
                if (Fix64.Abs(up.Dot(oth.up)) > deltaRange)
                {
                    Fix64 tIn1   = (oth.positionA.Dot(oth.up) - positionA.Dot(oth.up)) / up.Dot(oth.up);
                    Fix64 tIn2   = (oth.positionB.Dot(oth.up) - positionA.Dot(oth.up)) / up.Dot(oth.up);
                    Fix64 tInMin = ((tIn1 < tIn2) ? tIn1 : tIn2);
                    Fix64 tInMax = ((tIn1 < tIn2) ? tIn2 : tIn1);

                    //SDebug.Log(tInMin + "  " + tInMax);

                    var w    = positionA - oth.positionA;
                    var wf   = positionA - oth.positionB;
                    var u12  = up.Dot(oth.up);
                    var u1w  = up.Dot(w);
                    var u2w  = oth.up.Dot(w);
                    var u1wf = up.Dot(wf);


                    var minDis    = Fix64.MaxValue;
                    var minMiddle = Fix64.MaxValue;
                    var minLeft   = Fix64.MaxValue;
                    var minRight  = Fix64.MaxValue;

                    Fix64 et       = Fix64.Zero;
                    Fix64 etLeft   = Fix64.Zero;
                    Fix64 etMiddle = Fix64.Zero;
                    Fix64 etRight  = Fix64.Zero;

                    if (tInMin <= length && tInMax >= Fix64.Zero)
                    {
                        minMiddle = minValueFunc((Fix64)1 - u12 * u12, (Fix64)2 * (u1w - u12 * u2w), w.sqrtMagnitude - u2w * u2w,
                                                 MathF.max((Fix64)0, tInMin), MathF.min(length, tInMax), out etMiddle);
                        //SDebug.Log(gameObject.name+"  middle: " + minMiddle);
                    }
                    if (tInMin >= Fix64.Zero)
                    {
                        Fix64 temEtLeft1 = Fix64.Zero;
                        Fix64 temEtLeft2 = Fix64.Zero;

                        var temMin1 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude,
                                         Fix64.Zero, MathF.min(length, tInMin), out temEtLeft1);

                        var temMin2 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude,
                                         Fix64.Zero, MathF.min(length, tInMin), out temEtLeft2);

                        etLeft  = (temMin1 < temMin2) ? temEtLeft1 : temEtLeft2;
                        minLeft = MathF.min(temMin1, temMin2);
                        //SDebug.Log(gameObject.name+"  left: " + minLeft + " " + etLeft);
                    }
                    if (tInMax <= length)
                    {
                        Fix64 temEtRight1 = Fix64.Zero;
                        Fix64 temEtRight2 = Fix64.Zero;

                        var temMin1 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude,
                                         MathF.max(Fix64.Zero, tInMax), length, out temEtRight1);

                        var temMin2 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude,
                                         MathF.max(Fix64.Zero, tInMax), length, out temEtRight2);

                        etRight  = (temMin1 < temMin2) ? temEtRight1 : temEtRight2;
                        minRight = MathF.min(temMin1, temMin2);
                        //SDebug.Log(gameObject.name+"  right: " + minRight + " " + etRight);
                    }
                    if (minLeft <= minRight && minLeft <= minMiddle)
                    {
                        et     = etLeft;
                        minDis = minLeft;
                    }
                    else if (minMiddle <= minLeft && minMiddle <= minRight)
                    {
                        et     = etMiddle;
                        minDis = minMiddle;
                    }
                    else
                    {
                        et     = etRight;
                        minDis = minRight;
                    }
                    if (minDis <= (radius + oth.radius) * (radius + oth.radius))
                    {
                        SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                    }
                }
                else
                {
                    Fix64 minDis = Fix64.MaxValue;
                    Fix64 et     = Fix64.Zero;
                    SDebug.LogWarning("Vertical");


                    var p1tp2  = positionA - oth.positionA;
                    var p1tp2f = positionA - oth.positionB;
                    var ti     = p1tp2.Dot(oth.up);
                    var tj     = p1tp2f.Dot(oth.up);

                    if (ti * tj <= Fix64.Zero)
                    {
                        var a = Fix64.One;
                        var w = positionA - oth.positionA;
                        var b = (Fix64)2 * up.Dot(w);
                        var c = w.sqrtMagnitude - oth.up.Dot(w) * oth.up.Dot(w);


                        minDis =
                            minValueFunc(a, b, c, Fix64.Zero, length, out et);
                        //minDis = temMin;
                    }
                    else if (ti <= Fix64.Zero)
                    {
                        var w   = positionA - oth.positionA;
                        var u1w = up.Dot(w);
                        minDis =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude, Fix64.Zero, length, out et);
                    }
                    else if (tj >= Fix64.Zero)
                    {
                        var wf   = positionA - oth.positionB;
                        var u1wf = up.Dot(wf);
                        minDis =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude, Fix64.Zero, length, out et);
                    }

                    if (minDis <= (radius + oth.radius) * (radius + oth.radius))
                    {
                        SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                    }
                }
            }
        }
Example #4
0
 internal void DeleteColliderBody(SICollider collider)
 {
     _physicsObjectList.Remove(collider);
 }
Example #5
0
 protected override bool GenerateCollisionRes(SICollider other, out SCollisionResult selfres, out SCollisionResult otherres)
 {
     selfres  = new SCollisionResult();
     otherres = new SCollisionResult();
     return(false);
 }
Example #6
0
 internal void AddColliderBody(SICollider collider)
 {
     _physicsObjectList.Add(collider);
 }
Example #7
0
 internal abstract void DetectCollision(SICollider other);
Example #8
0
 protected abstract bool GenerateCollisionRes(SICollider other, out SCollisionResult selfres, out SCollisionResult otherres);