Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 285

Like
0Likes
Like

Posted 27 September 2012 - 02:12 AM

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.

Sponsor:

#2 Ashaman73   Members   -  Reputation: 4605

Like
0Likes
Like

Posted 27 September 2012 - 02:36 AM

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);
}


#3 tom_mai78101   Members   -  Reputation: 285

Like
0Likes
Like

Posted 27 September 2012 - 07:50 AM

Oh ok. Thanks!

So, there's no way we can manipulate a manipulated matrix?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS