Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

the glRotate Matrix

This topic is 6037 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

I want to build myself the matrix that glRotate creates. In the redbook it is written:
The call glRotate*(a, x, y, z) generates R as follows:

Let v = (x, y, z)T, and u = v/||v|| = (x'', y'', z'')T.

Also let

Then


But I am doing something wrong because my matrix is different from the one that glRotate creates.
I am creating it like this:
Vnorm(vect_rot); // u
double uu = vect_rot[0]*vect_rot[0]+vect_rot[1]*vect_rot[1]+vect_rot[2]*vect_rot[2];
double i_uu = 1 - uu;
double cos_tetha = cos(tetha), sin_tetha=sin(tetha);
double M[4][4]= { uu+i_uu*cos_tetha,        -vect_rot[2]*sin_tetha,   vect_rot[1]*sin_tetha,    0,
                    vect_rot[2]*sin_tetha,    uu+i_uu*cos_tetha,        -vect_rot[0]*sin_tetha,   0, 
                    -vect_rot[1]*sin_tetha,   vect_rot[0]*sin_tetha,    uu+i_uu*cos_tetha,        0, 
                    0,                        0,                        0,                        1};
Is this correct??
Thank YOU!
=]

Share this post


Link to post
Share on other sites
Advertisement
It seems like you don''t describe the matrix the right way. You should use a 1D array and matrix elements must be given column by column (instead of row by row). Here''s an example :

This matrix declaration :
  
const float m[16] = { 0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15 }


Will give this matrix :

  
[ 0 4 8 12]
[ 1 5 9 13]
[ 2 6 10 14]
[ 3 7 11 15]


Hope it helps.

Share this post


Link to post
Share on other sites
yes, OpenGL defines 4x4 matrices differently from C/C++. I think OpenGL does columns, rows and C/C++ does rows columns. i.e:

  

// OpenGL style:


float Matrix[4][4] = {0, 4, 8, 12,
1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11, 15};

// whereas C/C++ style:


float MatrixB[4][4] = {0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15};



I just wanted to clarify that!



------------------------------
Baldur K

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!