I am playing some animation where all frames are same height, but different width. All well, but I would like to apply some transformations using matrix for better performance.
On first frame:
Below is code that almost works. Somehow it is not consistent and frames are sometimes centered and sometimes offset. I don't have experience with matrixes so I would appreciate if someone with more knowledge can confirm/fix/improve transformation procedure. This matrix is supplied to canvas drawing method.
Additionally I would like to control:
edit: I guess I can control exact scale down size and bottom center position with screenRect (destination rect)?
Basic stripped down code:
RectF screenRect = new RectF(0, 0, ((float) displayWith), ((float) displayHeight));
Matrix mirror = null;
if (isMirror) {
mirror = new Matrix();
mirror.setScale(-1, 1);
mirror.postTranslate(p.x, 0); // position X back to original point
}
Matrix scale = null;
if (isScaleDown) { // down-scale
scale = new Matrix();
scale.setRectToRect(imageRect, screenRect, Matrix.ScaleToFit.CENTER);
}
// COMBINED TRANSFORMATION MATRIX
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Matrix trans = null;
if (scale != null) trans = scale;
if (mirror != null && trans == null) trans = mirror;
if (mirror != null && trans != null) trans.setConcat(trans, mirror);
return trans;
For those interested, I ended up setting "scale" and "mirror" matrix this way: