IntelliJ Java IDE
The moose likes Game Development and the fly likes trying to understand this collision algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Game Development
Reply Bookmark "trying to understand this collision algorithm" Watch "trying to understand this collision algorithm" New topic
Author

trying to understand this collision algorithm

Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
I almost understand this algorithm for axis-aligned bounding box sweep tests:


However I have a few problems:

1) VECTOR u_0(0,0,0);
//first times of overlap along each axis

VECTOR u_1(1,1,1);
//last times of overlap along each axis

These seem to me like they should be reversed. If one imagines box B moving away from box A, all of the tests in the main for loop will fail. Thus, we will get to the return statement, and the max of u_0 will be less than the min of u_1.

2) I'm using the current position rather than the previous position as A and B, because that's what my program is set up to have. I justify this in my mind by saying this just tests if they will collide in the next frame, rather that if they did collide in the previous frame. If frames are 16 millis, it doesn't feel like it'd make much of a difference.

3) This will tell me when the next collision will occur. Is it then my responsibility to say if that will occur in the next frame?


Thanks,
Nick


I've heard it takes forever to grow a woman from the ground
Jeremy Tartaglia
Ranch Hand

Joined: Mar 11, 2004
Posts: 62
I'll take a closer look at this tomorrow, but in answer to your first question, that would make sense to me. If B is moving away from A, from A's perspective, all the tests should fail. B and A will never collide. B has to be moving toward A in some aspect (x, y, or z) in order for any collision to possibly occur.

But I might've misunderstood the algorithm.
 
IntelliJ Java IDE
 
subject: trying to understand this collision algorithm
 
Threads others viewed
Rotating a JWindow with multiple JPanels
Cannon fire
Please Help: Putting Vector objects into HashMap
AffineTransform Rectangle2D
Balls are not moving
developer file tools