Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collision detection with rotating shapes

 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm trying to perform collision detection with shapes that rotates on the screen using the Graphics2D rotation. The problem is that I need to rotate the sprite.getBounds() Rectangle in some way after the graphics rotation so it fits well so I later on can use the intersect method with decent accuracy. As the above code is now, the sprite.getBounds() Rectangle follows the sprite in x and y, but doesn't rotate with it as can be seen in the images below. Is there some method to rotate the actual sprite.getBounds() Rectangle's coordinates, or how can this problem be approached in best way?



//Kalle
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could pair the sprite with a java.awt.geom.Area, rotate the sprite using an AffineTransform and pass that AffineTransform instance to the Area.transform() method. You can then use Area.getBounds() / getBounds2D() to obtain the post-rotation coördinates for your sprite.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use AffineTransforms, apply them to a cloned copy of the Graphics object, obtained with a method of the Graphics class, I think called create().
 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:You could pair the sprite with a java.awt.geom.Area, rotate the sprite using an AffineTransform and pass that AffineTransform instance to the Area.transform() method. You can then use Area.getBounds() / getBounds2D() to obtain the post-rotation coördinates for your sprite.


If this was what you meant, it worked fine! Thank you.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic