Jump to content
  • Advertisement
Sign in to follow this  
thecheeselover

OpenGL [Answered] Quick Matrix question

This topic is 2115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

translations are at m12,13,14 smile.png 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?

Share this post


Link to post
Share on other sites
[s]you mean the last element?
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[/s]

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!