# does XNA have 3x3 matrix?

I've checked intelisence and googled for it but it seems there is no 3x3 matrix in xna. I'm just wondering should I just write a matrix class for xna to work freely with matrix class?

by the way I'm trying to multiply vector3 into 3x3 matrix to have both rotation and translation in one matrix class.

-

XNA has a 4x4 `Matrix` class (MSDN) which can be used everywhere that you might use a 3x3 matrix - just leave the third or last (depends on your usage) row and column as their identity values. In most cases you should just use that. The only benefit of writing your own 3x3 matrix is if you need the smaller data structure (36 bytes instead of 64).

If you intend to apply translation transformations to your 3D vector, then you need a 4x4 matrix. The vector implicitly has a fourth element that is equal to 1. Without going through the maths - this allows it to multiply in the translation elements of the matrix. (Details on Wikipedia, see also)

Matrices can be multiplied together to combine multiple transformation operations into a single matrix. For example:

``````Matrix transform = Matrix.CreateScale(2f)
* Matrix.CreateRotationZ(1f)
* Matrix.CreateTranslation(10f, 10f, 10f);
``````
-
I'm developing a 2D game so adding one dimension, I need 3D vector and 3x3 Matrix to keep both translation and rotation. anyway seems I've got to work with 4x4 matrix in the end. – Ali.S Aug 16 '11 at 2:55
@Gajet in fact you don't need a 3D vector to apply translation (the required extra vector element is implicit; and `Vector2` has a `Transform` method). 4x4 is certainly usable for 2D work, but if you were inclined to write your own matrix type then a 3x3 Affine matrix is a good way to go (only 6 elements). – Andrew Russell Aug 16 '11 at 3:55
@ShadowChaser I believe your maths is wrong. 4x4 elements = 16 elements. Each element is a single-precision (32-bit) `float`. That is 4 bytes per element. 16x4 bytes = 64 bytes. – Andrew Russell Feb 17 '12 at 13:38