Breakout collision questions :)

Started by
2 comments, last by Ritual Magic 21 years, 6 months ago
Hiyas! Well, I''m writing breakout in OpenGL, and I have a probably dumb question on collision detection. Hokay - the way it''s written so far is that a level (i.e. an array of bricks, 2 types) are loaded from a file. The bricks themselves are just primitives with some color shading to make em look nice. The ball is also just a circle. I''ve got the movement going well, as in the bounces work properly, but I can''t really see how to manage the collision with the bricks. I downloaded some code on polygon collision, but it was (a) WAY too complex, and (b) pertaining to 3D (i.e. working off about 8 million dimensions hehe). Anyone got an idea? And sorry if it''s a daft question Thanks, RM. ------------------------------------------------------------ Yes. it''''s true, I DO wield the ugly stick. And I see I have beaten you with it before!
------------------------------------------------------------Yes. it''s true, I DO wield the ugly stick. And I see I have beaten you with it before!
Advertisement
Either pretend that the circle is infact a square, then you can make collision detection alot easier, otherwise if you want you can keep the position of the ball by using the centeral point, and then check if the block is within or equal to the radius of the circle.
Whoops forgot to log in.

Ballistic Programs
Probably the fastest way, assuming your blocks are uniform, would be to first check the ball''s center.y+radius (or whatever your variable names are) against the bottoms of the bricks. For each row, you check to see if the ball''s top ''edge'' is higher the bottoms of bricks. Then for each of those rows, check to see if the ball''s bottom ''edge'' crosses the top plane of that row. (Basically using the ball as a square for primary collision detection) Here''s where it can get a little tricky, first, check if the ball is contained entirely horizontally within each piece. If the ball''s left and right edges are contained within the piece, you have a collision. If not, probably the best way would be to check to see if the corner points of the two potential colliding bricks are contained in the circle.
(If distance(circle.center, brick.cornerpoint) <= radius)

it''s early, and this may be way off, but just a thought.

This topic is closed to new replies.

Advertisement