aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes AffineTransform - please help me out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "AffineTransform - please help me out" Watch "AffineTransform - please help me out" New topic
Author

AffineTransform - please help me out

Sunit Naik
Greenhorn

Joined: Mar 18, 2007
Posts: 7
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39826
    
  28
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
    Craig Wood
    Ranch Hand

    Joined: Jan 14, 2004
    Posts: 1535
    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

    Joined: Mar 18, 2007
    Posts: 7
    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 !
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: AffineTransform - please help me out