PONG that s HARD (hard to believe eh?)
WOW.
Well, its not REALLY pong thus it is hard... So, take the classic pong game but change the shape of the paddle to lets say any polygon... When a ball hits any side of this polygon it should bounce off with the same angle as the incident angle but in the opposite dierection... Ok... So, how can I find out which side of the polygon is involved in the collision? I need to know which side so I can extract the two nodes and treat that portion as a "wall". Im not using Polygon because Polygon class does not have this and it will make my life harder (i think). So instead I made an array of points containing the shape of the polygon. Any advise or ideas on how to find out which side of a polygon the ball has passed/hit?
# 1
Use a Polygon.
The polygon has methods to determine if the ball is inside the shape (contains or intersects methods, depending on how you want your ball to be represented (i.e. as a point or a shape)). If it is then get one of the pathIterators (use the . Iterate over this grabbing pairs of nodes. Compute the distance between your ball and the edge pair. Store the closest distance and use that edge as the rebound surface.
You can also use the getBounds() method to return a bounding box for fast checks so you don't need to perform the entire test for each iteration of your game.
Once you have it working using a Polygon you can determine if it is fast enough for your purpose. If not then you can write an optimized version of Polygon yourself :)
matfud
# 2
Yea, thats what i ended up doing anyway... it works...There is only one bug as a circumstance... Since the shape of the paddle may have uneven length sides, the "distance check" wont always work =(BUT, It works OK-ish...THANKS