Something Interesting about monogame matrices i discovered.

So i have been working on matrices a lot lately and i have discovered a interesting thing in that monogame xna while claiming to be a right handed coordinate system is using a left handed rotation system in world space this will be the M11 element or the first element.

Basically it is internally inside the matrices using
The renderman system for rotations.

Vector wise it uses the open gl standard definition.
Vector3.Right {X:1 Y:0 Z:0}
Vector3.Up {X:0 Y:1 Z:0}
Vector3.Forward {X:0 Y:0 Z:-1}

This has some interesting implications. Ill show these in a moment after i point out more fully the meaning of what i just said.

Lets create a RotationZ matrix with zero degrees of radians and print it.
If our coordinate system in world space was really right up forward we should get a matrix
With a negative z coordinate just like our system vector Vector3.Forward.

Matrix is Normalized Matches MG LH Matrix. Orientation
: 1.00 0.00 0.00 0.00 X is Right
: 0.00 1.00 0.00 0.00 Y is Up
: 0.00 0.00 1.00 0.00 Z is Forward
: 0.00 0.00 0.00 1.00

As you see however instead we get a matrix equal to identity.
You might think well we just picked the wrong rotation matrix.
So lets try this with create world.

A CreateWorld matrix from System Vectors Forward Up and a Vector3.Zero for position.
Remember these are are system vectors describing a right handed coordinate system
Right {X:1 Y:0 Z:0}
Up {X:0 Y:1 Z:0}
Forward {X:0 Y:0 Z:-1}

Matrix m = Matrix.CreateWorld(Vector3.Zero, Vector3.Forward, Vector3.Up);
Matrix is Normalized Matches MG LH Matrix. Orientation
: 1.00 0.00 0.00 0.00 X is Right
: 0.00 1.00 0.00 0.00 Y is Up
: 0.00 0.00 1.00 0.00 Z is Forward
: 0.00 0.00 0.00 1.00

We get yet again however a identity matrix of the LH rotation system type.
By this i mean that our Forward vector int the matrix as you can see is (0,0,1) not -1

From this lets say we want to put in negative Forward that has a positive z coordinate to create world you can visualize this on either hand with your thumb up and your index finer pointing back toward you. If the Right value in the resulting matrix is negative you have a left handed system.
if the right vector is positive a right handed system.

What will we get ?

A create world matrix from System Vectors neg -Forward / Vector3.Backwards and the Up
Matrix is Normalized Matches MG LH Matrix. Orientation
: -1.00 0.00 0.00 0.00 X is Left
: 0.00 1.00 0.00 0.00 Y is Up
: 0.00 0.00 -1.00 0.00 Z is Back
: 0.00 0.00 0.00 1.00

What does this mean ?

Well if you wanted you could set up things in render man coordinates in a world matrix provided you didn’t call the CreateWorld function on them and set your models up also go forward in the z direction. Basically just like on a graph with the bottom left as the coordinate origin to the top right. Because the identity matrix in monogame has a positive value of 1 for its Right Up Forward and that is the renderman rotational coordinate system which is left handed. While our vectors themselves describe a right handed open gl coordinate system.

This is actually pretty cool because you get clockwise rotation with the traditional -z depth at the same time basically you get the best part of both systems.

Thought someone might find this to be a cool bit of info.

1 Like

I think your inferences about the handedness of the matrices is incorrect, and I think it stems from your assumptions about what should be inside the matrix. The fact is, yes, it’s a right-handed coordinate system.

A Z-rotation matrix with a rotation of 0 radians does nothing - that is to say, it is an “identity” matrix, which is all zeroes with ones down its diagonal. This is the Identity matrix for any system. We should not have any negatives in there.

Now, if you transform the “forward” vector (0, 0, -1) by this matrix, which we just established does nothing, you should end up with the same “forward” vector (0, 0, -1). This is why Monogame reports that the matrix’s “forward” vector too is (0, 0, -1).

If you create a matrix with CreateWorld, even though you are asked to supply up and forward, it does not stick those values directly into the matrix’s elements. The Y column will be your up argument, sure, and the W column will be the position, but the Z column will be the opposite of your forward, and the X column will be the cross product of your forward and up. I figure they probably use this convention because it’s easier to visualise a transformation in terms of “forward” rather than “backward”.

1 Like

I think you missed my point the vector representation of the coordinate system and the representation on the matrix built by create world are not the same handedness.

I suppose i could be wrong if up right forward should be considered 1 1 1 at all i always thought that was the definition of a left handed coordinate system as the positive positive positive section of a cartesian graph with forward being positive.

What is in the the result of a Matrix.CreateWorld m.Forward and what is in a Vector3.Forward.
One only needs to print out to see they are not the same, (I didn’t make up those numbers)

If you negate only one dimension of a coordinate system it swaps the orientational handedness of the coordinate system which goes without saying left |/__ __|/ right