AffinedTransform strange behaviour

Reply

Join Date: Jul 2008
Posts: 4
Reputation: echilon is an unknown quantity at this point 
Solved Threads: 0
echilon echilon is offline Offline
Newbie Poster

AffinedTransform strange behaviour

 
0
  #1
Dec 10th, 2008
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?
  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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: AffinedTransform strange behaviour

 
0
  #2
Dec 15th, 2008
Can you set a breaking point on "Shape bounds= " to find location.x & location.y between "green" ?


Albert
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC