Я тоже боролся с этим в течение некоторого времени. Было бы легко определить матрицу преобразования 4x4 и вычислить ее для каждого кадра, но, к сожалению, в Android есть только матричный объект 3x3, который не поддерживает 3D-поворот и перевод. Мое решение для опрокидывания обеих диагоналей:
public class RightDiagonalFlipAnimation extends Animation {
private float fromDegree;
private float toDegree;
private float densityDpi;
private float width;
private Camera camera;
public RightDiagonalFlipAnimation(float fromDegree, float toDegree, float densityDpi) {
this.fromDegree = fromDegree;
this.toDegree = toDegree;
this.densityDpi = densityDpi;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
this.width = width;
camera = new Camera();
float cameraDistance = width * 25;
camera.setLocation(0, 0, -cameraDistance/densityDpi);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float xDegrees = fromDegree + ((toDegree - fromDegree) * interpolatedTime);
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateX(-xDegrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-this.width/(float) Math.sqrt(2), -this.width/(float) Math.sqrt(2));
matrix.postTranslate(this.width/(float)Math.sqrt(2), this.width/(float)Math.sqrt(2));
matrix.postRotate(-45);
matrix.preRotate(45);
}
}
public class LeftDiagonalFlipAnimation extends Animation {
private float fromDegree;
private float toDegree;
private float densityDpi;
private float width;
private Camera camera;
public LeftDiagonalFlipAnimation(float fromDegree, float toDegree, float densityDpi) {
this.fromDegree = fromDegree;
this.toDegree = toDegree;
this.densityDpi = densityDpi;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
this.width = width;
camera = new Camera();
float cameraDistance = width * 25;
camera.setLocation(0, 0, -cameraDistance/densityDpi);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float xDegrees = fromDegree + ((toDegree - fromDegree) * interpolatedTime);
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateX(xDegrees);
camera.getMatrix(matrix);
camera.restore();
matrix.postRotate(45);
matrix.preRotate(-45);
}
}
что-то не так? Я пробовал ваш код, и он работает – Raghunandan
Его простой флип, но мне нужен диагональный флип ... –