Ball to Ball Collision - Detection and Handling

前端 未结 14 1596
逝去的感伤
逝去的感伤 2020-11-22 05:29

With the help of the Stack Overflow community I\'ve written a pretty basic-but fun physics simulator.

\"alt

14条回答
  •  没有蜡笔的小新
    2020-11-22 06:02

    As a clarification to the suggestion by Ryan Fox to split the screen into regions, and only checking for collisions within regions...

    e.g. split the play area up into a grid of squares (which will will arbitrarily say are of 1 unit length per side), and check for collisions within each grid square.

    That's absolutely the correct solution. The only problem with it (as another poster pointed out) is that collisions across boundaries are a problem.

    The solution to this is to overlay a second grid at a 0.5 unit vertical and horizontal offset to the first one.

    Then, any collisions that would be across boundaries in the first grid (and hence not detected) will be within grid squares in the second grid. As long as you keep track of the collisions you've already handled (as there is likely to be some overlap) you don't have to worry about handling edge cases. All collisions will be within a grid square on one of the grids.

提交回复
热议问题