通过旧矩阵值转换和旋转矩阵

时间:2014-07-03 12:24:28

标签: java android matrix rotation translate-animation

我正在尝试使用矩阵旋转和翻译我的位图,我使用下面的代码(我试着用简单的英语):

playerX = playerValues[Matrix.MTRANS_X];
playerY = playerValues[Matrix.MTRANS_Y];

if (fingerx1 > playerX) {
    xspeed = 1;

}
if (fingerx1 < playerX) {
    xspeed = -1;
}
if (fingery1 < playerY) {
    yspeed = -1;
}
if (fingery1 > playerY) {
    yspeed = 1;
}

//playerX and playerY are checked in Log.d, returns correct values

playerMatrix.setRotate(rotation, bitmap.getWidth()/2, bitmap.getHeight()/2);
playerX += xspeed;
playerY += yspeed;
playerValues[Matrix.MTRANS_X] = playerX;
playerValues[Matrix.MTRANS_Y] = playerY;
playerMatrix.setValues(playerValues);

这不起作用:P它在开始和当前x和y值之间来回闪烁。谁能告诉我这种翻译的正确方法是什么?

(旋转工作正常)

1 个答案:

答案 0 :(得分:0)

使用Matrix.setXXX()将替换先前的矩阵变换。您可以使用:

代替setValues
playerMatrix.postRotate(rotation, bitmap.getWidth()/2, bitmap.getHeight()/2);
playerX += xspeed;
playerY += yspeed;
playerValues[Matrix.MTRANS_X] = playerX;
playerValues[Matrix.MTRANS_Y] = playerY;
playerMatrix.postTranslate(playerX, playerY);