Would you like to react to this message? Create an account in a few clicks or log in to continue.

    Collision Detection

    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    Collision Detection Empty Collision Detection

    Post  Admin Sat Mar 06, 2010 3:28 pm


    • Collision detection is a constant balance between performance and accuracy.
    The more accurate an algorithm is, the more of a performance hit is usually
    incurred.


    • The bounding-box algorithm for collision detection is one of the most simple
    and straightforward algorithms. If you “draw” an imaginary box around each
    object, you can easily tell which box is colliding with another box.

    • You can speed up collision detection while improving accuracy by combining
    methods. Use a large box to determine if it’s worth the time to check the smaller
    boxes surrounding sections of an object, or implement a grid-based system to
    avoid unnecessary collision checks between objects that are not close together.
    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    Collision Detection Empty Collide method example

    Post  Admin Sat Mar 06, 2010 3:30 pm

    Method in class scope to be used in Update cycle

    protected bool Collide()
    {
    Rectangle ringsRect = new Rectangle(
    (int)ringsPosition.X + ringsCollisionRectOffset,
    (int)ringsPosition.Y + ringsCollisionRectOffset,
    ringsFrameSize.X - (ringsCollisionRectOffset * 2),
    ringsFrameSize.Y - (ringsCollisionRectOffset * 2));
    Rectangle skullRect = new Rectangle(
    (int)skullPosition.X + skullCollisionRectOffset,
    (int)skullPosition.Y + skullCollisionRectOffset,
    skullFrameSize.X - (skullCollisionRectOffset * 2),
    skullFrameSize.Y - (skullCollisionRectOffset * 2));

    return ringsRect.Intersects(skullRect);

    }

      Current date/time is Thu May 09, 2024 3:55 pm