hypernewbie

Members
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

123 Neutral

About hypernewbie

  • Rank
    Newbie

Personal Information

  • Location
    Sydney, Australia
  1. Thanks heaps for the tutorial. Unfortunately the given swept AABB code is buggy. Sorry my following code has a slightly different naming scheme from the above (and is also in Java). Firstly, the code is missing these two lines before finding earliest / latest exit/entry points. This corrects the bug in the tutorial code where an axis non-entry due to overshooting can cover an entry on the other axis. if (entryY > 1.0f) entryY = -Float.MAX_VALUE; if (entryX > 1.0f) entryX = -Float.MAX_VALUE; // Find the earliest/latest times of collision. float entryTime = Math.max(entryX, entryY); float exitTime = Math.min(exitX, exitY); The no-collision check is also incorrect. The check given was: if (entryTime > exitTime) return 1.0f; if (entryX < 0.0f && entryY < 0.0f) return 1.0f; if (entryX > 1.0f || entryY > 1.0f) return 1.0f; First problem with this check is that it fails to catch the case where one axis overshoots, but the other axis undershoots eg. entryX < 0.0f but entryY > 1.0f. This should be a non-collision, but this code will register that as a collision.   Second problem with this check is that it does not correctly handle single-entry collisions at all. Undershooting single-entries collisions are incorrectly ignored, while overshooting single-entries non-collisions are incorrectly collided. The following image demonstrates a counter-example of two cases which should result in different collision results but are incorrectly treated the same in the tutorial code: The correct set of checks should instead be: //if (entryY > 1.0f) entryY = -Float.MAX_VALUE; // From previous bug above. //if (entryX > 1.0f) entryX = -Float.MAX_VALUE; // From previous bug above. if (entryTime > exitTime) return 1.0f; // This check was correct. if (entryX < 0.0f && entryY < 0.0f) return 1.0f; if (entryX < 0.0f) { // Check that the bounding box started overlapped or not.     if (s.max.x < t.min.x || s.min.x > t.max.x) return 1.0f; } if (entryY < 0.0f) { // Check that the bounding box started overlapped or not.     if (s.max.y < t.min.y || s.min.y > t.max.y) return 1.0f; } After these bugs are corrected, the sweptAABB collision works fine. Hope this saves someone hours and hours of debugging