• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

AffineTransform - please help me out

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

I am using AffineTransform class to rotate an image. I need to get hold of the image coordinates at each instant, so that I can determine when the image is hitting another object. Is there any way I can get - say something like the rectangular coordinates i.e. the 4 coordinates of the image ?

I am using g2d.drawImage(image, X, Y, this) to draw the image, but X,Y are always pointing to the top left coordinate of the image.

Please help me out
Thanks
 
Marshal
Posts: 71740
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Difficult. I would suggest you don't rotate the Graphics2D object, but take a clone of it, and rotate that.
That way you will have an un-rotated object to draw your next shape.
You can certainly get the size of an Image in terms of a rectangle, and work out its bounds.

Try
  • Using the matrix given in the Graphics2D method to work out the 4 corners of the new image area
  • Work out a Rectangle (or Rectangle2D) of the same size and rotation
  • Try their intersects method with all the other shapes around.

  • There is bound to be a better way of doing it, which I don't know.

    Anybody else got a better idea??

    CR
     
    Ranch Hand
    Posts: 1535
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There are many ways to approach this. You can construct transforms to both locate the
    rotated image and to create a transformedShape for hit–testing.
    Here's an illustration of the concept. Use/move the mouse to hit–test the rotated image.
    If testing for collisions with other shapes you could use something like this

    in the mouseDragged method or in (a method called from) your animation event code.
     
    Sunit Naik
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    rotate.createTransformedShape(rect) did the trick for me, I was looking for something exactly like this

    Thanks a lot . . both Campbell Ritchie and Craig Wood

    Javaranch rocks !
     
    We can walk to school together. And we can both read this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic