-1
\$\begingroup\$

From a previous question, thank you very much by the way, but what on earth is the Matrix of? I'm very new to Mono/XNA and finding any meaningful documentation is practically impossible.

point = Vector2.Transform(point, Matrix.CreateRotationZ(AngleToRotate);
point += originPoint;

Edit: I would like to rotate my 2D game world around my character who is in the center of the view port. I was kindly given the above function, which I'm sure with the knowledge how to use it, would be exactly what I'm looking for. However, I don't have that knowledge. I understand what vectors are, but I have no idea what the matrix is generated from.

\$\endgroup\$
0

2 Answers 2

2
\$\begingroup\$

In this case, the matrix is generated from the call to Matrix.CreateRotationZ, which is a function (a static method of the Matrix class). It creates a 4x4 tranformation matrix which describe a rotation about the Z axis. The formula for constructing that matrix can be seen here, as Rz. Extending that the 4x4 form used for the Matrix class, it would look like this:

cos(theta) -sin(theta) 0 0
sin(theta)  cos(theta) 0 0
    0           0      1 0
    0           0      0 1

theta is the desired rotation angle (your AngleToRotate).

In addition to the linked Wikipedia page, you may want to read The Matrix and Quaternion FAQ.

\$\endgroup\$
0
\$\begingroup\$

The thing you currently have is a transformation matrix Transfomation Matrices are way, to easily represent a the position, rotation and scale of an object in 3d or 2d scene, a 2d scene only needs a 3*3 matrix, a 3d one usually uses a 4*4, but 2d transformation can be represented in a 4*4 matrix too, but it just wastes space. The matrix is oriented like this:

Translation matrix (x, y and z coordinates)

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1

Scale matrix (again, x, y and z values)

x 0 0 0
0 y 0 0
0 0 z 0
0 0 0 1

Rotation matrix is a bit more involved, it is different on x, y and z axis, this is for example the z axis (for 2d rotation basically:

cos(theta) -sin(theta) 0 0
sin(theta) cos(theta)   0 0
0                0                   0 0
0                0                   0 0

By multiplying these matrices together in a strict way (translation * rotationxyz * scale), ypu get the trabsformation matrix.

Also, matrices are used in many more ways, like ptojection matrices, wich help to convert from 2d semi-ortographic projection to e.g perspective projection, or view matrix, wich defines the camera's position, you too have a view matrix.

If you multiply together the projection, the view and the model/transformation matrix, you get a modelviewprojection (MVP) matrix, wich is used, to get the screen positions of models or sprites.

To rotate your world around, you need to multiply every point with the rotation matrix you have, and you get the transformed position, wich look like it is rotated around.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .