Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

hthb

A little help with collision detection

This topic is 5373 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

Hi. I''m trying to make a simple pinball game. I already have a simple platform consisting of 6 planes (in which the ball bounces around) and one cube which the ball can collide with and bounce off of. The problem is getting the dynamic coordinates of the cube. By "dynamic" I mean the coordinates (vertices) of the cube after arbitrary transformations. I''ve constructed it using GL_QUADs and use glGetDoublev(GL_MODELVIEW_MATRIX,m) to return the newest transform matrix to the ball class. The ball class then multiplies the original coordinates of the cube with that matrix to get the newest position of the vertices. After this I can get a useful bounding box after any type of TRANSLATIONS, but after rotation, I find that the typical bounding box algorithm ( pos.x < boxArray[1].max.x pos.x > boxArray[1].min.x pos.y < boxArray[1].max.y pos.x > boxArray[1].min.y pos.z < boxArray[1].max.z pos.z > boxArray[1].min.z ) doesn''t work cause the coordinate systems for the ball and the cube are not "aligned". I hope you know what I mean. So how can I accomplish this? I''ve read NeHe''s tutorial, about ball to plane collision detection, but that would only work with the walls, cause the planes are infinite. Or am I misunderstanding? Look, I''m sorry if this isn''t understandable. I''ll clarify anything if you ask for it.

Share this post


Link to post
Share on other sites
Advertisement
As you noticed, the bounding box is only valid in the cube''s coordinate space, so you have 2 choices: You can transform the ball into the cube''s coordinate space and use the bounding box formula, or you can use the plane equations for the 6 sides of the cube.

To put the ball into the cube''s coordinate system, you''d multiply the ball''s position vector by the inverse of the cube''s transformation matrix.

And BTW, this is a math and physics question, so I''m moving it there.

Share this post


Link to post
Share on other sites
Is it wrong of me to think that a plane is infinite (half-space, i.e. cuts the space in half)? How could I then use plane equations for this?

Visit www.doc2pdf.net, for a free, no-need-to-register, .doc (MSWord) to .pdf (Acrobat) file conversion.

Share this post


Link to post
Share on other sites
Planes are infinite, but you can use them in combination to define a convex shape, in your case a cube. If the ball is at least partially behind all planes then it''s inside the cube (assuming your planes face outwards).

Share this post


Link to post
Share on other sites
hmmm, actually, in the case of a ball, neither solution is going to be very accurate, because the ball isn''t a point. Imagine the case where the ball is at the corner of the cube. Here, a point on the ball is behind every plane.


---
| |
--- | |
\ ---
\
|


I''m not sure of the best solution to this. You could bevel the edges of the cube I guess, or you could just make the ball very small and call it a point .

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!