views:

51

answers:

1

Given 2 java AffineTransform items, how can I interpolate between them. I need the image on screen to slowly move from the position/rotation/scale with one matrix applied, to the other.

Preferably this should be reasonably efficient since it's running every time a game draws.

My current (really hacky) solution is to getTranslate() from both matrices, lerp between them, and then create a new matrix (This doesn't work fully, since there is no equivalent for rotation)

+1  A: 

Get the affine matrixes of each transform via getMatrix(). Step through the interpolation of one matrix to the other, creating a new transform via AffineTransform(float[] matrix) at each step.

Steve Emmerson
Hey, I accepted this but after implemented it noticed something odd. When the camera is lerping from one matrix to the other, it scales everything to be smaller. This actually looks cool so it's not a problem, but any ideas why it does that?
Martin
Are you getting 4 or 6 values in the getMatrix() method? If 6, are the last 3 elements of both matricies {0, 0, 1}? How many values are you giving to the AffineTransform constructor?
Steve Emmerson
You could also decompose the two transformations into the same translate/rotate/scale/shear sequence and morph each subtransformation separately. The subtransformations would be combined in each step to form the current AffineTransformation -- resulting in a less puzzling visual transformation.
Steve Emmerson