views:

1041

answers:

1

I have a ball moving inside a cube, and I detect when it goes outside of the cube (with a bounding sphere and a bounding box). Now I would like to detect from which side the ball goes out. Then I could redirect the ball in the correct direction. How can I do this with the ball's “world” matrix?

Should I keep track of the ball's coordinates myself, or should I deduce them from the world matrix?

+1  A: 

I'd start over with the collisions. You have six planes (each a [point,normal unit vector] pair) and a sphere (a [point,radius] pair).

Check the point against each plane. To do this, subtract the unit vector, scaled up by the radius of the sphere, of the plane from the point. (Point -= PlaneUnitVector * radius)

Now, with some vector math, you can see which side of the plane it's on.

You'll then use the unit vector of the plane for the bounce calculation.

The next problem you'll run into is the case where you cross through more than one plane at a time.

Nosredna