Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are the values of android.graphics.Matrix used?

I am trying to understand how the 9 values in the android.graphics.Matrix class are used to render something (specifically a Bitmap).

I saw the defines for the 9 indices into the value array, however the naming convention did not seem to make much sense to me.

I have my own orientation system that I am using for all my objects in my engine. For me an orientation consists of a position, a forward vector, and a left vector.

I am trying to figure out how to take these 3 pieces of data (which are already mapped to screen space) and create an android.graphics.Matrix that will render my object's bitmap as I would expect.

Any help would be appreciated.

Thanks

like image 644
SnapGames Avatar asked May 01 '11 01:05

SnapGames


People also ask

What is the use of matrix in Android?

The matrix supports a bunch of different transformations like translate , scale , rotate and skew . If those sound familiar it's because they're (mostly) the same as on a view, an animation or the canvas.

What is image matrix in Android?

Matrix is the class that be used to process images in android. This article will show you examples of how to use android. graphics. Matrix to rotate, scale, skew and translate bitmap images in android.


1 Answers

I eventually figured out the documentation. For anyone who was confused about the wording like I was, here is another explanation:

[0,0 0,1 0,2]

[1,0 1,1 1,2]

[2,0 2,1 2,2]

=

[MSCALE_X MSKEW_X MTRANS_X]

[MSKEW_Y MSCALE_Y MTRANS_Y]

[MPERSP_0 MPERSP_1 MPERSP_2]

=

[scale.x diagonal.x pos.x]

[diagonal.y scale.y pos.y]

[0.0f 0.0f 1.0f]

like image 141
SnapGames Avatar answered Oct 23 '22 19:10

SnapGames