AffineTransform.rotate() - how do I xlate, rotate, and scale at the same time?

后端 未结 2 1049
闹比i
闹比i 2020-11-30 15:41

I have the following code which does (the first part of) what I want drawing a chessboard with some pieces on it.

              Image pieceImage = getImage(c         


        
2条回答
  •  一整个雨季
    2020-11-30 16:21

    Try performing the rotation before translating it into the correct position. Simply reorder the transformations so that first you scale, then you rotate (around the center point of the image), and then you translate:

    transform.scale(scale, scale);
    transform.rotate(Math.PI, pieceWidth / 2, pieceHeight /2);
    transform.translation(xPos, yPos);
    

    By the way, the black pieces on a chess board usually aren't rotated. :)

    Update

    In what way does it not work? The solution I provided also also differs from your code in that scaling is performed before translating. You can try the rotating, translating, and then scaling.

    I strongly suggest that you modify your code so that you can perform the translation last. If you do this, everything will become a lot less complicated. Once you have done so, you only have to scale once to automatically take care of the rotation.

    transform.scale(scale, scale); // or transform.scale(scale, -scale); to rotate
    transform.translate(xPos, yPos);
    

提交回复
热议问题