Sign in to follow this  

Do matrix manipulation on already manipulated matrix: Any way to do this?

This topic is 1903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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:
[CODE]
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);
}
[/CODE]

Share this post


Link to post
Share on other sites

This topic is 1903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this