| 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: 32714
|
|
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. TryUsing the matrix given in the Graphics2D method to work out the 4 corners of the new image areaWork out a Rectangle (or Rectangle2D) of the same size and rotationTry 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 !
|
 |
 |
|
|
subject: AffineTransform - please help me out
|
|
|