In Android, there's a Java class called "Matrix" which I can use to do scaling, rotation and translation on 2D bitmaps.
But there's something about it that I'm beginning to ponder. Is it possible that you can do matrix manipulation (scaling, rotation, translation) on an already manipulated matrix?
For instance, pretend we have something that needs to be optimized, something in our code like below that really needs a performance boost:
[source lang="java"]Matrix matrix = new Matrix();
while (game.isRunning()){
matrix.reset();
matrix.setScale(-1, 1);
matrix.postRotate(0);
matrix.postTranslate(bitmap.getWidth(), 0);
canvas.drawBitmap(bitmap, matrix, null);
matrix.reset();
matrix.setScale(1, 1);
matrix.postRotate(45);
matrix.postTranslate(bitmap.getWidth(), 0);
canvas.drawBitmap(bitmap, matrix, null);
}
[/source]
Maybe it could be faster if we don't have to call on reset() and reset the matrix properties so many times.
Of course the code is a bit useless, because I made the code as a mock-up. It doesn't have anything useful. I'm using it only to ask if matrix manipulation on an already manipulated matrix is possible in code programming. That's all.
Thanks in advance.
Do matrix manipulation on already manipulated matrix: Any way to do this?
There are set,post and pre methods,the set methods actually overwrites the matrix. Therefore you just need to use the 'set' method for your first transformation, in your case it would look like:
Matrix matrix = new Matrix();
while (game.isRunning()){
matrix.setScale(-1, 1);
matrix.postRotate(0);
matrix.postTranslate(bitmap.getWidth(), 0);
canvas.drawBitmap(bitmap, matrix, null);
matrix.setScale(1, 1);
matrix.postRotate(45);
matrix.postTranslate(bitmap.getWidth(), 0);
canvas.drawBitmap(bitmap, matrix, null);
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement