Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert 2D affine transformation matrix to 3D affine transformation matrix

I have a bug somewhere in my code, was wondering if this is incorrect.

I have a 2D view matrix in my code, but to display my world to the screen I need to convert the 2D view matrix to a 3D one. This is the process that I am using:

| 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 |

It works when I use an identity matrix for the 2D matrix, but as soon as I apply any transforms to the 2D matrix all my objects being drawn disappear.

For drawing in 2D using 3D, I use this projection matrix:

_basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1);

What is the correct way to transform the 2D matrix to 3D?

like image 984
Soap Avatar asked Apr 01 '11 01:04

Soap


People also ask

How do you combine two affine transforms?

Concatenation combines two affine transformation matrices by multiplying them together. You might perform several concatenations in order to create a single affine transform that contains the cumulative effects of several transformations.

What is 3D affine transformation?

3D Affine Transformation Matrices. Any combination of translation, rotations, scalings/reflections and shears can be combined in a single 4 by 4 affine transformation matrix: Such a 4 by 4 matrix M corresponds to a affine transformation T() that transforms point (or vector) x to point (or vector) y.

How do you reverse affine transformation?

The inverse of an affine transformation is also affine, assuming it exists. Proof: Let ¯q = A¯p+ t and assume A−1 exists, i.e. det(A) = 0. Then A¯p = ¯q− t, so ¯p = A−1 ¯q− A−1t.

How do you find the affine transform of a matrix?

The affine transforms scale, rotate and shear are actually linear transforms and can be represented by a matrix multiplication of a point represented as a vector, [x y ] = [ax + by dx + ey ] = [a b d e ][x y ] , or x = Mx, where M is the matrix.


1 Answers

Affine transformations use the extra row/column of the transformation matrix for translation. So I think what you want to do is to move the last row/column down/right and then for the new axis simply insert the identity transformation.

| 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 |

I'm not sure, but give it a try at least.

like image 115
Gustav Larsson Avatar answered Sep 21 '22 00:09

Gustav Larsson