将2D仿射变换矩阵转换为3D仿射变换矩阵

Soa*_*oap 7 c# xna transformation matrix linear-algebra

我的代码中有一个错误,想知道这是不正确的.

我的代码中有一个2D视图矩阵,但要将我的世界显示在屏幕上,我需要将2D视图矩阵转换为3D视图矩阵.这是我正在使用的过程:

| a b c |      | a b c 0 |
| d e f |  =>  | d e f 0 |
| g h i |      | g h i 0 |
               | 0 0 0 1 |
Run Code Online (Sandbox Code Playgroud)

当我对2D矩阵使用单位矩阵时它起作用,但是一旦我将任何变换应用于2D矩阵,我绘制的所有对象都会消失.

对于使用3D绘制2D,我使用此投影矩阵:

_basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1);
Run Code Online (Sandbox Code Playgroud)

将2D矩阵转换为3D的正确方法是什么?

Gus*_*son 16

仿射变换使用变换矩阵的额外行/列进行转换.所以我认为你想要做的是向下/向右移动最后一行/列,然后为新轴简单地插入标识转换.

| a b c |      | a b 0 c |
| d e f |  =>  | d e 0 f |
| g h i |      | 0 0 1 0 |
               | g h 0 i |
Run Code Online (Sandbox Code Playgroud)

我不确定,但至少试一试.