PDA

View Full Version : Wierd question about Collision Detection...



10-23-2000, 06:17 AM
Im doing a little demo featuring a ball bouncing against the faces of a cube...
I wanted to know a Good way of knowing which face the ball is colliding with. Im actually making the collision test using a bouncing sphere for the ball...

Dodger
10-23-2000, 08:28 AM
If the local axes of the ball and the cube are pointing in the same directions (not independently rotated), something like this should work:

...
if(ball.x+ball.xm-ball.xr < cube.left &#0124; &#0124;
ball.x+ball.xm+ball.xr > cube.right)
ball.xm = -ball.xm;

if(ball.y+ball.ym-ball.yr<cube.bottom &#0124; &#0124;
ball.y+ball.ym+ball.yr > cube.top)
ball.ym = -ball.ym;

if(ball.z+ball.zm-ball.zr < cube.far &#0124; &#0124;
ball.z+ball.zm+ball.zr > cube.near)
ball.zm = -ball.zm;

ball.x += ball.xm;
ball.y += ball.ym;
ball.z += ball.zm;

drawScene();
...

ball.x/y/z being the ball's position, ball.xm/ym/zm the vector of movement of the ball and ball.xr/yr/zr the 3 radii of the ball http://www.opengl.org/discussion_boards/ubb/smile.gif

Space Dog
10-23-2000, 02:23 PM
If I'm not mistaken, the above code assumes a completely elastic and instantaneous collision. The ball does not compress, slow down, or have any of its energy absorbed by the cube or converted into heat or some other form of energy. This form of collision detection is akin to ideal photons hitting an ideal mirror.

Still, if that's all Devon needs, this may work fine for him. All depends on how realistic he needs the physics to be.

10-24-2000, 02:10 AM
Thx for your replies. I dont need cutting edge physics my problem is that im doing collision detection like: Take a vertex of Obj1 and test it against all the faces of Obj2. This works fine, the problem is that I need to know if Obj1 is hitting one of the top faces or one of the sides faces to do correct (not realistic) physics...