migueltk's picture

Matrix4 multiplication problem

Recently I have noticed that the value returned by the gml math library, is different to that returned by OpenTK when I multiply matrices.

The image shows the two input matrices and the result matrix that matches the gml library. OpenTK returns the following array:

Row0 = 1.0; 0.0; 0.0; 0.0
Row1 = 0.0; 0.5; -0.866; 0.0
Row2 = 0.0; 0.866; 0.5; 0.0
Row3 = 0.0; -86.602; -50; 1.0

Can anyone verify this?

Inline Images

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
migueltk's picture

Site where I found a calculator matrix is this.

migueltk's picture

Tested with OpenTK version 1.1.1428.49013

the Fiddler's picture

I just tested an I am getting:

a
(1; 0; 0; 0)
(0; 1; 0; 0)
(0; 0; 1; -100)
(0; 0; 0; 1)
b
(1; 0; 0; 0)
(0; 0,5; 0,866; 0)
(0; -0,866; 0,5; 0)
(0; 0; 0; 1)
c = a * b
(1; 0; 0; 0)
(0; 0,5; 0,866; 0)
(0; -0,866; 0,5; -100)
(0; 0; 0; 1)

Are you using a specific Matrix4* class? Which method are you using for the multiplication?

Edit:
are you, by any chance, mixing a * b with b * a? The latter gives a result similar to the one you are getting.

migueltk's picture

The problem is that I'm porting source code that was originally written to use the glm library, glm uses the OpenGL convention 'column-major' and OpenTK uses 'row-major'. I have to invert operations, for example:

Gml Code:
viewMatrix = translateMatrix * rotateMatrix * pivotMatrix

OpenTK code:
viewMatrix = pivotMatrix * rotateMatrix * translateMatrix

Thanks for your answer.

PS: The decision to use 'row-major' in OpenTK does not provide porting opengl code ...

the Fiddler's picture

IIRC, the decision was to match whatever Managed DirectX (and later XNA) provided at the time. Whether this was the right decision is debatable, but it is too late to change now.

I'm laying the groundwork for a modular version, so in the future you'll be able to substitute the math library with a different implementation. This is going to take a while, though.