// store previous matrix
float mOld[16];
glGetFloatv( GL_MODELVIEW_MATRIX, mOld );
// modify OpenGL matrix in some way...
glMultMatrixf( m_myOwnMatrix );
// get the new matrix
float mNew[16];
glGetFloatv( GL_MODELVIEW_MATRIX, mNew );
// Now let's see if we can extract "m_myOwnMatrix" from the new OpenGL matrix for testing
mOld.Invert();
// remove previous matrix from new matrix
mNew *= mOld;
ASSERT( mNew == m_myOwnMatrix );
Help please: Matrix issues............. :((((
Hello people,
I'm trying some matrix things at the moment and I just don't get it whats wrong with my code.
A simplified example in pseudo-code:
Note, this is no real C code. I'm using my own matrix class that is able to handle multiplication and the .Invert() thing.
The last assert fails and I don't really know why. What am I doing wrong?
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
[edited by - Lyve on March 16, 2003 3:21:26 PM]
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
looks ok to me.. can it be your multiplication and/or invert code?
-----------my quote is under construction
quote:
Original post by Lyve
Note, this is no real C code. I''m using my own matrix class that is able to handle multiplication and the .Invert() thing.
The last assert fails and I don''t really know why. What am I doing wrong?
Why don''t you post the code for your invert() and mult() methods? In my own experiences, It''s really easy to swap a var and not notice in matrix processing code. The thing I would do is test those first, just step through in the debugger with some simple matricies and make sure it''s doing what it''s supposed to.
- sighuh?
- sighuh?
Thanks for your answers. Here''s the invert code:
Well, the swap macro is okay, believe me, used VEERRRYYY often!
void CMatrix::Invert(){// SWAP( matrix[ 0], matrix[ 0], float ); SWAP( matrix[ 1], matrix[ 4], float ); SWAP( matrix[ 2], matrix[ 8], float ); SWAP( matrix[ 3], matrix[12], float );// SWAP( matrix[ 4], matrix[ 1], float );// SWAP( matrix[ 5], matrix[ 5], float ); SWAP( matrix[ 6], matrix[ 9], float ); SWAP( matrix[ 7], matrix[13], float );// SWAP( matrix[ 8], matrix[ 2], float );// SWAP( matrix[ 9], matrix[ 6], float );// SWAP( matrix[10], matrix[10], float ); SWAP( matrix[11], matrix[14], float );// SWAP( matrix[12], matrix[ 3], float );// SWAP( matrix[13], matrix[ 7], float );// SWAP( matrix[14], matrix[11], float );// SWAP( matrix[15], matrix[15], float );}
Well, the swap macro is okay, believe me, used VEERRRYYY often!

_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
Nah, forgot the mult code:
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
CMatrix CMatrix::Mult( CMatrix& _m1, CMatrix& _m2 ){ CMatrix m; m.matrix[ 0] = _m1.matrix[ 0] * _m2.matrix[ 0] + _m1.matrix[ 1] * _m2.matrix[ 4] + _m1.matrix[ 2] * _m2.matrix[ 8] + _m1.matrix[ 3] * _m2.matrix[12]; m.matrix[ 1] = _m1.matrix[ 0] * _m2.matrix[ 1] + _m1.matrix[ 1] * _m2.matrix[ 5] + _m1.matrix[ 2] * _m2.matrix[ 9] + _m1.matrix[ 3] * _m2.matrix[13]; m.matrix[ 2] = _m1.matrix[ 0] * _m2.matrix[ 2] + _m1.matrix[ 1] * _m2.matrix[ 6] + _m1.matrix[ 2] * _m2.matrix[10] + _m1.matrix[ 3] * _m2.matrix[14]; m.matrix[ 3] = _m1.matrix[ 0] * _m2.matrix[ 3] + _m1.matrix[ 1] * _m2.matrix[ 7] + _m1.matrix[ 2] * _m2.matrix[11] + _m1.matrix[ 3] * _m2.matrix[15]; m.matrix[ 4] = _m1.matrix[ 4] * _m2.matrix[ 0] + _m1.matrix[ 5] * _m2.matrix[ 4] + _m1.matrix[ 6] * _m2.matrix[ 8] + _m1.matrix[ 7] * _m2.matrix[12]; m.matrix[ 5] = _m1.matrix[ 4] * _m2.matrix[ 1] + _m1.matrix[ 5] * _m2.matrix[ 5] + _m1.matrix[ 6] * _m2.matrix[ 9] + _m1.matrix[ 7] * _m2.matrix[13]; m.matrix[ 6] = _m1.matrix[ 4] * _m2.matrix[ 2] + _m1.matrix[ 5] * _m2.matrix[ 6] + _m1.matrix[ 6] * _m2.matrix[10] + _m1.matrix[ 7] * _m2.matrix[14]; m.matrix[ 7] = _m1.matrix[ 4] * _m2.matrix[ 3] + _m1.matrix[ 5] * _m2.matrix[ 7] + _m1.matrix[ 6] * _m2.matrix[11] + _m1.matrix[ 7] * _m2.matrix[15]; m.matrix[ 8] = _m1.matrix[ 8] * _m2.matrix[ 0] + _m1.matrix[ 9] * _m2.matrix[ 4] + _m1.matrix[10] * _m2.matrix[ 8] + _m1.matrix[11] * _m2.matrix[12]; m.matrix[ 9] = _m1.matrix[ 8] * _m2.matrix[ 1] + _m1.matrix[ 9] * _m2.matrix[ 5] + _m1.matrix[10] * _m2.matrix[ 9] + _m1.matrix[11] * _m2.matrix[13]; m.matrix[10] = _m1.matrix[ 8] * _m2.matrix[ 2] + _m1.matrix[ 9] * _m2.matrix[ 6] + _m1.matrix[10] * _m2.matrix[10] + _m1.matrix[11] * _m2.matrix[14]; m.matrix[11] = _m1.matrix[ 8] * _m2.matrix[ 3] + _m1.matrix[ 9] * _m2.matrix[ 7] + _m1.matrix[10] * _m2.matrix[11] + _m1.matrix[11] * _m2.matrix[15]; m.matrix[12] = _m1.matrix[12] * _m2.matrix[ 0] + _m1.matrix[13] * _m2.matrix[ 4] + _m1.matrix[14] * _m2.matrix[ 8] + _m1.matrix[15] * _m2.matrix[12]; m.matrix[13] = _m1.matrix[12] * _m2.matrix[ 1] + _m1.matrix[13] * _m2.matrix[ 5] + _m1.matrix[14] * _m2.matrix[ 9] + _m1.matrix[15] * _m2.matrix[13]; m.matrix[14] = _m1.matrix[12] * _m2.matrix[ 2] + _m1.matrix[13] * _m2.matrix[ 6] + _m1.matrix[14] * _m2.matrix[10] + _m1.matrix[15] * _m2.matrix[14]; m.matrix[15] = _m1.matrix[12] * _m2.matrix[ 3] + _m1.matrix[13] * _m2.matrix[ 7] + _m1.matrix[14] * _m2.matrix[11] + _m1.matrix[15] * _m2.matrix[15]; return m;}
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
Are you sure that ''=='' will work correctly? I don''t remember how c++ implements it for arrays but I''m willing to bet that it will only be true if the two arrays are the same thing in memory (not if they have the same data)
Also I''m almost positve you''re going to get precision errors trying that.
In fact, a better programming practice is to not even compare floating points directly because they can be inconsistent. Instead of say, "(p == q)", you should use "(p - q < .0001)". There are lots of resources on the net that explain how floats are evil.
Also I''m almost positve you''re going to get precision errors trying that.
In fact, a better programming practice is to not even compare floating points directly because they can be inconsistent. Instead of say, "(p == q)", you should use "(p - q < .0001)". There are lots of resources on the net that explain how floats are evil.
The assert() was only pseudo code and should only make clear that the two matrices arent the same now. The two matrices differ more than only some little floating point values.
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
hey again,
your "invert" procedure is actually computing the transpose. For some matrices, this is the same thing (matrices whose transpose is equal to the inverse are called ''orthogonal''). for example, rotation matrices are orthogonal, so this will work on them. However, its not true for all matrices.
your "invert" procedure is actually computing the transpose. For some matrices, this is the same thing (matrices whose transpose is equal to the inverse are called ''orthogonal''). for example, rotation matrices are orthogonal, so this will work on them. However, its not true for all matrices.
quote:
Original post by andy_fish
hey again,
your "invert" procedure is actually computing the transpose. For some matrices, this is the same thing (matrices whose transpose is equal to the inverse are called ''orthogonal''). for example, rotation matrices are orthogonal, so this will work on them. However, its not true for all matrices.
This might be my problem :-(. Is there some code for that anywhere or a guide how to invert an opengl matrix?
Lyve
_____________________________________
Visit http://www.nilsschneider.de for finest trance music, studio, bio, guestbook and more!
_____________________________________http://www.winmaze.de, a 3D shoot em up in OpenGL, nice graphics, multiplayer, chat rooms, a nice community, worth visiting! ;)http://www.spheretris.tk, an upcoming Tetrisphere clone for windows, a 3D tetris game on a sphere with powerful graphics for Geforce FX and similar graphics cards.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement