2012-10-16 55 views
0

我在這裏有在C#中的一些代碼C#矩陣到Android矩陣?

//take a world Vector2D and make it a relative Vector2D 
    public Vector2D WorldToRelative(Vector2D world) 
    { 
     Matrix mat = new Matrix(); 
     PointF[] Vectors = new PointF[1]; 

     Vectors[0].X = world.X; 
     Vectors[0].Y = world.Y; 

     mat.Rotate(-m_angle/(float)Math.PI * 180.0f); 
     mat.TransformVectors(Vector2Ds); 

     return new Vector2D(Vectors[0].X, Vectors[0].Y); 
    } 

問題是Android的矩陣似乎並不具備旋轉和變換向量。

它有前後旋轉和映射向量。

我能做些什麼才能正確地將此代碼移植到android?

感謝

回答

0

Android有很棒的Matrix class;只需使用mMatrix.setRotate()mMatrix.setTranslate()即可進行輪換和翻譯。如果您需要縮放,請使用mMatrix.setScale()

很多Android功能都以'set'爲前綴,所以.rotate()變成.setRotate()。它只是需要一點習慣!