| | |
AffinedTransform strange behaviour
![]() |
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
I'm trying to rotate a shape around a point, but I'm having a problem. To give this some context - it's for a game. The transform is applied and the image is drawn, then green rectangle is drawn, then the transform is reset. When I try to use newTrans.createTransformedShape() to transform the red rectangle, I get the blue rectangle (which should actually overlap the green one).
Here's the picture to explain the problem
Shouldn't applying a transform, drawing a shape and resetting the transform have the same effect as using createTransformedShape() with the original transform?
The small blue dot in the upper left shows the location of the "location" variable. Any idea why the two rectangles are different?
Here's the picture to explain the problem
Shouldn't applying a transform, drawing a shape and resetting the transform have the same effect as using createTransformedShape() with the original transform?
Java Syntax (Toggle Plain Text)
AffineTransform origTrans = g.getTransform(), newTrans = (AffineTransform)origTrans.clone(); newTrans.rotate(rotationAngle, location.x+(image.getWidth()/2), location.y+(image.getHeight()/2)); g.setTransform(newTrans); g.drawImage(image, (int)location.x, (int)location.y, null); g.setColor(Color.green); g.draw(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight())); g.setTransform(origTrans); Shape bounds = newTrans.createTransformedShape(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight())); g.setColor(Color.blue); g.draw(bounds); g.setColor(Color.red); g.draw(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight()));
![]() |
Other Threads in the Java Forum
- Previous Thread: java error printing to a text document
- Next Thread: ATM program
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows





