• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collision detection with rotating shapes

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic