943,709 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 459
  • Java RSS
Dec 10th, 2008
0

AffinedTransform strange behaviour

Expand Post »
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?
Java Syntax (Toggle Plain Text)
  1. AffineTransform origTrans = g.getTransform(),
  2. newTrans = (AffineTransform)origTrans.clone();
  3. newTrans.rotate(rotationAngle, location.x+(image.getWidth()/2), location.y+(image.getHeight()/2));
  4. g.setTransform(newTrans);
  5.  
  6. g.drawImage(image, (int)location.x, (int)location.y, null);
  7. g.setColor(Color.green);
  8. g.draw(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight()));
  9. g.setTransform(origTrans);
  10.  
  11. Shape bounds = newTrans.createTransformedShape(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight()));
  12. g.setColor(Color.blue);
  13. g.draw(bounds);
  14.  
  15. g.setColor(Color.red);
  16. g.draw(new Rectangle2D.Double(location.x, location.y, image.getWidth(), image.getHeight()));
The small blue dot in the upper left shows the location of the "location" variable. Any idea why the two rectangles are different?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
echilon is offline Offline
4 posts
since Jul 2008
Dec 15th, 2008
0

Re: AffinedTransform strange behaviour

Can you set a breaking point on "Shape bounds= " to find location.x & location.y between "green" ?


Albert
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: java error printing to a text document
Next Thread in Java Forum Timeline: Simple Java timer lag issue (caused by quad core?)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC