I'm trying to transfer my bitmap from using rectF translation to using matrix rotation and translation. I feel like I've tried every combination of pre,set,post for rotate and translate. This is a sample of my code
Matrix m;
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(bitmap, m, null);
}
onTouchEvent(MotionEvent event)
{
m.setRotate(rotation, bitmap.getWidth()/2, bitmap.getHeight()/2); //rotation points to your finger
if (fingerx1 > bitmapX) {
xspeed = xspeed + accel;
}
if (fingerx1 < bitmapX) {
xspeed = xspeed - accel;
}
if (fingery1 < bitmapY) {
yspeed = yspeed - accel;
}
if (fingery1 > bitmapY) {
yspeed = yspeed + accel;
}
}
private Runnable runny = new Runnable() {
public void run() {
m.postTranslate(xspeed, yspeed);
handler.postDelay(this, 50);
}
};
Not the final code since I don't know which pre,set,post to use in these situations. I feel like this would be the solution though (setRotate, postTranslate).
With this combination, the bitmap looks like it tries to but can't translate.
When I've tried setTranslate(bitmapX + xspeed, bitmapY + yspeed) and postRotate it gives me the right translation but crazy rotation. Using both setRotate, setTranslate gives me crazy glitches. Adding pretranslate and prerotate to the mix just gave me a headache.
TL;DR: Ugh.
EDIT:
bitmapX = playerValues[Matrix.MTRANS_X];
bitmapY = playerValues[Matrix.MTRANS_Y];
After trying postRotate and postTranslate together, I see my bitmap rotate around it's center at first and then it moves out of the 0,0 position and continue to rotate around the 0,0 center.x,center.y position.
Basically I need to fix my rotate's center x,y to make them dynamically change with my bitmap's location.
Thanks pskink, I was having a very bad case of matricides.