如何获取CATransform3D矩阵中的每一个Scale, Translation, Rotation, Projection形式?

问题描述 投票:0回答:0

在 IOS 中有 CATransform3D 矩阵来转换层,我需要使用 opengles C++ 对 android 进行相同的转换,但我需要知道哪个矩阵元素代表哪个? `函数 rectToQuad( 矩形:CGRect, _ x1a:CGFloat, _ y1a:CGFloat, _ x2a:CGFloat, _ y2a:CGFloat, _ x3a:CGFloat, _ y3a:CGFloat, _ x4a:CGFloat, _ y4a:CGFloat )->(CATransform3D) {

       let X = rect.origin.x;
       let Y = rect.origin.y;
       let W = rect.size.width;
       let H = rect.size.height;
       
       let y21 = y2a - y1a;
       let y32 = y3a - y2a;
       let y43 = y4a - y3a;
       let y14 = y1a - y4a;
       let y31 = y3a - y1a;
       let y42 = y4a - y2a;
       
       let a = -H*(x2a*x3a*y14 + x2a*x4a*y31 - x1a*x4a*y32 + x1a*x3a*y42);
       let b = W*(x2a*x3a*y14 + x3a*x4a*y21 + x1a*x4a*y32 + x1a*x2a*y43);
       
       let c0 = -H*W*x1a*(x4a*y32 - x3a*y42 + x2a*y43)
       let cx = H*X*(x2a*x3a*y14 + x2a*x4a*y31 - x1a*x4a*y32 + x1a*x3a*y42)
       let cy = -W*Y*(x2a*x3a*y14 + x3a*x4a*y21 + x1a*x4a*y32 + x1a*x2a*y43)
       let c = c0 + cx + cy
       
       let d = H*(-x4a*y21*y3a + x2a*y1a*y43 - x1a*y2a*y43 - x3a*y1a*y4a + x3a*y2a*y4a);
       let e = W*(x4a*y2a*y31 - x3a*y1a*y42 - x2a*y31*y4a + x1a*y3a*y42);
       
       let f0 = -W*H*(x4a*y1a*y32 - x3a*y1a*y42 + x2a*y1a*y43)
       let fx = H*X*(x4a*y21*y3a - x2a*y1a*y43 - x3a*y21*y4a + x1a*y2a*y43)
       let fy = -W*Y*(x4a*y2a*y31 - x3a*y1a*y42 - x2a*y31*y4a + x1a*y3a*y42)
       let f = f0 + fx + fy
       
       let g = H*(x3a*y21 - x4a*y21 + (-x1a + x2a)*y43);
       let h = W*(-x2a*y31 + x4a*y31 + (x1a - x3a)*y42);
       
       let i0 = H*W*(x3a*y42 - x4a*y32 - x2a*y43)
       let ix = H*X*(x4a*y21 - x3a*y21 + x1a*y43 - x2a*y43)
       let iy = W*Y*(x2a*y31 - x4a*y31 - x1a*y42 + x3a*y42)
       var i = i0 + ix + iy
       
    
       let kEpsilon:CGFloat = 0.0001;
       if(fabs(i) < kEpsilon) { i = kEpsilon * (i > 0 ? 1.0 : -1.0); }
           let q = a/i;
           let q1 = d/i;
           let q2 = g/i;
           let q3 = b/i;
           let q4 = e/i;
           let q5 = h/i;
           let q6 = c/i;
           let q7 = f/i;
           print("a/i, \(q)!")
           print("d/i, \(q1)!")
           print("g/i, \(q2)!")
           print("b/i, \(q3)!")
           print("e/i, \(q4)!")
           print("h/i, \(q5)!")
           print("c/i, \(q6)!")
           print("f/i, \(q7)!")
           return CATransform3D(m11:a/i, m12:d/i, m13:0, m14:g/i,
                           m21:b/i, m22:e/i, m23:0, m24:h/i,
                           m31:0, m32:0, m33:1, m34:0,
                           m41:c/i, m42:f/i, m43:0, m44:1.0)
       }`

此 iOS 代码用于计算转换。我需要一个相同的转换,它适用于 android opengles c++。

我需要一个相同的转换,它在 android opengles c++ 上作为视图矩阵工作。

c++ swift opengl-es
© www.soinside.com 2019 - 2024. All rights reserved.