Re: Graphics2D rotation
- From: Simon <count.numbers@xxxxxx>
- Date: Thu, 04 May 2006 09:38:07 +0200
James McGill wrote:
I make a buffered image for the base layer, which is a circle.
Then I make another buffered image for the top layer, which is also a
circle, the same size.
I want to animate the second image on top of the first, I guess I'd call
it a "pinwheel" effect. So each timer tick, the top layer should be
redrawn in its next step of rotation.
This worked for my purpose:
...
// first translate
g2.translate(radius, radius);
// then rotate
g2.rotate(stepRadians);
// then translate back
g2.translate(-radius, -radius);
g2.drawImage(topLayerImage, 0, 0, this);
...
So I think I have to translate the origin back after rotating becuase
the image itself is oriented to that space, correct?
Ok, now I see the problem. You are drawing an image and that does not have the
center at the "origin" but at the upper left corner. I thought you were drawing
a Shape which typically has the center at the origin. Therefore, you need the
second translation. I would assume that your code should actually solve the
problem, doesn't it?
One suggestion: Once you are sure about which transformations you need,
aggregate all of them into a single AffineTransform and apply it once when
rendering the image. There are also variants of the drawImage methods that
accept an AffineTransform. Depending on how quickly your wheel rotates and how
much memory you can affort, it might be even better to generate rotated copies
of the image in a preprocessing phase so you don't have to perform the time
consuming rotation for each frame.
Cheers,
Simon
.
- References:
- how to use recursive algorithm to determine all of the arrangements?
- From: index
- Re: how to use recursive algorithm to determine all of the arrangements?
- From: index
- Graphics2D rotation
- From: James McGill
- Re: Graphics2D rotation
- From: Simon
- Re: Graphics2D rotation
- From: James McGill
- how to use recursive algorithm to determine all of the arrangements?
- Prev by Date: Re: Travelling Salesman with Spherical Coordinates.
- Next by Date: Re: JDBC Driver - DataSource
- Previous by thread: Re: Graphics2D rotation
- Next by thread: Re: Graphics2D rotation
- Index(es):
Relevant Pages
|
Loading