8

i'm having trouble working out the returned values of the below code pMeasure = PathMeasure, m = Matrix, distCount is the distance along the path

pMeasure.getMatrix(distCount, m, 0x01 | 0x02); 
m.getValues(float[] values)

float[2] & float[5] are position x & y respectively but i can't figure out the rest

any help once again appreciated.

Matt
  • 1,368
  • 4
  • 16
  • 32

2 Answers2

13

Taken from the Matrix class documentation:

public static final int MPERSP_0
Constant Value: 6 (0x00000006)

public static final int MPERSP_1
Constant Value: 7 (0x00000007)

public static final int MPERSP_2
Constant Value: 8 (0x00000008)

public static final int MSCALE_X
Constant Value: 0 (0x00000000)

public static final int MSCALE_Y
Constant Value: 4 (0x00000004)

public static final int MSKEW_X
Constant Value: 1 (0x00000001)

public static final int MSKEW_Y
Constant Value: 3 (0x00000003)

public static final int MTRANS_X
Constant Value: 2 (0x00000002)

public static final int MTRANS_Y
Constant Value: 5 (0x00000005)

Pang
  • 9,564
  • 146
  • 81
  • 122
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
  • Thank you but what does perspective mean in this regard? – Matt Jul 14 '10 at 10:56
  • 4
    Honesly, I don't know.. I bet these values are reserved, and the reason why they are present perhaps is to complete the matrix. Here you will find more info on this topic: http://mobiledevelop.blogspot.com/2009/02/android-canvas-translation-discussion.html – Andrejs Cainikovs Jul 14 '10 at 13:05
  • 3
    Android uses skia and I checked the source code for androids matrix class, in its C++ core, it simply glues Matrix, with SkMatrix. The matrix is 3x3 row major. Because of this MSCALE_X/Y is not actually scale. As long as no rotations are involved it is scale. If matrix encodes a rotation you need to do extra math to calculate the scale. MPERSP is used to calculate the "z" coordinate, by default z=1. If z !=1 then x=x/z; y=y/z; z=z/z=1. In general you don't need to worry about it z. It's just like opengl 4x4 for 3D, except on android its 3x3 for 2D – over_optimistic Mar 22 '13 at 14:49
9

Android Matrix uses skia and its row-major meaning the indices are as follows

0  1  2  
3  4  5
6  7  8

I contrast OpenGL uses indices like so

0  3  6
1  4  7
2  5  8

The "meanings" are identical in regards to matrix position.

a  b  tx
c  d  ty
0  0   1

a,b,c,d encode scale & rotation at the same time. tx/ty encode translation. If you do m.getValues(vals); then vals[2] == tx, vals[5] == ty, and the rest is straight forward. The best way to extract translation is to make a vector

float[] point = {0, 0};

Then map it and see where it ends up and that's your translation (which is exactly (tx, ty). Under rare circumstances its not

to get scale map a second point

float[] point2 = {1, 0};

Now take the difference rel = (point - point2) and get the length of that vector and that's your scale. To extract rotation, normalize rel and it's simple to get it's standard angle.

over_optimistic
  • 1,399
  • 2
  • 18
  • 27