public CustomCollider2D(Entity entity, CustomAABB aABB)
 {
     mEntity     = entity;
     mAABB       = aABB;
     mState      = ColliderState.Open;
     mAreas      = new List <Vector2i>();
     mIdsInAreas = new List <int>();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Checks whether a Vector2i p lies inside AABB2D a.
 /// </summary>
 /// <returns>
 /// True if the Vector2i is inside the AABB2D, otherwise false.
 /// </returns>
 /// <param name='a'>
 /// If set to <c>true</c> a.
 /// </param>
 /// <param name='p'>
 /// If set to <c>true</c> p.
 /// </param>
 public static bool PointInside2D(CustomAABB a, Vector2 p)
 {
     if (Mathf.Abs(a.CenterX - p.x) > a.HalfSizeX ||
         Mathf.Abs(a.CenterY - p.y) > a.HalfSizeY)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
 public static bool Overlaps2D(CustomAABB a, Vector2 otherCenter, Vector2 otherHalfSize)
 {
     if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f || otherHalfSize.x == 0.0f || otherHalfSize.y == 0.0f ||
         Mathf.Abs(a.CenterX - otherCenter.x) > a.HalfSizeX + otherHalfSize.x ||
         Mathf.Abs(a.CenterY - otherCenter.y) > a.HalfSizeY + otherHalfSize.y)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Checks for overlap between AABB2Ds a and b.
 /// </summary>
 /// <param name='a'>
 /// A reference to the first AABB2D.
 /// </param>
 /// <param name='b'>
 /// A reference to the second AABB2D.
 /// </param>
 public static bool Overlaps2D(CustomAABB a, CustomAABB b)
 {
     if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f || b.HalfSizeX == 0.0f || b.HalfSizeY == 0.0f ||
         Mathf.Abs(a.CenterX - b.CenterX) > a.HalfSizeX + b.HalfSizeX ||
         Mathf.Abs(a.CenterY - b.CenterY) > a.HalfSizeY + b.HalfSizeY)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
 public bool Overlaps2D(CustomAABB other)
 {
     if (HalfSizeX == 0.0f || HalfSizeY == 0.0f || other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
         Mathf.Abs(CenterX - other.CenterX) > HalfSizeX + other.HalfSizeX ||
         Mathf.Abs(CenterY - other.CenterY) > HalfSizeY + other.HalfSizeY)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
 public bool IsInterSectAABB(CustomAABB other)
 {
     if ((_minExtent.x <= other.maxExtent.x && _maxExtent.x >= other.minExtent.x) &&
      (_minExtent.y <= other.maxExtent.y && _maxExtent.y >= other.minExtent.y) &&
      (_minExtent.z <= other.maxExtent.z && _maxExtent.z >= other.minExtent.z))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 public static bool CircleVsCircle2D(CustomAABB a, CustomAABB b)
 {
     if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f || b.HalfSizeX == 0.0f || b.HalfSizeY == 0.0f)
     {
         return(false);
     }
     if (a.halfSize.x * a.halfSize.x + b.halfSize.x * b.halfSize.x < (a.Center - b.Center).sqrMagnitude)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
 public bool Overlaps(CustomAABB other)
 {
     if (HalfSizeX == 0.0f || HalfSizeY == 0.0f ||
         other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
         Mathf.Abs(CenterX - other.CenterX) > HalfSizeX + other.HalfSizeX ||
         Mathf.Abs(CenterY - other.CenterY) > HalfSizeY + other.HalfSizeY ||
         (HalfSizeZ > 0.0f && other.HalfSizeZ > 0.0f && Mathf.Abs(CenterZ - other.CenterZ) > HalfSizeZ + other.HalfSizeZ))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 9
0
 public static bool Overlaps(CustomAABB a, Vector3 otherCenter, Vector3 otherHalfSize)
 {
     if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f ||
         otherHalfSize.x == 0.0f || otherHalfSize.y == 0.0f ||
         Mathf.Abs(a.CenterX - otherCenter.x) > a.HalfSizeX + otherHalfSize.x ||
         Mathf.Abs(a.CenterY - otherCenter.y) > a.HalfSizeY + otherHalfSize.y ||
         (a.HalfSizeZ > 0.0f && otherHalfSize.z > 0.0f && Mathf.Abs(a.CenterZ - otherCenter.z) > a.HalfSizeZ + otherHalfSize.z))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
 public void Copy(CustomAABB other)
 {
     center       = other.center;
     halfSize     = other.halfSize;
     offset       = other.offset;
     baseOffset   = other.baseOffset;
     baseHalfSize = other.baseHalfSize;
     scale        = other.scale;
     rotation     = other.rotation;
     isCircle     = other.isCircle;
     flipped      = other.flipped;
 }
Exemplo n.º 11
0
    public static bool InterSectWithAABB(Ray ray, CustomAABB aabb)
    {
        float tmin = (aabb.minExtent.x - ray.origin.x) / ray.direction.normalized.x;
        float tmax = (aabb.maxExtent.x - ray.origin.x) / ray.direction.normalized.x;

        if (tmin > tmax)
        {
            float tmp = tmin;
            tmin = tmax;
            tmax = tmp;
        }

        float tymin = (aabb.minExtent.y - ray.origin.y) / ray.direction.normalized.y;
        float tymax = (aabb.maxExtent.y - ray.origin.y) / ray.direction.normalized.y;

        if (tymin > tymax)
        {
            float tmp = tymin;
            tymin = tymax;
            tymax = tmp;
        }

        if ((tmin > tymax) || (tymin > tmax))
            return false;

        if (tymin > tmin)
            tmin = tymin;

        if (tymax < tmax)
            tmax = tymax;

        float tzmin = (aabb.minExtent.z - ray.origin.z) / ray.direction.normalized.z;
        float tzmax = (aabb.maxExtent.z - ray.origin.z) / ray.direction.normalized.z;

        if (tzmin > tzmax)
        {
            float tmp = tzmin;
            tzmin = tzmax;
            tzmax = tmp;
        }

        if ((tmin > tzmax) || (tzmin > tmax))
            return false;
        
        if (tzmin > tmin)
            tmin = tzmin;

        if (tzmax < tmax)
            tmax = tzmax;

        return true;
    }
Exemplo n.º 12
0
 public static bool OverlapsUnsigned2D(CustomAABB a, CustomAABB b, out float overlapWidth, out float overlapHeight)
 {
     overlapWidth = overlapHeight = 0;
     if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f || b.HalfSizeX == 0.0f || b.HalfSizeY == 0.0f ||
         Mathf.Abs(a.Center.x - b.CenterX) > a.HalfSizeX + b.HalfSizeX ||
         Mathf.Abs(a.Center.y - b.CenterY) > a.HalfSizeY + b.HalfSizeY)
     {
         return(false);
     }
     overlapWidth  = (b.HalfSizeX + a.HalfSizeX) - Mathf.Abs(a.CenterX - b.CenterX);
     overlapHeight = (b.HalfSizeY + a.HalfSizeY) - Mathf.Abs(a.CenterY - b.CenterY);
     return(true);
 }
Exemplo n.º 13
0
 public bool OverlapsUnsigned2D(CustomAABB other, out float overlapWidth, out float overlapHeight)
 {
     overlapWidth = overlapHeight = 0;
     if (HalfSizeX == 0.0f || HalfSizeY == 0.0f || other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
         Mathf.Abs(Center.x - other.CenterX) > HalfSizeX + other.HalfSizeX ||
         Mathf.Abs(Center.y - other.CenterY) > HalfSizeY + other.HalfSizeY)
     {
         return(false);
     }
     overlapWidth  = (other.HalfSizeX + HalfSizeX) - Mathf.Abs(CenterX - other.CenterX);
     overlapHeight = (other.HalfSizeY + HalfSizeY) - Mathf.Abs(CenterY - other.CenterY);
     return(true);
 }
Exemplo n.º 14
0
 public static bool Collides2D(CustomAABB a, CustomAABB b)
 {
     if (a.isCircle && b.isCircle)
     {
         return(CircleVsCircle(a, b));
     }
     if (a.isCircle && !b.isCircle)
     {
         return(CircleVsAABB2D(b, a));
     }
     if (!a.isCircle && b.isCircle)
     {
         return(CircleVsAABB2D(a, b));
     }
     return(Overlaps(a, b));
 }
Exemplo n.º 15
0
 public bool OverlapsUnsigned(CustomAABB other, out float overlapWidth, out float overlapHeight, out float overlapDepth)
 {
     overlapWidth = overlapHeight = overlapDepth = 0;
     if (HalfSizeX == 0.0f || HalfSizeY == 0.0f ||
         other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
         Mathf.Abs(Center.x - other.CenterX) > HalfSizeX + other.HalfSizeX ||
         Mathf.Abs(Center.y - other.CenterY) > HalfSizeY + other.HalfSizeY ||
         (HalfSizeZ > 0.0f && other.HalfSizeZ > 0.0f && Mathf.Abs(Center.z - other.CenterZ) > HalfSizeZ + other.HalfSizeZ))
     {
         return(false);
     }
     overlapWidth  = (other.HalfSizeX + HalfSizeX) - Mathf.Abs(CenterX - other.CenterX);
     overlapHeight = (other.HalfSizeY + HalfSizeY) - Mathf.Abs(CenterY - other.CenterY);
     overlapDepth  = (other.HalfSizeZ + HalfSizeZ) - Mathf.Abs(CenterZ - other.CenterZ);
     return(true);
 }
Exemplo n.º 16
0
    public bool OverlapsSigned2D(CustomAABB other, out Vector2 overlap)
    {
        overlap = Vector2.zero;

        if (HalfSizeX == 0.0f || HalfSizeY == 0.0f || other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
            Mathf.Abs(CenterX - other.CenterX) > HalfSizeX + other.HalfSizeX ||
            Mathf.Abs(CenterY - other.CenterY) > HalfSizeY + other.HalfSizeY)
        {
            return(false);
        }

        overlap = new Vector2(Mathf.Sign(CenterX - other.CenterX) * ((other.HalfSizeX + HalfSizeX) - Mathf.Abs(CenterX - other.CenterX)),
                              Mathf.Sign(CenterY - other.CenterY) * ((other.HalfSizeY + HalfSizeY) - Mathf.Abs(CenterY - other.CenterY)));

        return(true);
    }
Exemplo n.º 17
0
    public static bool OverlapsUnsigned(CustomAABB a, CustomAABB b, out float overlapWidth, out float overlapHeight, out float overlapDepth)
    {
        overlapWidth = overlapHeight = overlapDepth = 0;
        if (a.HalfSizeX == 0.0f || a.HalfSizeY == 0.0f ||
            b.HalfSizeX == 0.0f || b.HalfSizeY == 0.0f ||
            Mathf.Abs(a.Center.x - b.CenterX) > a.HalfSizeX + b.HalfSizeX ||
            Mathf.Abs(a.Center.y - b.CenterY) > a.HalfSizeY + b.HalfSizeY ||
            (a.HalfSizeZ > 0.0f && b.HalfSizeZ > 0.0f && Mathf.Abs(a.Center.z - b.CenterZ) > a.HalfSizeZ + b.HalfSizeZ))
        {
            return(false);
        }

        overlapWidth  = (b.HalfSizeX + a.HalfSizeX) - Mathf.Abs(a.CenterX - b.CenterX);
        overlapHeight = (b.HalfSizeY + a.HalfSizeY) - Mathf.Abs(a.CenterY - b.CenterY);
        overlapDepth  = (b.HalfSizeZ + a.HalfSizeZ) - Mathf.Abs(a.CenterZ - b.CenterZ);
        return(true);
    }
Exemplo n.º 18
0
    //public Transform mTransform;

    //A physics body needs a reference to the entity it is apart of
    //We could also get this using GetComponent
    public PhysicsBody(Entity entity, CustomAABB aABB) : base(entity, aABB)
    {
        mCollisions = new List <CollisionData>();
        mGame       = GameManager.instance;
        mEntity     = entity;
        mAABB       = aABB;

        mPS = new PositionState();
        //mEntity = mEntity;
        //All the basics that every physics object needs upon initialization
        //colliderType = ColliderType.Pushbox;
        //mAABB.Scale = Vector2.one;

        //This should suffice for all physics bodies, maybe we'll come back to this
        //mAABB.Center = RoundVector(mEntity.Position);
        //mAABB.OffsetY = mAABB.HalfSizeY;

        //Check to see if we're in editorMode
    }
Exemplo n.º 19
0
    public bool OverlapsSigned(CustomAABB other, out Vector3 overlap)
    {
        overlap = Vector3.zero;

        if (HalfSizeX == 0.0f || HalfSizeY == 0.0f ||
            other.HalfSizeX == 0.0f || other.HalfSizeY == 0.0f ||
            Mathf.Abs(CenterX - other.CenterX) > HalfSizeX + other.HalfSizeX ||
            Mathf.Abs(CenterY - other.CenterY) > HalfSizeY + other.HalfSizeY ||
            (HalfSizeZ > 0.0f && other.HalfSizeZ > 0.0f && Mathf.Abs(CenterZ - other.CenterZ) > HalfSizeZ + other.HalfSizeZ))
        {
            return(false);
        }

        overlap = new Vector3(Mathf.Sign(CenterX - other.CenterX) * ((other.HalfSizeX + HalfSizeX) - Mathf.Abs(CenterX - other.CenterX)),
                              Mathf.Sign(CenterY - other.CenterY) * ((other.HalfSizeY + HalfSizeY) - Mathf.Abs(CenterY - other.CenterY)),
                              Mathf.Sign(CenterZ - other.CenterZ) * ((other.HalfSizeZ + HalfSizeZ) - Mathf.Abs(CenterZ - other.CenterZ)));

        return(true);
    }
Exemplo n.º 20
0
    /// <summary>
    /// 테스트버전.
    /// </summary>
    /// <param name="r"></param>
    /// <param name="aabb"></param>
    /// <returns></returns>
    public static bool InterSectWithAABB_TEST_Version(Ray r, CustomAABB aabb)
    {
        if (!aabb.isEnable) return false;

        Vector3 dirfrac;
        float t;
        // r.direction is unit direction vector of ray
        dirfrac.x = 1.0f / r.direction.x;
        dirfrac.y = 1.0f / r.direction.y;
        dirfrac.z = 1.0f / r.direction.z;
        // aabb.minExtent is the corner of AABB with minimal coordinates - left bottom, aabb.maxExtent is maximal corner
        // r.origin is origin of ray
        float t1 = (aabb.minExtent.x - r.origin.x) * dirfrac.x;
        float t2 = (aabb.maxExtent.x - r.origin.x) * dirfrac.x;
        float t3 = (aabb.minExtent.y - r.origin.y) * dirfrac.y;
        float t4 = (aabb.maxExtent.y - r.origin.y) * dirfrac.y;
        float t5 = (aabb.minExtent.z - r.origin.z) * dirfrac.z;
        float t6 = (aabb.maxExtent.z - r.origin.z) * dirfrac.z;

        float tmin = Mathf.Max(Mathf.Max(Mathf.Min(t1, t2), Mathf.Min(t3, t4)), Mathf.Min(t5, t6));
        float tmax = Mathf.Min(Mathf.Min(Mathf.Max(t1, t2), Mathf.Max(t3, t4)), Mathf.Max(t5, t6));

        // if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us
        if (tmax < 0)
        {
            t = tmax;
            return false;
        }

        // if tmin > tmax, ray doesn't intersect AABB
        if (tmin > tmax)
        {
            t = tmax;
            return false;
        }

        t = tmin;
        return true;
    }
Exemplo n.º 21
0
    public static bool CircleVsAABB2D(CustomAABB aabb, CustomAABB circle)
    {
        if (aabb.HalfSizeX == 0.0f || aabb.HalfSizeY == 0.0f || circle.HalfSizeX == 0.0f)
        {
            return(false);
        }

        float   s, d = 0;
        float   r   = circle.HalfSizeX;
        Vector2 min = aabb.Min();
        Vector2 max = aabb.Max();
        Vector2 c   = circle.Center;

        if (c.x < min.x)
        {
            s  = c.x - min.x;
            d += s * s;
        }
        else if (c.x > max.x)
        {
            s  = c.x - max.x;
            d += s * s;
        }

        if (c.y < min.y)
        {
            s  = c.y - min.y;
            d += s * s;
        }
        else if (c.y > max.y)
        {
            s  = c.y - max.y;
            d += s * s;
        }

        return(d <= r * r);
    }
Exemplo n.º 22
0
 public Blockbox(Entity entity, CustomAABB aABB) : base(entity, aABB)
 {
     mCollisions = new List <Hitbox>();
     mDealtWith  = new List <Hitbox>();
 }
Exemplo n.º 23
0
 public Hitbox(AttackObject entity, CustomAABB aABB) : base(entity, aABB)
 {
     attackObject = entity;
     mCollisions  = new List <IHurtable>();
     mDealtWith   = new List <IHurtable>();
 }
Exemplo n.º 24
0
 public Hurtbox(Entity entity, CustomAABB aABB) : base(entity, aABB)
 {
 }
Exemplo n.º 25
0
 /// <summary>
 /// Octree 중에 특정 AABB와 충돌하는 노드를 찾습니다.
 /// </summary>
 /// <param name="other"></param>
 /// <param name="root"></param>
 private CollideInfo CollideNodeWithAABB(CustomAABB other, COTNode root)
 {
     CollideInfo info;
     info.isCollide = false;
     info.hitBlockCenter = new Vector3(0, 0, 0);
     if(root.size == blockMinSize) 
     {
         info.isCollide = true;
         info.hitBlockCenter = root.center;
         return info;
     }
     for (int i = 0; i < 8; i++)
     {
         if ((root.childs[i] != null) &&
            (root.childs[i].aabb.IsInterSectAABB(other)))
         {
             return CollideNodeWithAABB(other, root.childs[i]);
         }
     }
     return info;
 }
Exemplo n.º 26
0
 public CollideInfo Collide(CustomAABB other)
 {
     return CollideNodeWithAABB(other, root);
 }