使用 flash10 中的 4x4 Matrix3D 进行非仿射 2D 变换

发布于 2024-08-19 13:00:33 字数 970 浏览 1 评论 0原文

当我使用flash10的Matrix3D类进行2D非仿射变换时,我一直感到非常厌倦。基本上,我在精灵中有一个正方形和形成四边形的四个点,我想对精灵应用变换以使这些点成为精灵的顶点。

使用 3x3 矩阵解决这个数学问题不会有太多问题,就像 this案例。问题是 flash 的本机变换 Matrix 类不执行非仿射变换 - 这意味着无法访问 Matrix 类的 uvw 字段。

随着flash10对3D的原生支持,引入了Matrix3D类,它允许非仿射变换,但使用起来很混乱。基本上,您在此矩阵上应用的任何内容都不完全是屏幕上显示的内容,因为它将应用 PerspectiveProjection 类中的强制投影矩阵。没有办法禁用这个投影,并且这个透视投影矩阵始终是一个不可逆矩阵(*1)。这里描述的方法 - 在 stackoverflow 上,关于 flash10 正交投影 - 将 fieldOfView 属性定义为接近 0,或将 focusLengh 定义为一个巨大的数字,将无助于消除使用非仿射的边缘情况的透视投影二维变换。这意味着,即使我们在使用 Matrix3D 的正常剪切/缩放/旋转时可以制作几乎正交的投影,但具有非仿射 2d 变换的 Matrix3D 上的相同 PerspectiveProjection 仍然会产生不需要的透视投影。有什么办法可以消除这个透视投影吗?或者也许有更好的方法?现在我正在使用一种解决方法,将平面分成两个三角形,并对它们应用两个仿射变换。

非常非常感谢! 注意

(*1)当焦距等于1时,透视投影矩阵具有以下形式:

--          --
| 1  0  0  0 |
| 0  1  0  0 |
| 0  0  1  0 |
| 0  0  1  0 |
--          --
           ^ No, sadly this wasn't a typo!

I've been having a very tiresome time when using flash10's Matrix3D class for 2D non-affine transformations. Basically, I have a square in a sprite and four points that form a quadrilateral, and I want to apply a transformation to the sprite to make those points the vertices of the sprite.

There wouldn't be much problem solving this Math problem using 3x3 matrices, like in this case. The problem is that flash's native transform Matrix class doesn't perform non-affine transformations - which means, there is no way to access the u v w fields of the Matrix class.

With flash10's native support to 3D, it was introduced the Matrix3D class, which allows non-affine transformation, but is a mess to work with. Basically whatever you apply on this matrix isn't exactly what will appear on screen, since it will apply a mandatory projection matrix from PerspectiveProjection class. There is no way to disable this projection, and this perspectiveProjection matrix is always a non-inversible matrix(*1). The method described here - at stackoverflow, about flash10 orthographic projection -, of defining the fieldOfView property to near 0, or the focalLengh to a huge number, won't help to nullify the perspective projection for the edge cases that work with non-affine 2d transformations. This means that even though we can make a projection almost-orthographic when working with normal shear/scale/rotation of a Matrix3D, the same PerspectiveProjection on a Matrix3D with non-affine 2d transforms will still have a undesired perspective projection. Would there be any way to nullify this perspectiveProjection? Or maybe a better way to do it? For now I am using a workaround of separating the plane into two triangles, and applying two affine transforms on them.

Thank you very very much!
Cauê

(*1) when the focal length equals to 1, the perspective projection matrix has the following form:

--          --
| 1  0  0  0 |
| 0  1  0  0 |
| 0  0  1  0 |
| 0  0  1  0 |
--          --
           ^ No, sadly this wasn't a typo!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-08-26 13:00:33

我建议你去问问Senoptic

I suggest you go and ask Senocular.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文