Advertisement

A classic problem, I'm sure

Started by September 21, 2002 09:47 PM
1 comment, last by dhscompguy 22 years, 4 months ago
Hello everyone, I'm absolutely positive this has been asked before so I'm just gonna apologize right off the bat -- SORRY! I would've done a search but, well, you know the deal. The problem -- I have a spinning 2D polygon. A ball is bouncing around inside of it. Sometimes the ball goes too far during a frame update and my line intersection test fails (because the test segment has made its way outside of the polygon, of course). Here's my pseudocode: Save ball position Set ball position to position + velocity Create line segment between the new position and the old For each side of polygon: Rotate side by 5 degrees Draw side Test side against ball's line segment If intersection occurs: move ball to that point minus a little bit reflect velocity vector Draw ball Repeat The problem has to do with the rotating polygon, I think. An intersection occurs. The ball is moved a little bit inside of the point of intersection. That position is saved as the old position at the top of the loop. The ball's test segment is created using the velocity vector. A side rotates enough to jump over the ball's new position so the next intersection test/vector reflection will be incorrect. So, back to square one, right? I will gladly kiss your feet if you help me figure this out. Thanks, Denny [edited by - dhscompguy on September 21, 2002 11:57:51 PM] [edited by - dhscompguy on September 21, 2002 11:59:41 PM] [edited by - dhscompguy on September 23, 2002 12:59:49 PM]
test start and endpoint against the line. if the side changed, you hit. else, if the distance of one of the balls is less than the radius of the ball, you hit, else, not..

..thats for a line..

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement
Sorry if I am being dense but you lost me there.

<< test start and endpoint against the line >>

By this do you mean ''draw a line between the ball''s last position and its new position and test it against the line representing a wall''? If so, I am doing that.

<< if the side changed, you hit. >>

The side changed? I don''t understand what you mean.

<< else, if the distance of one of the balls is less than the radius of the ball, you hit, else, not.. >>

Are you talking about ball to ball collisions? I''m not handling that yet. I only have one ball and a ''spinning room'' that the ball is supposed to bounce around in.

In certain cases the ball makes it outside of the room. Does this make sense or should I draw a picture?

Thanks

This topic is closed to new replies.

Advertisement