Sign in to follow this  

Collision Detection for a 3D Beer Pong Game

This topic is 3854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 =)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this