**1**

# [Answered] Quick Matrix question

###
#1
Members - Reputation: **330**

Posted 29 September 2012 - 07:33 PM

It is said that OpenGL uses column-major 4x4 matrices (http://www.songho.ca.../gl_matrix.html). Does this mean that the translations are at the right or at the bottom like in Xna?

Opengl: Column-major matrix

Row-major matrix

Thanks

###
#2
Prime Members - Reputation: **2059**

Posted 29 September 2012 - 11:32 PM

you can pass them with glUniform* with false in the transpose parameter

btw. if you want to make your own little matrix lib, i heartily recommend it

lots of little mini-functions in the class that can do alot less flops than constantly multiplying entire matrices together

eg. translateXZ, translateXYZ, and so on.

###
#3
Crossbones+ - Reputation: **1263**

Posted 30 September 2012 - 03:44 AM

###
#4
Prime Members - Reputation: **2059**

Posted 30 September 2012 - 04:53 AM

You can put the translation along the last row or column, depending on your conventions. Note the distinction between row/column majorness and row/column vectors. Dx and GL's matrix uploading functions expect the matrices to be stored in a given majorness so as long as you comply, you can use any combination of row/column vectors stored in row/column major (although both APIs will transpose your matrices for you if you specify it, at least GL does to my knowledge).

yes, that's the transpose parameter in the glUniformMatrix* functions

default is the one i specified in the other post, and is likely a faster upload to gpu since it would be a bit block transfer

###
#5
Members - Reputation: **330**

Posted 30 September 2012 - 06:20 PM

translations are at m12,13,14 i just checked

you can pass them with glUniform* with false in the transpose parameter

btw. if you want to make your own little matrix lib, i heartily recommend it

lots of little mini-functions in the class that can do alot less flops than constantly multiplying entire matrices together

eg. translateXZ, translateXYZ, and so on.

By the way, when I do RotateXY, m33 is set twice. How do I solve this? Should I multiply both?

###
#6
Prime Members - Reputation: **2059**

Posted 30 September 2012 - 06:27 PM

its calculated like this:

element[15] += element[3] * x + element[7] * y + element[11] * z

the reason for += is because you also add element[15] * w, but here we assume w to be 1.0f

so... if you are only translating x and y, then z would be 0, and thus:

element[15] += element[3] * x + element[7] * y

nevermind, i just noticed you said -Rotate-XY

let's see....

in this code sx is sin(x), sy is sin(y), and cx is cos(x), finally cy is cos(y)

// left vector m_Element[0] = cy; m_Element[1] = sx * sy; m_Element[2] = -cx * sy; m_element[3] = 0.0f; // w1 // up vector m_Element[4] = 0.0f; m_Element[5] = cx; m_Element[6] = sx; m_element[7] = 0.0f; // w2 // forward vector m_Element[ 8] = sy; m_Element[ 9] = -sx * cy; m_Element[10] = cx * cy; m_element[11] = 0.0f; // w3 // translation m_element[12] = 0.0f; // tx m_element[13] = 0.0f; // ty m_element[14] = 0.0f; // tz m_element[15] = 1.0f; // w4

i haven't really optimized this, and as you can see this only creates a 2D rotation matrix

i think it's probably best for each rotation to make a matrix and multiply together to make a complete transformation

**Edited by Kaptein, 30 September 2012 - 06:33 PM.**