将 android.graphics.Matrix 转换为 GL mat4? [英] Convert an android.graphics.Matrix to a GL mat4?

查看:110
本文介绍了将 android.graphics.Matrix 转换为 GL mat4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与 如何将 3x3 旋转矩阵转换为 4x4 矩阵?:我正在编写 2D OpenGL 代码来操作平面(z 始终等于 0)几何体上的纹理.android.graphics.Matrix 类有许多方便的调试方法可以执行诸如绕显式枢轴点旋转之类的操作.

I have a somewhat different issue than How to convert a 3x3 rotation matrix into 4x4 matrix?: I'm writing 2D OpenGL code that manipulates textures on a flat (z always equals 0) geometry. The android.graphics.Matrix class has many handy, debugged convenience methods that can do things like rotate about an explicit pivot point.

不是将 3x3 矩阵(可以进行 2D 仿射变换)转换为 4x4 矩阵

Isn't converting a 3x3 matrix (that can do 2D affine transformations) to a 4x4 matrix a matter of

a11 a12 a13    a11 a12   0 a13
a21 a22 a23    a21 a22   0 a23
a31 a32 a33      0   0   1   0
               a31 a32   0 a33

...,也许,转置以使其成为列主要?

... with, perhaps, a transpose to make it column-major?

推荐答案

如果你只做仿射变换,它会这样工作.在这种情况下,a31 和 a32 总是可以为零,而 a33 无论如何都应该是一.在这些情况下,您可以使用 2x3 矩阵,而使用基于现代着色器的 GL,您甚至可以直接使用该 3x3 或 2x3 矩阵而无需任何转换.

If you only do affine transformations, it will work that way. In that case, a31 and a32 can always be zero and a33 should be one anyways. You can get away with a 2x3 matrix in these situations, and with modern shader-based GL, you could even directly work with that 3x3 or 2x3 matrix without any conversion.

请注意,如果您进行投影变换,将矩阵扩展到 4x4 仍然有效,但会在 z 维中引入失真.

Note that if you do projective transforms, extending the matrix to 4x4 will still work, but introduces distortions in the z dimension.

这篇关于将 android.graphics.Matrix 转换为 GL mat4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆