#### Archived

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

# 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.

## 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 on other sites
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 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 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 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 .

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633421
• Total Posts
3011797
• ### Who's Online (See full list)

There are no registered users currently online

×