hooded_paladin 122 Report post Posted December 17, 2001 I''m trying to do environment mapping right, but the sphere refelction does not rotate with the camera. Someone told me I need to find the inverse of the rotational matrix and put it into the texture matrix. 2 questions 1) is this the right way to do it? and 2) if so, then how? Thanks 0 Share this post Link to post Share on other sites

python_regious 929 Report post Posted December 17, 2001 Firsly, I have no idea whether that is the right method or not. There are many ways to invert matrices, but as far as I am aware, with orthogonal matrices, the inverse is equal to it''s transpose. Since all the transformation matrices ( translate, rotate and scale ) are orthogonal, then the inverse is simply it''s transpose.When you say "put it" into the texture matrix, I assume you mean multiply, to do this select the texture matrix and use glMultMatrix* like so:glMatrixMode( GL_TEXTURE );glMultMatrixf( inverse_rotation_matrix ); 0 Share this post Link to post Share on other sites

Gorg 248 Report post Posted December 17, 2001 The inverse of a rotation matrix is simply the transpose of the matrix. Easy heh! 0 Share this post Link to post Share on other sites

Guest Anonymous Poster Report post Posted December 18, 2001 Are you sure the inverse is the transpose when doing rotation? I thought the inverse was just negating the angles in the case of rotation. Like:if R is:[cos(theta) sin(theta) 0 0][-sin(theta) cos(theta) 0 0][0 0 1 0][0 0 0 1]then the inverse is:[cos(-theta) sin(-theta) 0 0][-sin(-theta) cos(-theta) 0 0][0 0 1 0][0 0 0 1] 0 Share this post Link to post Share on other sites

python_regious 929 Report post Posted December 18, 2001 The rotation matrix is orthogonal, ALL othogonal matrices have their transpose equal to their inverse. Also, since the cosine terms are on the top left to bottom right diagonal, it's true that:R ^{-1}( theta ) = R ( -theta ) = R ^{T}( theta )Think of like this, to get back to the previous position after rotating by an angle theta, you need to rotate by and angle -theta. Since cosine is symetrical around the y axis, it won't make a difference, so it's only the sin terms that do. And if you think about it, -sin( theta ) is the same as sin( -theta ). So if you swap all the sin terms with it's opposite ( so sin turns to -sin, and -sin turns to sin ), you will find that it ends up being the transpose of the original matrix.[EDIT: formatting]Edited by - python_regious on December 18, 2001 10:15:14 AM 0 Share this post Link to post Share on other sites

hooded_paladin 122 Report post Posted December 18, 2001 Transpose? What is that? I''m not really all that good with matrices, or higher math. 0 Share this post Link to post Share on other sites

Guest Anonymous Poster Report post Posted December 18, 2001 Ahh..thanks Python. I was the one that posted about the inverse being the cos(-theta) thing. I see now that the transpose gives you pretty much the same answer. duhhh on my part. Thanx. :-) 0 Share this post Link to post Share on other sites

Brother Bob 10347 Report post Posted December 18, 2001 Just transposing the modeview matrix is not enough, I believe. If the matrix contains translations, you get into trouble. It should be the rotation part only, and transposed of course.If the modelview matrix looks like this: [ a d g x ][ b e h y ][ c f i z ][ 0 0 0 1 ]a-i = rotation partx-z = translation part You should not upload the transpose of that matrix, but rather the transposed rotation part only. [ a b c 0 ][ d e f 0 ][ g h i 0 ][ 0 0 0 1 ] quote:Transpose? What is that? I'm not really all that good with matrices, or higher math. A transposed matrix is a matrix that is rotated about is't main diagonal. An element at (m, n) is places at (n, m). Basically, rows and collumns are swaped.Edited by - Brother Bob on December 18, 2001 4:59:34 PM 0 Share this post Link to post Share on other sites

Scarab0 122 Report post Posted December 18, 2001 quote:Original post by Anonymous Poster Are you sure the inverse is the transpose when doing rotation? I thought the inverse was just negating the angles in the case of rotation. Like:if R is:[cos(theta) sin(theta) 0 0][-sin(theta) cos(theta) 0 0][0 0 1 0][0 0 0 1]then the inverse is:[cos(-theta) sin(-theta) 0 0][-sin(-theta) cos(-theta) 0 0][0 0 1 0][0 0 0 1] What you are saying is identical to the transpose. Remember that: sin(-x) = -sin(x) and cos(-x) = cos(x). Therefore -sin(-theta) becomes sin(theta) and sin(-theta) becomes -sin(theta). Also both cos(-theta) become cos(theta). So the inverse you describe is identical to the transpose!Math is great isn't it? EDIT: DOH! python_regious already posted this but I overlooked his post. I need some sleep. Edited by - Scarab0 on December 18, 2001 5:35:43 PM 0 Share this post Link to post Share on other sites