Reputation: 1032
I've implemented a kind of Pong where the paddles (Rectangle2D) can rotate. To obtain more accuracy, many things are managed by Graphics2D. The rotation too is managed by the methods rotate(...) of the previous told class.
To reach a realistic bounce, I need to know where the ball hits the paddle (only the side, not the particular point).
I've tried to define (and rotate) two Rectangle2D that represent the back and the front side of the paddle and then recognize the bounce in one of these two by the method hit(Rectangle2D r, Shape s, boolean onStroke), but it doesn't work properly.
Here is the java class Graphics2D:
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
Have you any idea?
Upvotes: 1
Views: 194
Reputation: 26
Assuming you have one rectangle for your paddle and know the center of rectangle and circle and the rotation of your rectangle. Assuming a rotation of zero means, your rectangle is aligned horizontally (width > height).
q = Math.atan2(height of rectangle, width of rectangle)
Upvotes: 1