Reputation: 1934
I am trying to rotate regular bitmap around X, Y and Z axis using canvas and matrix. I could use OpenGL but I think it would be overkill to achieve such a simple effect as I am pretty sure this is possible using just canvas, bitmap and matrix.
I tried using camera and its rotateX, rotateY and rotateZ method and then applying that matrix to canvas but for some reason I can get it to rotate the bitmap around it center!
I can't find method to change the rotate origin so I decided to translate the camera so its at center of bitmap and afterwards translate it back, but whatever I try the bitmap doesn't get translated by its center...
camera.save();
camera.translate(-(team.getWidth() / 2), (team.getHeight() / 2), 0f);
rotateY += 1f;
camera.rotateY(rotateY);
camera.translate((team.getWidth() / 2), -(team.getHeight() / 2), 0f);
camera.applyToCanvas(canvas);
camera.restore();
/* code that has nothing to do with this..(fading) */
canvas.drawBitmap(team, null, rect, paint);
Upvotes: 3
Views: 2132
Reputation: 1504
Rotate3DAnimation is the answer for you. Here is the class
And here is the tutorial too: Tutorial of 3D flip
Upvotes: 2