Collision Detection for a 3D Beer Pong Game

Started by
3 comments, last by Forerunner 16 years, 11 months ago
Hello! I'm trying to write the collision detection code for a 3D rendition of Beer Pong in C++/OpenGL. I am a bit stuck on how exactly to do the collisions between the rim of the cup (a thin "ring" or "doughnut" shape) and the ball. Give that I have the radius of the ring, the 3D coordinate of the center of the ring, the radius of the ball, and the 3D coordinate of the center of the ball, what is the best way to tell if a collision occurs, how do I find the point of collision, and finally how do I find the normal to the surface at that point? Once I have the normal vector, I know how to find the velocity vector after the collision. Thanks in advance!
Advertisement
You need to use the equation of the Torus here:
http://mathworld.wolfram.com/Torus.html

You also need the equation of a point in space wrt time

s(t) = s0 + v*t + .5*a*t^2

Set the torus thickness equal to 1/2 the rim thickness + the ball radius. Then sub in the x,y,z components of s(t) into the torus equation and solve for time to find when the ball and rim intersect. To find the normal at that point, find the position at that point by solving for s(t) using the t value that you found. Then take the gradient of the torus equation at that point.

And isn't beer pong a little less fun with no beer?
Thanks a lot! So in order to use this method, do I need to keep track of units of time where t0 is the instant the ball starts its motion? Or is there a way to just test whether or not the xyz-coordinate of the ball falls somewhere inside the volume of the torus-of-collision when I do the check? The velocities I have to deal with are never so high that the ball is going to pass all the way through that collision zone without being picked up.

And yes, beer pong is a bit less fun without beer, but it fit our goal of making a PC game using Wiimote input too well to pass up =)
Also, if it's not too much trouble, how would I apply the same procedure to detection the collision and point of collision with the conical frustum of the cup? Right now I use a pretty rough detection check that does work fairly well, but improving accuracy is never a bad idea.
Still looking for some help on this.

This topic is closed to new replies.

Advertisement