Results 1 to 4 of 4
  1. #1
    Echilon Guest

    Question AffinedTransform strange behaviour

    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).

    A picture speaks a thousand words, but if this contradicts forum rules please remove the link - hxxp://mi6.nu/transform.png

    Shouldn't applying a transform, drawing a shape and resetting the transform have the same effect as using createTransformedShape() with the original transform?
    Java Code:
    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()));
    The small blue dot in the upper left shows the location of the "location" variable. Any idea why the two rectangles are different?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    Just another cross poster.
    Abstract Window Toolkit (AWT) - Rotating a shape

    db

  3. #3
    Echilon Guest

    Default

    Thanks for pointing that out, but I have a problem and I'm trying to find a solution. Do you have any idea why it's behaving like this?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    Maybe, maybe not, but I don't exert myself trying to help a cross poster.

    db

Similar Threads

  1. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM
  2. Strange problem
    By Tamir in forum Eclipse
    Replies: 1
    Last Post: 08-18-2008, 10:44 PM
  3. What is the answer to this strange problem:
    By willemjav in forum New To Java
    Replies: 5
    Last Post: 08-11-2008, 10:31 PM
  4. Strange behaviour in swing
    By cbalu in forum AWT / Swing
    Replies: 1
    Last Post: 05-23-2008, 10:23 PM
  5. Un expected behaviour when reading from inputstream
    By adoorsarath in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2007, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •